def update_fileinfo(cls, fileinfo, document=None): try: buffer = open(fileinfo.fullpathname, 'rb').read(1024) enc = get_encoding(buffer) if enc: enc = encodingdef.normalize_encname(enc, fileinfo.encoding) fileinfo.encoding = enc except IOError: pass
def update_fileinfo(cls, fileinfo, document=None): if not document: try: with open(fileinfo.fullpathname, 'rb') as buffer: s = buffer.read(1024) except IOError: return else: s = document.gettext(0, 1024).encode('utf-8', errors='ignore') m = re.search(rb'@charset\s+(' + rb'"([^"]+)"|' + rb"('[^']+'))", s) if m: enc = str(m.group(2) or m.group(3), 'utf-8', 'replace').strip() enc = encodingdef.normalize_encname(enc, fileinfo.encoding) fileinfo.encoding = enc
def update_fileinfo(cls, fileinfo, document=None): if not document: try: with open(fileinfo.fullpathname, 'rb') as buffer: s = buffer.read(1024) except IOError: return else: s = document.gettext(0, 1024).encode('utf-8', errors='ignore') m = re.search( rb'@charset\s+(' + rb'"([^"]+)"|' + rb"('[^']+'))", s) if m: enc = str(m.group(2) or m.group(3), 'utf-8', 'replace').strip() enc = encodingdef.normalize_encname(enc, fileinfo.encoding) fileinfo.encoding = enc
def adjust_encoding(self, encoding): if encoding.lower() == 'shiftjis': return 'cp932' encoding = encodingdef.normalize_encname(encoding) return encoding