Skip to content

Commit e547995

Browse files
committed
Remove pyxl's dependence on numpy.
1 parent 6beb8c3 commit e547995

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pyxl/base.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#!/usr/bin/env python
22

3-
import numpy
43
import sys
54

65
from pyxl.utils import escape
76

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+
815
class PyxlException(Exception):
916
pass
1017

@@ -82,8 +89,10 @@ def __call__(self, *children):
8289
def get_id(self):
8390
eid = self.attr('id')
8491
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
8796
self.set_attr('id', eid)
8897
return eid
8998

0 commit comments

Comments
 (0)