diff --git a/etherpump/commands/common.py b/etherpump/commands/common.py index b694ff2..0946198 100644 --- a/etherpump/commands/common.py +++ b/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) - diff --git a/etherpump/commands/gettext.py b/etherpump/commands/gettext.py index ed9a899..6ac1c65 100644 --- a/etherpump/commands/gettext.py +++ b/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): diff --git a/etherpump/commands/index.py b/etherpump/commands/index.py index 42a06e4..a7f0293 100644 --- a/etherpump/commands/index.py +++ b/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) diff --git a/etherpump/commands/init.py b/etherpump/commands/init.py index a4fc4fa..a8d2b2b 100644 --- a/etherpump/commands/init.py +++ b/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... diff --git a/etherpump/commands/list.py b/etherpump/commands/list.py index 6de1ad1..9a686ca 100644 --- a/etherpump/commands/list.py +++ b/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) - diff --git a/etherpump/commands/publication.py b/etherpump/commands/publication.py index d2e8fa9..81f7d0d 100644 --- a/etherpump/commands/publication.py +++ b/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', diff --git a/etherpump/commands/pull.py b/etherpump/commands/pull.py index 66716fd..a50d0bb 100644 --- a/etherpump/commands/pull.py +++ b/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