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. 16
      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): def padpath2id(path):
if type(path) == str:
path = path.encode("utf-8")
dd, p = os.path.split(path) dd, p = os.path.split(path)
gname = dd.split("/")[-1] gname = dd.split("/")[-1]
p = unquote_plus(p) p = unquote_plus(p)

2
etherpump/commands/creatediffhtml.py

@ -45,6 +45,6 @@ def main(args):
if args.format == "json": if args.format == "json":
print(json.dumps(results)) print(json.dumps(results))
else: else:
print(results['html'].encode("utf-8")) print(results['html'])
except HTTPError as e: except HTTPError as e:
pass pass

5
etherpump/commands/deletepad.py

@ -24,10 +24,9 @@ def main(args):
with open(args.padinfo) as f: with open(args.padinfo) as f:
info = json.load(f) info = json.load(f)
apiurl = info.get("apiurl") apiurl = info.get("apiurl")
# apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info)
data = {} data = {}
data['apikey'] = info['apikey'] data['apikey'] = info['apikey']
data['padID'] = args.padid # is utf-8 encoded data['padID'] = args.padid
requesturl = apiurl + 'deletePad?' + urlencode(data) requesturl = apiurl + 'deletePad?' + urlencode(data)
if args.showurl: if args.showurl:
print(requesturl) print(requesturl)
@ -37,4 +36,4 @@ def main(args):
print(json.dumps(results)) print(json.dumps(results))
else: else:
if results['data']: if results['data']:
print(results['data']['text'].encode("utf-8")) print(results['data']['text'])

16
etherpump/commands/dumpcsv.py

@ -17,7 +17,7 @@ padid, groupid, revisions, lastedited, author_ids
groupid is without (g. $) groupid is without (g. $)
revisions is an integral number of edits revisions is an integral number of edits
lastedited is ISO8601 formatted 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+)\$") groupnamepat = re.compile(r"^g\.(\w+)\$")
@ -69,7 +69,7 @@ def main(args):
if len(msg) > maxmsglen: if len(msg) > maxmsglen:
maxmsglen = len(msg) maxmsglen = len(msg)
sys.stderr.write("\r{0}".format(" " * maxmsglen)) sys.stderr.write("\r{0}".format(" " * maxmsglen))
sys.stderr.write(msg.encode("utf-8")) sys.stderr.write(msg)
sys.stderr.flush() sys.stderr.flush()
m = groupnamepat.match(padid) m = groupnamepat.match(padid)
if m: if m:
@ -79,7 +79,7 @@ def main(args):
groupname = "" groupname = ""
padidnogroup = padid padidnogroup = padid
data['padID'] = padid.encode("utf-8") data['padID'] = padid
revisions = jsonload(apiurl + 'getRevisionsCount?' + urlencode(data))[ revisions = jsonload(apiurl + 'getRevisionsCount?' + urlencode(data))[
'data' 'data'
]['revisions'] ]['revisions']
@ -95,15 +95,9 @@ def main(args):
author_ids = jsonload(apiurl + 'listAuthorsOfPad?' + urlencode(data))[ author_ids = jsonload(apiurl + 'listAuthorsOfPad?' + urlencode(data))[
'data' 'data'
]['authorIDs'] ]['authorIDs']
author_ids = " ".join(author_ids).encode("utf-8") author_ids = " ".join(author_ids)
out.writerow( out.writerow(
( (padidnogroup, groupname, revisions, lastedited_iso, author_ids)
padidnogroup.encode("utf-8"),
groupname.encode("utf-8"),
revisions,
lastedited_iso,
author_ids,
)
) )
count += 1 count += 1

2
etherpump/commands/gethtml.py

@ -41,4 +41,4 @@ def main(args):
if args.format == "json": if args.format == "json":
print(json.dumps(results)) print(json.dumps(results))
else: 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") args.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"]) 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.siteurl = args.siteurl or padurlbase
args.utcnow = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000") 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") apiurl = info.get("apiurl")
data = {} data = {}
data['apikey'] = info['apikey'] data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8") data['padID'] = args.padid
requesturl = apiurl + 'listAuthorsOfPad?' + urlencode(data) requesturl = apiurl + 'listAuthorsOfPad?' + urlencode(data)
if args.showurl: if args.showurl:
print(requesturl) print(requesturl)
@ -36,4 +36,4 @@ def main(args):
print(json.dumps(results)) print(json.dumps(results))
else: else:
for r in results: 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") args.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"]) 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.siteurl = args.siteurl or padurlbase
args.utcnow = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000") 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.common import *
from etherpump.commands.html5tidy import html5tidy from etherpump.commands.html5tidy import html5tidy
# debugging
# import ElementTree as ET
""" """
pull(meta): pull(meta):
@ -199,10 +197,10 @@ def main(args):
continue continue
progressbar(i, numpads, padid) progressbar(i, numpads, padid)
data['padID'] = padid.encode("utf-8") data['padID'] = padid
p = padpath(padid, args.pub, args.group, args.fix_names) p = padpath(padid, args.pub, args.group, args.fix_names)
if args.folder: if args.folder:
p = os.path.join(p, padid.encode("utf-8")) p = os.path.join(p, padid)
metapath = p + ".meta.json" metapath = p + ".meta.json"
revisions = None revisions = None
@ -210,8 +208,7 @@ def main(args):
skip = False skip = False
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"]) padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"])
meta = {} meta = {}
# if type(padurlbase) == unicode:
# padurlbase = padurlbase.encode("utf-8")
while True: while True:
try: try:
if os.path.exists(metapath): if os.path.exists(metapath):
@ -226,7 +223,7 @@ def main(args):
skip = True skip = True
break break
meta['padid'] = padid # .encode("utf-8") meta['padid'] = padid
versions = meta["versions"] = [] versions = meta["versions"] = []
versions.append( versions.append(
{ {
@ -421,7 +418,6 @@ def main(args):
links=links, links=links,
) )
with open(ver["path"], "w") as f: with open(ver["path"], "w") as f:
# f.write(html.encode("utf-8"))
print( print(
ET.tostring(doc, method="html", encoding="unicode"), ET.tostring(doc, method="html", encoding="unicode"),
file=f, file=f,
@ -453,7 +449,6 @@ def main(args):
links=links, links=links,
) )
with open(ver["path"], "w") as f: with open(ver["path"], "w") as f:
# f.write(html.encode("utf-8"))
print( print(
ET.tostring(doc, method="html", encoding="unicode"), ET.tostring(doc, method="html", encoding="unicode"),
file=f, file=f,

2
etherpump/commands/revisionscount.py

@ -21,7 +21,7 @@ def main(args):
apiurl = info.get("apiurl") apiurl = info.get("apiurl")
data = {} data = {}
data['apikey'] = info['apikey'] data['apikey'] = info['apikey']
data['padID'] = args.padid.encode("utf-8") data['padID'] = args.padid
requesturl = apiurl + 'getRevisionsCount?' + urlencode(data) requesturl = apiurl + 'getRevisionsCount?' + urlencode(data)
if args.showurl: if args.showurl:
print(requesturl) print(requesturl)

2
etherpump/commands/showmeta.py

@ -35,4 +35,4 @@ def main(args):
formatstr = args.format.decode("utf-8") formatstr = args.format.decode("utf-8")
formatstr = re.sub(r"{(\w+)}", r"{0[\1]}", formatstr) formatstr = re.sub(r"{(\w+)}", r"{0[\1]}", formatstr)
print(formatstr.format(meta).encode("utf-8")) print(formatstr.format(meta))

Loading…
Cancel
Save