def asWebArchive(self): """ Convert the MHT archive to a webarchive. """ rootType, rootText = self.parts[self.root] pageResource = WebResource.alloc( ).initWithData_URL_MIMEType_textEncodingName_frameName_( NSData.dataWithBytes_length_(rootText.replace(b"\\", b"/"), len(rootText)), NSURL.URLWithString_(self.fixupURL(self.root)), NSString.stringWithString_(rootType), None, None, ) resources = [] for url in self.parts: if url == self.root: continue tp, data = self.parts[url] resources.append(WebResource.alloc( ).initWithData_URL_MIMEType_textEncodingName_frameName_( NSData.dataWithBytes_length_(data, len(data)), NSURL.URLWithString_(self.fixupURL(url)), NSString.stringWithString_(tp), None, None, )) return WebArchive.alloc( ).initWithMainResource_subresources_subframeArchives_( pageResource, resources, None)
def asWebArchive(self): """ Convert the MHT archive to a webarchive. """ rootType, rootText = self.parts[self.root] pageResource = WebResource.alloc().initWithData_URL_MIMEType_textEncodingName_frameName_( NSData.dataWithBytes_length_(rootText.replace(b"\\", b"/"), len(rootText)), NSURL.URLWithString_(self.fixupURL(self.root)), NSString.stringWithString_(rootType), None, None) resources = [] for url in self.parts: if url == self.root: continue tp, data = self.parts[url] resources.append(WebResource.alloc().initWithData_URL_MIMEType_textEncodingName_frameName_( NSData.dataWithBytes_length_(data, len(data)), NSURL.URLWithString_(self.fixupURL(url)), NSString.stringWithString_(tp), None, None)) return WebArchive.alloc().initWithMainResource_subresources_subframeArchives_( pageResource, resources, None)
def guesses(checker, string, _range): from Cocoa import NSString, NSRange _string = NSString.stringWithString_(string) _words = checker.guessesForWordRange_inString_language_inSpellDocumentWithTag_(_range, _string, None, 0) n = len(_words) words = u', '.join(_words) # logger.info('Guesses: ' + words) return n, words
def guesses(checker, string, _range): from Cocoa import NSString, NSRange _string = NSString.stringWithString_(string) _words = checker.guessesForWordRange_inString_language_inSpellDocumentWithTag_(_range, _string, None, 0) n = len(_words) words = u', '.join(_words) logger.info('Guesses: %s', words) return n, words
def check_spelling(checker, string, start=0): from Cocoa import NSString _string = NSString.stringWithString_(string) _range, _count = checker.checkSpellingOfString_startingAt_language_wrap_inSpellDocumentWithTag_wordCount_(_string, start, None, False, 0, None) # logger.debug('Check spelling: %s range: %s count: %d' % (string.encode('utf-8'), _range, _count)) if _range.length == 0: return True, _count, None, None else: word = string[_range.location:_range.location+_range.length] # logger.info('Misspelled word: ' + word.encode('utf-8')) return False, _count, _range, word
def check_spelling(checker, string, start=0): from Cocoa import NSString _string = NSString.stringWithString_(string) _range, _count = checker.checkSpellingOfString_startingAt_language_wrap_inSpellDocumentWithTag_wordCount_(_string, start, None, False, 0, None) logger.debug('Check spelling: %s range: %s count: %d', string.encode('utf-8'), _range, _count) if _range.length == 0: return True, _count, None, None else: word = string[_range.location:_range.location+_range.length] logger.info('Misspelled word: %s', word.encode('utf-8')) return False, _count, _range, word
def remove_word(checker, word): from Cocoa import NSString _word = NSString.stringWithString_(word) if checker.hasLearnedWord_(_word): logger.info('Unlearning word: %s', word) checker.unlearnWord_(_word)
def ignore_word(checker, word): from Cocoa import NSString _word = NSString.stringWithString_(word) logger.info('Ignoring word: %s', word) checker.ignoreWord_inSpellDocumentWithTag_(_word, 0)
def add_word(checker, word): from Cocoa import NSString _word = NSString.stringWithString_(word) if not checker.hasLearnedWord_(_word): logger.info('Learning word: %s', word) checker.learnWord_(_word)