Changeset 20 for lib/bletchley/blobtools.py
- Timestamp:
- 12/06/12 18:35:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/bletchley/blobtools.py
r1 r20 41 41 def isExample(self, blob): 42 42 sblob = frozenset(blob) 43 return ((self.charset == None or sblob.issubset(self.charset)) and self.extraTests(blob)) 43 if self.charset != None and not sblob.issubset(self.charset): 44 return False 45 return self.extraTests(blob) 44 46 45 47 def extraTests(self, blob): 48 """May return True, False, or None, for is an example, isn't an 49 example, or unknown, respectively. 50 51 """ 46 52 return True 47 53 … … 254 260 chunks = blob.split('%') 255 261 if len(chunks) < 2: 256 return False262 return None 257 263 for c in chunks[1:]: 258 264 if len(c) < 2: … … 320 326 321 327 def possibleEncodings(blob): 322 ret_val = set() 328 likely = set() 329 possible = set() 323 330 for name,encoding in encodings.items(): 324 if encoding.isExample(blob): 325 ret_val.add(name) 326 return ret_val 331 result = encoding.isExample(blob) 332 if result == True: 333 likely.add(name) 334 elif result == None: 335 possible.add(name) 336 return likely,possible 327 337 328 338 329 339 def encodingIntersection(blobs): 330 340 ret_val = set(encodings.keys()) 341 p = set(encodings.keys()) 331 342 for b in blobs: 332 ret_val &= possibleEncodings(b) 333 334 return ret_val 343 likely,possible = possibleEncodings(b) 344 ret_val &= likely | possible 345 p &= possible 346 return ret_val - p 335 347 336 348 … … 404 416 405 417 418 #XXX: move this to buffertools 406 419 def smartPermutateBlobs(blobs, block_size=8): 407 420 """
Note: See TracChangeset
for help on using the changeset viewer.