Browse Source

Remove Python 2 cruft

pull/8/head
Luke Murphy 5 years ago
parent
commit
fc9c82c9e5
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 23
      etherpump/commands/common.py
  2. 11
      etherpump/commands/gettext.py
  3. 20
      etherpump/commands/index.py
  4. 15
      etherpump/commands/init.py
  5. 14
      etherpump/commands/list.py
  6. 24
      etherpump/commands/publication.py
  7. 21
      etherpump/commands/pull.py
  8. 11
      etherpump/commands/settext.py

23
etherpump/commands/common.py

@ -3,21 +3,9 @@ import re, os, json, sys
from math import ceil, floor
from time import sleep
try:
# python2
from urllib.parse import urlparse, urlunparse
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
from urllib.parse import quote_plus, unquote_plus
from html.entities import name2codepoint
input = raw_input
except ImportError:
# python3
from urllib.parse import urlparse, urlunparse, urlencode, quote_plus, unquote_plus
from urllib.request import urlopen, URLError, HTTPError
from html.entities import name2codepoint
from urllib.parse import urlparse, urlunparse, urlencode, quote_plus, unquote_plus
from urllib.request import urlopen, URLError, HTTPError
from html.entities import name2codepoint
groupnamepat = re.compile(r"^g\.(\w+)\$")
def splitpadname (padid):
@ -32,10 +20,6 @@ def padurl (padid, ):
def padpath (padid, pub_path="", group_path="", normalize=False):
g, p = splitpadname(padid)
# if type(g) == unicode:
# g = g.encode("utf-8")
# if type(p) == unicode:
# p = p.encode("utf-8")
p = quote_plus(p)
if normalize:
p = p.replace(" ", "_")
@ -128,4 +112,3 @@ def unescape(text):
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)

11
etherpump/commands/gettext.py

@ -1,15 +1,8 @@
from argparse import ArgumentParser
import json, sys
try:
# python2
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
except ImportError:
# python3
from urllib.parse import urlencode
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlencode
from urllib.request import urlopen, URLError, HTTPError
def main(args):

20
etherpump/commands/index.py

@ -4,16 +4,8 @@ import sys, json, re, os, time
from datetime import datetime
import dateutil.parser
try:
# python2
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
from urllib.parse import urlparse, urlunparse
except ImportError:
# python3
from urllib.parse import urlparse, urlunparse, urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlparse, urlunparse, urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from jinja2 import FileSystemLoader, Environment
from etherpump.commands.common import *
@ -117,7 +109,7 @@ def main (args):
pg.add_argument("--prev", default=None, help="prev link, default: None")
args = p.parse_args(args)
tmpath = args.templatepath
# Default path for template is the built-in data/templates
if tmpath == None:
@ -154,11 +146,11 @@ def main (args):
ret['versions'] = [wrappath(x) for x in paths]
lastedited = None
for p in paths:
mtime = os.stat(p).st_mtime
mtime = os.stat(p).st_mtime
if lastedited == None or mtime > lastedited:
lastedited = mtime
ret["lastedited_iso"] = datetime.fromtimestamp(lastedited).strftime("%Y-%m-%dT%H:%M:%S")
ret["lastedited_raw"] = mtime
ret["lastedited_raw"] = mtime
return ret
def loadmeta(p):
@ -224,7 +216,7 @@ def main (args):
if p:
if not has_version(p, x):
print ("Grouping file {0} with pad {1}".format(x, p['padid']), file=sys.stderr)
p['versions'].append(wrappath(x))
p['versions'].append(wrappath(x))
else:
print ("Skipping existing version {0} ({1})...".format(x, p['padid']), file=sys.stderr)
removelist.append(x)

15
etherpump/commands/init.py

@ -1,17 +1,8 @@
from argparse import ArgumentParser
try:
# python2
from urllib.parse import urlparse, urlunparse
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
input = raw_input
except ImportError:
# python3
from urllib.parse import urlparse, urlunparse, urlencode
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlparse, urlunparse, urlencode
from urllib.request import urlopen, URLError, HTTPError
import json, os, sys
@ -52,7 +43,7 @@ def tryapiurl (url, verbose=False):
scheme, netloc, path, params, query, fragment = urlparse(url)
if scheme == "":
url = "http://" + url
scheme, netloc, path, params, query, fragment = urlparse(url)
scheme, netloc, path, params, query, fragment = urlparse(url)
params, query, fragment = ("", "", "")
path = path.strip("/")
# 1. try directly...

14
etherpump/commands/list.py

