Browse Source

Avoid encoding issues with Python 3

pull/8/head
Luke Murphy 5 years ago
parent
commit
9f17a039a4
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 2
      etherpump/commands/common.py
  2. 2
      etherpump/commands/creatediffhtml.py
  3. 5
      etherpump/commands/deletepad.py
  4. 14
      etherpump/commands/dumpcsv.py
  5. 2
      etherpump/commands/gethtml.py
  6. 2
      etherpump/commands/index.py
  7. 4
      etherpump/commands/listauthors.py
  8. 2
      etherpump/commands/publication.py
  9. 13
      etherpump/commands/pull.py
  10. 2
      etherpump/commands/revisionscount.py
  11. 2
      etherpump/commands/showmeta.py

2
etherpump/commands/common.py

@ -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)

2
etherpump/commands/creatediffhtml.py

@ -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

5
etherpump/commands/deletepad.py

@ -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'])

14
etherpump/commands/dumpcsv.py

@ -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

2
etherpump/commands/gethtml.py

@ -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'])

2
etherpump/commands/index.py

@ -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")

4
etherpump/commands/listauthors.py

@ -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)

2
etherpump/commands/publication.py

@ -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")

13
etherpump/commands/pull.py

@ -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,

2
etherpump/commands/revisionscount.py

@ -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)

2
etherpump/commands/showmeta.py

@ -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…
Cancel
Save