File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python
2
2
3
- import numpy
4
3
import sys
5
4
6
5
from pyxl .utils import escape
7
6
7
+ # We need a way to ensure that on a given page, no two pyxl elements are given the
8
+ # same 'pyxl<num>' id. Using a random number generator works reasonably well, but
9
+ # introduces extra complexity and overhead that is unnecessary. A global variable
10
+ # counter works just as well and is much faster. Since we only care about collisions
11
+ # in a single page, we don't have to worry about two different instances having the
12
+ # same counters.
13
+ pyxl_id_counter = 0
14
+
8
15
class PyxlException (Exception ):
9
16
pass
10
17
@@ -82,8 +89,10 @@ def __call__(self, *children):
82
89
def get_id (self ):
83
90
eid = self .attr ('id' )
84
91
if not eid :
85
- # Use numpy to generate random numbers quickly. These don't need to be secure random.
86
- eid = 'pyxl%d' % numpy .random .random_integers (0 , sys .maxint - 1 )
92
+ # See comment at definition of pyxl_id_counter for more details.
93
+ global pyxl_id_counter
94
+ eid = 'pyxl%d' % pyxl_id_counter
95
+ pyxl_id_counter = (pyxl_id_counter + 1 ) % sys .maxint
87
96
self .set_attr ('id' , eid )
88
97
return eid
89
98
You can’t perform that action at this time.
0 commit comments