@ -3,17 +3,8 @@ from argparse import ArgumentParser
import json
import sys
from etherpump.commands.common import getjson
try:
# python2
from urllib.parse import urlparse, urlunparse
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
input = raw_input
except ImportError:
# python3
from urllib.parse import urlparse, urlunparse, urlencode
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlparse, urlunparse, urlencode
from urllib.request import urlopen, URLError, HTTPError
def main (args):
p = ArgumentParser("call listAllPads and print the results")
@ -38,4 +29,3 @@ def main (args):
else:
for r in results:
print (r)

24
etherpump/commands/publication.py

@ -5,16 +5,8 @@ from datetime import datetime
import dateutil.parser
import pypandoc
try:
# python2
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
from urllib.parse import urlparse, urlunparse
except ImportError:
# python3
from urllib.parse import urlparse, urlunparse, urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlparse, urlunparse, urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from jinja2 import FileSystemLoader, Environment
from etherpump.commands.common import *
@ -25,7 +17,7 @@ import dateutil.parser
publication:
Generate a single document from etherpumps using a template.
Built-in templates: publication.html
Built-in templates: publication.html
"""
@ -118,7 +110,7 @@ def main (args):
pg.add_argument("--prev", default=None, help="prev link, default: None")
args = p.parse_args(args)
tmpath = args.templatepath
# Default path for template is the built-in data/templates
if tmpath == None:
@ -155,11 +147,11 @@ def main (args):
ret['versions'] = [wrappath(x) for x in paths]
lastedited = None
for p in paths:
mtime = os.stat(p).st_mtime
mtime = os.stat(p).st_mtime
if lastedited == None or mtime > lastedited:
lastedited = mtime
ret["lastedited_iso"] = datetime.fromtimestamp(lastedited).strftime("%Y-%m-%dT%H:%M:%S")
ret["lastedited_raw"] = mtime
ret["lastedited_raw"] = mtime
return ret
def loadmeta(p):
@ -225,7 +217,7 @@ def main (args):
if p:
if not has_version(p, x):
print ("Grouping file {0} with pad {1}".format(x, p['padid']), file=sys.stderr)
p['versions'].append(wrappath(x))
p['versions'].append(wrappath(x))
else:
print ("Skipping existing version {0} ({1})...".format(x, p['padid']), file=sys.stderr)
removelist.append(x)
@ -263,7 +255,7 @@ def main (args):
elif args.order == "custom":
# TODO: make this list non-static, but a variable that can be given from the CLI
customorder = [
'nooo.relearn.preamble',
'nooo.relearn.activating.the.archive',

21
etherpump/commands/pull.py

@ -3,15 +3,8 @@ from argparse import ArgumentParser
import sys, json, re, os
from datetime import datetime
try:
# python2
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
except ImportError:
# python3
from urllib.parse import urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from etherpump.commands.common import *
from time import sleep
@ -21,7 +14,7 @@ from xml.etree import ElementTree as ET
from fnmatch import fnmatch
# debugging
# import ElementTree as ET
# import ElementTree as ET
"""
pull(meta):
@ -98,7 +91,7 @@ def main (args):
if args.skip != None and i<args.skip:
continue
progressbar(i, numpads, padid)
data['padID'] = padid.encode("utf-8")
p = padpath(padid, args.pub, args.group, args.fix_names)
if args.folder:
@ -121,7 +114,7 @@ def main (args):
if meta['revisions'] == revisions and not args.force:
skip=True
break
meta['padid'] = padid # .encode("utf-8")
versions = meta["versions"] = []
versions.append({
@ -133,7 +126,7 @@ def main (args):
if revisions == None:
meta['revisions'] = getjson(info['localapiurl']+'getRevisionsCount?'+urlencode(data))['data']['revisions']
else:
meta['revisions' ] = revisions
meta['revisions' ] = revisions
if (meta['revisions'] == 0) and (not args.zerorevs):
# print("Skipping zero revs", file=sys.stderr)
@ -226,7 +219,7 @@ def main (args):
html = getjson(info['localapiurl']+'createDiffHTML?'+urlencode(data))
ver = {"type": "diffhtml"}
versions.append(ver)
ver["code"] = html["_code"]
ver["code"] = html["_code"]
if html["_code"] == 200:
try:
html = html['data']['html']

11
etherpump/commands/settext.py

@ -2,15 +2,8 @@
from argparse import ArgumentParser
import json, sys
try:
# python2
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from urllib.parse import urlencode
except ImportError:
# python3
from urllib.parse import urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlencode, quote
from urllib.request import urlopen, URLError, HTTPError
import requests

Loading…
Cancel
Save