1
2 import time, os, sys, types, traceback, re
3 from xml.dom import Node
4
5 import math
6
7 nonTextToken = "\x00\t"
8
9
10
11 use4Suite = 1
12 if (use4Suite):
13 try:
14 from Ft.Xml.XPath import ParsedRelativeLocationPath, ParsedAbsoluteLocationPath, \
15 ParsedStep, ParsedNodeTest, ParsedExpr, Compile, Context, \
16 ParsedAbbreviatedAbsoluteLocationPath, ParsedAbbreviatedRelativeLocationPath, ParsedNodeTest
17
18 except:
19 os.putenv('USE_MINIDOM', '1')
20 from Ft.Xml.XPath import ParsedRelativeLocationPath, ParsedAbsoluteLocationPath, \
21 ParsedStep, ParsedNodeTest, ParsedExpr, Compile
22 else:
23 from xml.xpath import *
24
25 elementType = Node.ELEMENT_NODE
26 textType = Node.TEXT_NODE
27
28
30 txt = []
31 for e in data:
32 if (e[0] == "3"):
33 if (len(txt) and txt[-1][-1] != ' ' and e[2].isalnum()):
34 txt.append(' ')
35 txt.append(e[2:])
36 txt = ''.join(txt)
37 return txt
38
40 l = []
41 for c in s:
42 if (ord(c) > 31 or c in ['\n', '\t', '\r']):
43 l.append(c)
44 return ''.join(l)
45
46 if (0):
47 from Ft.Xml.Domlette import NonvalidatingReaderBase
48 class reader(NonvalidatingReaderBase):
49 def fromString(self, str):
50 try:
51 return self.parseString(str, 'urn:foo')
52 except:
53 return self.parseString(fixString(str), 'urn:foo')
289 if not value:
290 value = 0
291 if type(value) == types.StringType:
292 if value[0:2] == "0x":
293
294 value = eval(value)
295 else:
296 value = int(value, 2)
297 self._d = value
298
300
301
302
303 if index >= len(self):
304 raise IndexError()
305 return (self._d >> index) & 1
306
308 if value:
309 self._d = self._d | (1L<<index)
310 else:
311 self._d = self._d ^ (1L <<index)
312
314 return self._d
315
317
318 s = hex(self._d)
319 if s[-1] == "L":
320 return s[:-1]
321 else:
322 return s
323
325 return self._d != 0
326
328
329
330 split = math.modf(math.log(self._d, 2))
331 if (split[0] > 0.9999999999):
332 return int(split[1]) + 1
333 else:
334 return int(split[1])
335
337 self._d = self._d | other._d
338
340 self._d = self._d & other._d
341
343 andnot = self._d & other._d
344 self._d = self._d ^ andnot
345
347 string = str(self)[2:]
348 string = string.replace('0', '')
349 string = string.lower()
350 l = 0
351 for quad in string:
352 if quad in ['1','2', '4', '8']:
353 l += 1
354 elif quad in ['3', '5', '6', '9', 'a', 'c']:
355 l += 2
356 elif quad in ['7', 'b', 'd', 'e']:
357 l += 3
358 else:
359 l += 4
360 return l
361
363 string = str(self)
364 posn = 0
365 ids = []
366
367 string = string[2:][::-1]
368
369 string = string.lower()
370 for quad in string:
371 if quad == '0':
372 pass
373 elif quad == '1':
374 ids.append(posn)
375 elif quad == '2':
376 ids.append(posn+1)
377 elif quad == '3':
378 ids.extend([posn, posn+1])
379 elif quad == '4':
380 ids.append(posn+2)
381 elif quad == '5':
382 ids.extend([posn, posn+2])
383 elif quad == '6':
384 ids.extend([posn+1, posn+2])
385 elif quad == '7':
386 ids.extend([posn, posn+1, posn+2])
387 elif quad == '8':
388 ids.append(posn+3)
389 elif quad == '9':
390 ids.extend([posn, posn+3])
391 else:
392 if quad == 'a':
393 ids.extend([posn+1, posn+3])
394 elif quad == 'b':
395 ids.extend([posn, posn+1, posn+3])
396 elif quad == 'c':
397 ids.extend([posn+2, posn+3])
398 elif quad == 'd':
399 ids.extend([posn, posn+2, posn+3])
400 elif quad == 'e':
401 ids.extend([posn+1, posn+2, posn+3])
402 elif quad == 'f':
403 ids.extend([posn, posn+1, posn+2, posn+3])
404 else:
405
406 raise ValueError(quad)
407 posn += 4
408 return ids