Avoid encoding issues with Python 3
This commit is contained in:
parent
bc3f0bb703
commit
9f17a039a4
@ -45,8 +45,6 @@ def padpath(padid, pub_path="", group_path="", normalize=False):
|
||||
|
||||
|
||||
def padpath2id(path):
|
||||
if type(path) == str:
|
||||
path = path.encode("utf-8")
|
||||
dd, p = os.path.split(path)
|
||||
gname = dd.split("/")[-1]
|
||||
p = unquote_plus(p)
|
||||
|
@ -45,6 +45,6 @@ def main(args):
|
||||
if args.format == "json":
|
||||
print(json.dumps(results))
|
||||
else:
|
||||
print(results['html'].encode("utf-8"))
|
||||
print(results['html'])
|
||||
except HTTPError as e:
|
||||
pass
|
||||
|
@ -24,10 +24,9 @@ def main(args):
|
||||
with open(args.padinfo) as f:
|
||||
info = json.load(f)
|
||||
apiurl = info.get("apiurl")
|
||||
# apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
|
||||
data = {}
|
||||
data['apikey'] = info['apikey']
|
||||
data['padID'] = args.padid # is utf-8 encoded
|
||||
data['padID'] = args.padid
|
||||
requesturl = apiurl + 'deletePad?' + urlencode(data)
|
||||
if args.showurl:
|
||||
print(requesturl)
|
||||
@ -37,4 +36,4 @@ def main(args):
|
||||
print(json.dumps(results))
|
||||
else:
|
||||
if results['data']:
|
||||
print(results['data']['text'].encode("utf-8"))
|
||||
print(results['data']['text'])
|
||||
|
@ -17,7 +17,7 @@ padid, groupid, revisions, lastedited, author_ids
|
||||
groupid is without (g. $)
|
||||
revisions is an integral number of edits
|
||||
lastedited is ISO8601 formatted
|
||||
author_ids is a space delimited list of internal author IDs
|
||||
author_ids is a space delimited list of internal author IDs
|
||||
"""
|
||||
|
||||
groupnamepat = re.compile(r"^g\.(\w+)\$")
|
||||
@ -69,7 +69,7 @@ def main(args):
|
||||
if len(msg) > maxmsglen:
|
||||
maxmsglen = len(msg)
|
||||
sys.stderr.write("\r{0}".format(" " * maxmsglen))
|
||||
sys.stderr.write(msg.encode("utf-8"))
|
||||
sys.stderr.write(msg)
|
||||
sys.stderr.flush()
|
||||
m = groupnamepat.match(padid)
|
||||
if m:
|
||||
@ -79,7 +79,7 @@ def main(args):
|
||||
groupname = ""
|
||||
padidnogroup = padid
|
||||
|
||||
data['padID'] = padid.encode("utf-8")
|
||||
data['padID'] = padid
|
||||
revisions = jsonload(apiurl + 'getRevisionsCount?' + urlencode(data))[
|
||||
'data'
|
||||
]['revisions']
|
||||
@ -95,15 +95,9 @@ def main(args):
|
||||
author_ids = jsonload(apiurl + 'listAuthorsOfPad?' + urlencode(data))[
|
||||
'data'
|
||||
]['authorIDs']
|
||||
author_ids = " ".join(author_ids).encode("utf-8")
|
||||
author_ids = " ".join(author_ids)
|
||||
out.writerow(
|
||||
(
|
||||
padidnogroup.encode("utf-8"),
|
||||
groupname.encode("utf-8"),
|
||||
revisions,
|
||||
lastedited_iso,
|
||||
author_ids,
|
||||
)
|
||||
(padidnogroup, groupname, revisions, lastedited_iso, author_ids)
|
||||
)
|
||||
count += 1
|
||||
|
||||
|
@ -41,4 +41,4 @@ def main(args):
|
||||
if args.format == "json":
|
||||
print(json.dumps(results))
|
||||
else:
|
||||
print(results['html'].encode("utf-8"))
|
||||
print(results['html'])
|
||||
|
@ -340,8 +340,6 @@ def main(args):
|
||||
args.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"])
|
||||
# if type(padurlbase) == unicode:
|
||||
# padurlbase = padurlbase.encode("utf-8")
|
||||
args.siteurl = args.siteurl or padurlbase
|
||||
args.utcnow = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
|
||||
|
||||
|
@ -26,7 +26,7 @@ def main(args):
|
||||
apiurl = info.get("apiurl")
|
||||
data = {}
|
||||
data['apikey'] = info['apikey']
|
||||
data['padID'] = args.padid.encode("utf-8")
|
||||
data['padID'] = args.padid
|
||||
requesturl = apiurl + 'listAuthorsOfPad?' + urlencode(data)
|
||||
if args.showurl:
|
||||
print(requesturl)
|
||||
@ -36,4 +36,4 @@ def main(args):
|
||||
print(json.dumps(results))
|
||||
else:
|
||||
for r in results:
|
||||
print(r.encode("utf-8"))
|
||||
print(r)
|
||||
|
@ -341,8 +341,6 @@ def main(args):
|
||||
args.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"])
|
||||
# if type(padurlbase) == unicode:
|
||||
# padurlbase = padurlbase.encode("utf-8")
|
||||
args.siteurl = args.siteurl or padurlbase
|
||||
args.utcnow = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
|
||||
|
||||
|
@ -15,8 +15,6 @@ import html5lib
|
||||
from etherpump.commands.common import *
|
||||
from etherpump.commands.html5tidy import html5tidy
|
||||
|
||||
# debugging
|
||||
# import ElementTree as ET
|
||||
|
||||
"""
|
||||
pull(meta):
|
||||
@ -199,10 +197,10 @@ def main(args):
|
||||
continue
|
||||
progressbar(i, numpads, padid)
|
||||
|
||||
data['padID'] = padid.encode("utf-8")
|
||||
data['padID'] = padid
|
||||
p = padpath(padid, args.pub, args.group, args.fix_names)
|
||||
if args.folder:
|
||||
p = os.path.join(p, padid.encode("utf-8"))
|
||||
p = os.path.join(p, padid)
|
||||
|
||||
metapath = p + ".meta.json"
|
||||
revisions = None
|
||||
@ -210,8 +208,7 @@ def main(args):
|
||||
skip = False
|
||||
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"])
|
||||
meta = {}
|
||||
# if type(padurlbase) == unicode:
|
||||
# padurlbase = padurlbase.encode("utf-8")
|
||||
|
||||
while True:
|
||||
try:
|
||||
if os.path.exists(metapath):
|
||||
@ -226,7 +223,7 @@ def main(args):
|
||||
skip = True
|
||||
break
|
||||
|
||||
meta['padid'] = padid # .encode("utf-8")
|
||||
meta['padid'] = padid
|
||||
versions = meta["versions"] = []
|
||||
versions.append(
|
||||
{
|
||||
@ -421,7 +418,6 @@ def main(args):
|
||||
links=links,
|
||||
)
|
||||
with open(ver["path"], "w") as f:
|
||||
# f.write(html.encode("utf-8"))
|
||||
print(
|
||||
ET.tostring(doc, method="html", encoding="unicode"),
|
||||
file=f,
|
||||
@ -453,7 +449,6 @@ def main(args):
|
||||
links=links,
|
||||
)
|
||||
with open(ver["path"], "w") as f:
|
||||
# f.write(html.encode("utf-8"))
|
||||
print(
|
||||
ET.tostring(doc, method="html", encoding="unicode"),
|
||||
file=f,
|
||||
|
@ -21,7 +21,7 @@ def main(args):
|
||||
apiurl = info.get("apiurl")
|
||||
data = {}
|
||||
data['apikey'] = info['apikey']
|
||||
data['padID'] = args.padid.encode("utf-8")
|
||||
data['padID'] = args.padid
|
||||
requesturl = apiurl + 'getRevisionsCount?' + urlencode(data)
|
||||
if args.showurl:
|
||||
print(requesturl)
|
||||
|
@ -35,4 +35,4 @@ def main(args):
|
||||
|
||||
formatstr = args.format.decode("utf-8")
|
||||
formatstr = re.sub(r"{(\w+)}", r"{0[\1]}", formatstr)
|
||||
print(formatstr.format(meta).encode("utf-8"))
|
||||
print(formatstr.format(meta))
|
||||
|
Loading…
Reference in New Issue
Block a user