18
18
#
19
19
20
20
from xml .dom .minidom import parse , parseString , Node
21
- from cStringIO import StringIO
22
- #import md5
21
+
22
+ try :
23
+ from cStringIO import StringIO
24
+ except ImportError :
25
+ from io import StringIO
26
+
23
27
try :
24
28
import hashlib
25
29
_md5Obj = hashlib .md5
@@ -38,15 +42,16 @@ def addSubHash(self, hash):
38
42
self .md5Sum .update (hash .getDigest ())
39
43
40
44
def getDigest (self ):
41
- return self .md5Sum .digest ()
45
+ # type: () -> bytes
46
+ return bytes (self .md5Sum .digest ())
42
47
43
48
def _compute (self , node ):
44
49
attrs = node .attributes
45
- self .md5Sum .update (node .nodeName )
50
+ self .md5Sum .update (node .nodeName . encode () )
46
51
47
52
for idx in range (attrs .length ):
48
- self .md5Sum .update (attrs .item (idx ).nodeName )
49
- self .md5Sum .update (attrs .item (idx ).nodeValue )
53
+ self .md5Sum .update (attrs .item (idx ).nodeName . encode () )
54
+ self .md5Sum .update (attrs .item (idx ).nodeValue . encode () )
50
55
51
56
for child in node .childNodes :
52
57
if child .nodeType == Node .ELEMENT_NODE :
@@ -1064,10 +1069,12 @@ def genArgSchemaMap(self, stream, variables):
1064
1069
1065
1070
def genSchemaMD5 (self , stream , variables ):
1066
1071
sum = self .hash .getDigest ()
1067
- for idx in range ( len ( sum ) ):
1072
+ for idx , val in enumerate ( sum ):
1068
1073
if idx != 0 :
1069
- stream .write ("," )
1070
- stream .write (hex (ord (sum [idx ])))
1074
+ stream .write ("," )
1075
+ if isinstance (val , str ):
1076
+ val = ord (val ) # Python 2
1077
+ stream .write (hex (val ))
1071
1078
1072
1079
1073
1080
class SchemaClass :
@@ -1443,13 +1450,13 @@ def genPresenceMaskBytes (self, stream, variables):
1443
1450
if count == 0 :
1444
1451
stream .write ("0" )
1445
1452
else :
1446
- stream .write (str (((count - 1 ) / 8 ) + 1 ))
1453
+ stream .write (str (((count - 1 ) // 8 ) + 1 ))
1447
1454
1448
1455
def genPresenceMaskConstants (self , stream , variables ):
1449
1456
count = 0
1450
1457
for prop in self .properties :
1451
1458
if prop .isOptional == 1 :
1452
- stream .write (" static const uint8_t presenceByte_%s = %d;\n " % (prop .name , count / 8 ))
1459
+ stream .write (" static const uint8_t presenceByte_%s = %d;\n " % (prop .name , count // 8 ))
1453
1460
stream .write (" static const uint8_t presenceMask_%s = %d;\n " % (prop .name , 1 << (count % 8 )))
1454
1461
count += 1
1455
1462
@@ -1527,12 +1534,14 @@ def genParentRefAssignment (self, stream, variables):
1527
1534
" = _parent->GetManagementObject()->getObjectId();" )
1528
1535
return
1529
1536
1530
- def genSchemaMD5 (self , stream , variables ):
1537
+ def genSchemaMD5 (self , stream , variables ):
1531
1538
sum = self .hash .getDigest ()
1532
- for idx in range ( len ( sum ) ):
1539
+ for idx , val in enumerate ( sum ):
1533
1540
if idx != 0 :
1534
- stream .write ("," )
1535
- stream .write (hex (ord (sum [idx ])))
1541
+ stream .write ("," )
1542
+ if isinstance (val , str ):
1543
+ val = ord (val ) # Python 2
1544
+ stream .write (hex (val ))
1536
1545
1537
1546
def genAssign (self , stream , variables ):
1538
1547
for inst in self .statistics :
0 commit comments