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 math import ceil, floor
from time import sleep from time import sleep
try: from urllib.parse import urlparse, urlunparse, urlencode, quote_plus, unquote_plus
# python2 from urllib.request import urlopen, URLError, HTTPError
from urllib.parse import urlparse, urlunparse from html.entities import name2codepoint
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
groupnamepat = re.compile(r"^g\.(\w+)\$") groupnamepat = re.compile(r"^g\.(\w+)\$")
def splitpadname (padid): def splitpadname (padid):
@ -32,10 +20,6 @@ def padurl (padid, ):
def padpath (padid, pub_path="", group_path="", normalize=False): def padpath (padid, pub_path="", group_path="", normalize=False):
g, p = splitpadname(padid) 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) p = quote_plus(p)
if normalize: if normalize:
p = p.replace(" ", "_") p = p.replace(" ", "_")
@ -128,4 +112,3 @@ def unescape(text):
pass pass
return text # leave as is return text # leave as is
return re.sub("&#?\w+;", fixup, text) return re.sub("&#?\w+;", fixup, text)

11
etherpump/commands/gettext.py

@ -1,15 +1,8 @@
from argparse import ArgumentParser from argparse import ArgumentParser
import json, sys import json, sys
try: from urllib.parse import urlencode
# python2 from urllib.request import urlopen, URLError, HTTPError
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
def main(args): def main(args):

20
etherpump/commands/index.py

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

15
etherpump/commands/init.py

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

14
etherpump/commands/list.py

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

24
etherpump/commands/publication.py

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

21
etherpump/commands/pull.py

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

11
etherpump/commands/settext.py

@ -2,15 +2,8 @@
from argparse import ArgumentParser from argparse import ArgumentParser
import json, sys import json, sys
try: from urllib.parse import urlencode, quote
# python2 from urllib.request import urlopen, URLError, HTTPError
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
import requests import requests

Loading…
Cancel
Save