@@ -818,7 +818,7 @@ def format(self, obj, context, maxlevels, level):
818
818
except :
819
819
convert = True
820
820
if convert :
821
- return ("0x{}" .format (binascii . hexlify ( obj ) ), True , False )
821
+ return ("0x{}" .format (obj ), True , False )
822
822
return pprint .PrettyPrinter .format (self , obj , context , maxlevels , level )
823
823
824
824
# there is room for more space optimization (like using the tree structure),
@@ -856,17 +856,11 @@ def __call__(self, *args):
856
856
and info ['mtime' ] == getfilemtime_int (path ) \
857
857
and self .f .__name__ in info \
858
858
and cached .usecache :
859
- # NOTE: behavior change: hexlify & unhexlify
860
- #result = info[self.f.__name__]
861
- # TODO: HACK here
862
- if self .f .__name__ == 'crc32' : # it's a int (long), can't unhexlify
863
- result = info [self .f .__name__ ]
864
- else :
865
- result = binascii .unhexlify (info [self .f .__name__ ])
859
+ result = info [self .f .__name__ ]
866
860
if cached .debug :
867
861
pdbg ("Cache hit for file '{}',\n {}: {}\n size: {}\n mtime: {}" .format (
868
862
path , self .f .__name__ ,
869
- result if isinstance ( result , ( int , long , float , complex )) else binascii . hexlify ( result ) ,
863
+ result ,
870
864
info ['size' ], info ['mtime' ]))
871
865
else :
872
866
result = self .f (* args )
@@ -890,20 +884,14 @@ def __store(self, info, path, value):
890
884
cached .dirty = True
891
885
info ['size' ] = getfilesize (path )
892
886
info ['mtime' ] = getfilemtime_int (path )
893
- # NOTE: behavior change: hexlify & unhexlify
894
- #info[self.f.__name__] = value
895
- # TODO: HACK here
896
- if self .f .__name__ == 'crc32' : # it's a int (long), can't hexlify
897
- info [self .f .__name__ ] = value
898
- else :
899
- info [self .f .__name__ ] = binascii .hexlify (value )
887
+ info [self .f .__name__ ] = value
900
888
if cached .debug :
901
889
situation = "Storing cache"
902
890
if cached .usecache :
903
891
situation = "Cache miss"
904
892
pdbg ((situation + " for file '{}',\n {}: {}\n size: {}\n mtime: {}" ).format (
905
893
path , self .f .__name__ ,
906
- value if isinstance ( value , ( int , long , float , complex )) else binascii . hexlify ( value ) ,
894
+ value ,
907
895
info ['size' ], info ['mtime' ]))
908
896
909
897
# periodically save to prevent loss in case of system crash
@@ -1058,7 +1046,7 @@ def md5(filename, slice = OneM):
1058
1046
else :
1059
1047
break
1060
1048
1061
- return m .digest ()
1049
+ return m .hexdigest ()
1062
1050
1063
1051
# slice md5 for baidu rapidupload
1064
1052
@cached
@@ -1068,7 +1056,7 @@ def slice_md5(filename):
1068
1056
buf = f .read (256 * OneK )
1069
1057
m .update (buf )
1070
1058
1071
- return m .digest ()
1059
+ return m .hexdigest ()
1072
1060
1073
1061
@cached
1074
1062
def crc32 (filename , slice = OneM ):
@@ -1126,7 +1114,7 @@ def __str(self, prefix):
1126
1114
result += "{} - {}/{} - size: {} - md5: {} \n " .format (
1127
1115
v .type , prefix , k ,
1128
1116
v .extra ['size' ] if 'size' in v .extra else '' ,
1129
- binascii . hexlify ( v .extra ['md5' ]) if 'md5' in v .extra else '' )
1117
+ v .extra ['md5' ] if 'md5' in v .extra else '' )
1130
1118
1131
1119
for k , v in self .items ():
1132
1120
if v .type == 'D' :
@@ -2139,7 +2127,7 @@ def __verify_current_file(self, j, gotlmd5):
2139
2127
return EHashMismatch
2140
2128
2141
2129
if 'md5' in j :
2142
- rmd5 = binascii . unhexlify ( j ['md5' ])
2130
+ rmd5 = j ['md5' ]
2143
2131
#elif 'block_list' in j and len(j['block_list']) > 0:
2144
2132
# rmd5 = j['block_list'][0]
2145
2133
#else:
@@ -2161,8 +2149,8 @@ def __verify_current_file(self, j, gotlmd5):
2161
2149
if self .__verify :
2162
2150
if not gotlmd5 :
2163
2151
self .__current_file_md5 = md5 (self .__current_file )
2164
- self .pd ("Local file MD5 : {}" .format (binascii . hexlify ( self .__current_file_md5 ) ))
2165
- self .pd ("Remote file MD5: {}" .format (binascii . hexlify ( rmd5 ) ))
2152
+ self .pd ("Local file MD5 : {}" .format (self .__current_file_md5 ))
2153
+ self .pd ("Remote file MD5: {}" .format (rmd5 ))
2166
2154
2167
2155
if self .__current_file_md5 == rmd5 :
2168
2156
self .pd ("Local file and remote file hashes match" )
@@ -2340,7 +2328,7 @@ def __upload_slice_act(self, r, args):
2340
2328
# otherwise, it makes the uploading slower at the end
2341
2329
rsmd5 = j ['md5' ]
2342
2330
self .pd ("Uploaded MD5 slice: " + rsmd5 )
2343
- if self .__current_slice_md5 == binascii . unhexlify ( rsmd5 ) :
2331
+ if self .__current_slice_md5 == rsmd5 :
2344
2332
self .__slice_md5s .append (rsmd5 )
2345
2333
self .pv ("'{}' >>==> '{}' OK." .format (self .__current_file , args ))
2346
2334
return ENoError
@@ -2402,7 +2390,7 @@ def __upload_file_slices(self, localpath, remotepath, ondup = 'overwrite'):
2402
2390
for md in md5s :
2403
2391
cslice = f .read (slice )
2404
2392
cm = hashlib .md5 (cslice )
2405
- if (binascii . hexlify ( cm .digest () ) == md ):
2393
+ if (cm .hexdigest ( ) == md ):
2406
2394
self .pd ("{} verified" .format (md ))
2407
2395
# TODO: a more rigorous check would be also verifying
2408
2396
# slices exist at Baidu Yun as well (rapidupload test?)
@@ -2424,9 +2412,9 @@ def __upload_file_slices(self, localpath, remotepath, ondup = 'overwrite'):
2424
2412
self .__current_slice = f .read (slice )
2425
2413
m = hashlib .md5 ()
2426
2414
m .update (self .__current_slice )
2427
- self .__current_slice_md5 = m .digest ()
2415
+ self .__current_slice_md5 = m .hexdigest ()
2428
2416
self .pd ("Uploading MD5 slice: {}, #{} / {}" .format (
2429
- binascii . hexlify ( self .__current_slice_md5 ) ,
2417
+ self .__current_slice_md5 ,
2430
2418
i + 1 , pieces ))
2431
2419
j = 0
2432
2420
while True :
@@ -2497,8 +2485,8 @@ def __get_hashes_for_rapidupload(self, lpath, setlocalfile = False):
2497
2485
def __rapidupload_file (self , lpath , rpath , ondup = 'overwrite' , setlocalfile = False ):
2498
2486
self .__get_hashes_for_rapidupload (lpath , setlocalfile )
2499
2487
2500
- md5str = binascii . hexlify ( self .__current_file_md5 )
2501
- slicemd5str = binascii . hexlify ( self .__current_file_slice_md5 )
2488
+ md5str = self .__current_file_md5
2489
+ slicemd5str = self .__current_file_slice_md5
2502
2490
crcstr = hex (self .__current_file_crc32 )
2503
2491
return self .__rapidupload_file_post (rpath , self .__current_file_size , md5str , slicemd5str , crcstr , ondup )
2504
2492
@@ -3409,11 +3397,11 @@ def __proceed_remote_gather(self, remotepath, dirjs, filejs, args = None):
3409
3397
dlen = len (remotepath ) + 1
3410
3398
for d in dirjs :
3411
3399
self .__remote_dir_contents .get (remotepath [rootlen :]).add (
3412
- d ['path' ][dlen :], PathDictTree ('D' , size = d ['size' ], md5 = binascii . unhexlify ( d ['md5' ]) ))
3400
+ d ['path' ][dlen :], PathDictTree ('D' , size = d ['size' ], md5 = d ['md5' ]))
3413
3401
3414
3402
for f in filejs :
3415
3403
self .__remote_dir_contents .get (remotepath [rootlen :]).add (
3416
- f ['path' ][dlen :], PathDictTree ('F' , size = f ['size' ], md5 = binascii . unhexlify ( f ['md5' ]) ))
3404
+ f ['path' ][dlen :], PathDictTree ('F' , size = f ['size' ], md5 = f ['md5' ]))
3417
3405
3418
3406
return ENoError
3419
3407
@@ -3837,8 +3825,8 @@ def cdl_cancel(self, task_id):
3837
3825
return self .__cdl_cancel (task_id )
3838
3826
3839
3827
def __get_accept_cmd (self , rpath ):
3840
- md5str = binascii . hexlify ( self .__current_file_md5 )
3841
- slicemd5str = binascii . hexlify ( self .__current_file_slice_md5 )
3828
+ md5str = self .__current_file_md5
3829
+ slicemd5str = self .__current_file_slice_md5
3842
3830
crcstr = hex (self .__current_file_crc32 )
3843
3831
remotepath = rpath [AppPcsPathLen :]
3844
3832
if len (remotepath ) == 0 :
0 commit comments