diff --git a/.gitignore b/.gitignore index b7f1837b3..88e5fd147 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,3 @@ site/write/* tests/corpus/newyorker/* cache/* proselint/cache/* -proselintMDP.sublime-project -proselintMDP.sublime-workspace diff --git a/app.py b/app.py index 39421ff84..18d7fc72b 100644 --- a/app.py +++ b/app.py @@ -6,14 +6,8 @@ import uuid import os import re +import urllib2 import json -try: - # For Python 3.0 and later - from urllib.parse import unquote -except ImportError: - # Fall back to Python 2's urllib2 - from urllib2 import unquote - app = Flask(__name__) cors = CORS(app) @@ -27,7 +21,7 @@ def lint(): id = uuid.uuid4() filename = os.path.join("tmp", "{}.md".format(id)) - text = unquote(request.values['text']) + text = urllib2.unquote(request.values['text']) with open(filename, "w+") as f: f.write(text) diff --git a/plugins/sublime/SublimeLinter-contrib-proselint/linter.py b/plugins/sublime/SublimeLinter-contrib-proselint/linter.py index d5e04bcf3..a833e6304 100644 --- a/plugins/sublime/SublimeLinter-contrib-proselint/linter.py +++ b/plugins/sublime/SublimeLinter-contrib-proselint/linter.py @@ -16,7 +16,7 @@ class Proselint(Linter): """Provides an interface to proselint.""" - syntax = ('html', 'markdown', 'plain text', 'multimarkdown') + syntax = ('html', 'markdown', 'plain text') cmd = 'proselint' executable = None version_args = '--version' diff --git a/proselint/checks/garner/a_vs_an.py b/proselint/checks/garner/a_vs_an.py index 5e715c06b..596681e47 100644 --- a/proselint/checks/garner/a_vs_an.py +++ b/proselint/checks/garner/a_vs_an.py @@ -80,7 +80,7 @@ def starts_with_vowel_sound(word): def initialize(): """Initialize the cache of pronunciations.""" - print("Running initialization for garner.a_vs_an (may take a few minutes)") + print "Running initialization for garner.a_vs_an (may take a few minutes)" from nltk.corpus import cmudict global d @@ -89,6 +89,6 @@ def initialize(): for i, word in enumerate(d): starts_with_vowel_sound(word) if not (i % 1000): - print(i) + print i assert(d) diff --git a/proselint/checks/misc/linkchecker.py b/proselint/checks/misc/linkchecker.py index 6f7bc7174..c1efbf2b3 100644 --- a/proselint/checks/misc/linkchecker.py +++ b/proselint/checks/misc/linkchecker.py @@ -16,7 +16,7 @@ """ from proselint.tools import memoize import re -import urllib +import urllib2 from socket import error as SocketError @@ -27,7 +27,7 @@ def check(blob): msg = u"Broken link: {}" regex = re.compile( - r"""(?i)\b((?:https?://|www\d{0,3}[.] + ur"""(?i)\b((?:https?://|www\d{0,3}[.] |[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+ |(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\) |[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019\u21a9]))""", @@ -50,11 +50,10 @@ def check(blob): def is_broken_link(url): """Check if the link return a 404 error.""" try: - request = urllib.request.Request( - url, headers={'User-Agent': 'Mozilla/5.0'}) - urllib.request.urlopen(request).read() + request = urllib2.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) + urllib2.urlopen(request).read() return False - except urllib.error.URLError: + except urllib2.URLError: return True except SocketError: return True diff --git a/proselint/command_line.py b/proselint/command_line.py index 684cbffce..6c895f57e 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -100,14 +100,14 @@ def lintscore(): fullpath = os.path.join(root, f) # Run the linter. - print("Linting {}".format(f)) + print "Linting {}".format(f) out = subprocess.check_output( "proselint {}".format(fullpath), shell=True) # Determine the number of errors. regex = r".+?:(?P\d+):(?P\d+): (?P.+)" num_errors = len(tuple(re.finditer(regex, out))) - print("Found {} errors.".format(num_errors)) + print "Found {} errors.".format(num_errors) # Open the document. subprocess.call("{} {}".format("open", fullpath), shell=True) @@ -126,7 +126,7 @@ def lintscore(): except: pass - print("Currently {} hits and {} false alarms\n---".format(tp, fp)) + print "Currently {} hits and {} false alarms\n---".format(tp, fp) return tp * (1.0 * tp / (tp + fp)) ** 2 @@ -142,7 +142,7 @@ def proselint( """Define the linter command line API.""" # Return the version number. if version: - print("v0.0.1") + print "v0.0.1" return # Run the intialization. @@ -156,7 +156,7 @@ def proselint( # In debug mode, delete the cache and *.pyc files before running. if debug: - print("Deleting the cache...") + print "Deleting the cache..." subprocess.call("find . -name '*.pyc' -delete", shell=True) subprocess.call( "rm -rfv proselint/cache > /dev/null && mkdir proselint/cache", diff --git a/proselint/tools.py b/proselint/tools.py index 3d463f8f6..22893afa5 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -7,8 +7,6 @@ import inspect import functools import re -import hashlib -from textblob import TextBlob def on_heroku(): @@ -39,11 +37,12 @@ def memoize(f): try: cache = shelve.open(cachepath, protocol=2) except: - print('Could not open cache file %s, maybe name collision' % cachepath) + print 'Could not open cache file %s, maybe name collision' % cachepath cache = None @functools.wraps(f) def wrapped(*args, **kwargs): + argdict = {} # handle instance methods if hasattr(f, '__self__'): @@ -51,13 +50,10 @@ def wrapped(*args, **kwargs): tempargdict = inspect.getcallargs(f, *args, **kwargs) - signature = f.__module__ + '.' + f.__name__ + for k, v in tempargdict.iteritems(): + argdict[k] = v - for item in tempargdict.items(): - if isinstance(item, TextBlob): - signature += tempargdict['blob'].raw - - key = hashlib.sha256(signature.encode('utf-8')).hexdigest() + key = str(hash(frozenset(argdict.items()))) try: return cache[key] @@ -68,8 +64,8 @@ def wrapped(*args, **kwargs): return value except TypeError: call_to = f.__module__ + '.' + f.__name__ - print('Warning: could not disk cache call to ', - '%s; it probably has unhashable args' % (call_to)) + print ['Warning: could not disk cache call to ', + '%s; it probably has unhashable args'] % (call_to) return f(*args, **kwargs) return wrapped