Fix some `flake8` errors.
#! /usr/bin/env python
import sys, os
-print os.path.abspath(sys.argv[1])
+print(os.path.abspath(sys.argv[1]))
unqoted = urllib.unquote(url.strip())
if unqoted.startswith('file://'):
unqoted = unqoted[len('file://'):]
- print unqoted
+ print(unqoted)
import sys
parser = parse_html(sys.argv[1])
if hasattr(parser, "charset"):
- print parser.charset
+ print(parser.charset)
else:
import chardet
charset = chardet.detect(open(sys.argv[1]).read())["encoding"]
if charset in ("ISO-8859-2", "MacCyrillic"):
charset = "cp1251"
- print charset
+ print(charset)
except:
pass
parser.ParseFile(open(sys.argv[1], 'r'))
except:
pass
- if charset: print charset
+ if charset: print(charset)
infile = open(file)
try:
for line in infile:
- sys.stdout.write(unicode(line, from_charset, "replace").encode(to_charset, "replace"))
+ sys.stdout.write(line.decode(from_charset, "replace").encode(to_charset, "replace"))
except:
infile.close()
else:
for line in sys.stdin:
- sys.stdout.write(unicode(line, from_charset, "replace").encode(to_charset, "replace"))
+ sys.stdout.write(line.decode(from_charset, "replace").encode(to_charset, "replace"))
if from_charset is None:
- raise ValueError, "you must use -f param to name source charset"
+ raise ValueError("you must use -f param to name source charset")
if to_charset is None:
- raise ValueError, "you must use -t param to name destination charset"
+ raise ValueError("you must use -t param to name destination charset")
import tempfile, os, shutil
infile = open(file)
try:
for line in infile:
- sys.stdout.write(unicode(line, from_charset, "replace").encode(to_charset, "xmlcharrefreplace"))
+ sys.stdout.write(line.decode(from_charset, "replace").encode(to_charset, "xmlcharrefreplace"))
except:
infile.close()
else:
for line in sys.stdin:
- sys.stdout.write(unicode(line, from_charset, "replace").encode(to_charset, "xmlcharrefreplace"))
+ sys.stdout.write(line.decode(from_charset, "replace").encode(to_charset, "xmlcharrefreplace"))
reverse = True
address = sys.argv[2]
else:
- print >>sys.stderr, 'Usage: %s [-r] name.domain' % sys.argv[0]
- sys.exit(1)
+ sys.exit('Usage: %s [-r] name.domain' % sys.argv[0])
from m_lib.defenc import default_encoding
if reverse:
- print address.decode("idna").encode(default_encoding)
+ print(address.decode("idna").encode(default_encoding))
else:
- print unicode(address, default_encoding).encode("idna")
+ print(address.decode(default_encoding).encode("idna"))
}
def latin1_to_ascii(uinput):
- if not isinstance(uinput, unicode):
- uinput = unicode(uinput, sys.getfilesystemencoding())
+ if isinstance(uinput, bytes):
+ uinput = uinput.decode(sys.getfilesystemencoding())
out = []
for c in uinput:
i = ord(c)
if '.' in mc_version:
major, minor = [int(v) for v in mc_version.split('.')[:2]]
if major < 4:
- print 'old'
+ print('old')
elif (major == 4) and (minor < 6):
- print 'old'
+ print('old')
else:
- print 'new'
+ print('new')
else:
- print 'new'
+ print('new')
if os.path.exists(filename) and \
os.path.isfile(filename):
newname = _recode(filename)
- if newname <> filename:
+ if newname != filename:
os.rename(filename, newname)
os.chdir('..')
dirname = os.path.basename(dirname)
newname = _recode(dirname)
- if newname <> dirname:
+ if newname != dirname:
os.rename(dirname, newname)
os.chdir(save_dir)
elif dst_encoding == "cp1251":
from m_lib.rus.lat2rus import lat2win as _recode
else:
- raise NotImplementedError, "destination encoding must be koi8-r or cp1251, not `%s'" % dst_encoding
+ raise NotImplementedError("destination encoding must be koi8-r or cp1251, not `%s'" % dst_encoding)
elif dst_encoding == "translit":
if src_encoding == "koi8-r":
elif src_encoding == "cp1251":
from m_lib.rus.rus2lat import win2lat as _recode
else:
- raise NotImplementedError, "source encoding must be koi8-r or cp1251, not `%s'" % src_encoding
+ raise NotImplementedError("source encoding must be koi8-r or cp1251, not `%s'" % src_encoding)
from m_lib.rus.rus2lat import koi2lat_d
koi2lat_d["ะช"] = '' # remove apostrophs -
import urllib
def _recode(s):
s = urllib.unquote(s)
- if src_encoding <> dst_encoding:
+ if src_encoding != dst_encoding:
s = recode(s, src_encoding, dst_encoding, "replace")
return s
from m_lib.opstring import recode
import urllib
def _recode(s):
- if src_encoding <> dst_encoding:
+ if src_encoding != dst_encoding:
s = recode(s, src_encoding, dst_encoding, "replace")
return urllib.quote(s, safe=";/?:@&=+$,()'") # wget treats them as safe
import os
for filename in sys.argv[3:]:
new_name = _recode(filename)
- if new_name <> filename:
+ if new_name != filename:
os.rename(filename, new_name)
for zinfo in zf.infolist():
path = zinfo.filename
- if not isinstance(path, unicode):
+ if isinstance(path, bytes):
path = path.decode('cp866')
recoded_path = path.encode(default_encoding)
- print recoded_path
+ print(recoded_path)
if path.startswith('./'):
recoded_path = recoded_path[2:]
def addToZip(zf, path):
if os.path.isfile(path):
- print path
+ print(path)
recoded_path = path.decode(default_encoding).encode('cp866')
zf.write(path, recoded_path, ZIP_DEFLATED)
elif os.path.isdir(path):