Skip to content

Commit

Permalink
get lost changes from pypi's 0.6.0 -- py3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
agroszer committed Feb 26, 2015
1 parent ef7ee89 commit 2786169
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
5 changes: 3 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CHANGES
=======

0.5.5 (unreleased)
0.6.0 (2013-03-27)
------------------

- ...
- Added support for Python 3.3.


0.5.4 (2012-11-16)
------------------
Expand Down
22 changes: 13 additions & 9 deletions src/refline/srccheck/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

INDENT = ' '

try:
STR = basestring # Py2
except NameError:
STR = str # Py3


class BaseChecker(object):
fnameprinted = False
Expand All @@ -39,19 +44,19 @@ def log(self, lineidx=0, line=None, pos=None, noInfo=False):
filename = self.filename.replace('\\', '/')
filename = filename[len(self.basename) + 1:]
print
print filename
print '-' * len(filename)
print(filename)
print('-' * len(filename))
self.fnameprinted = True

print "%s%s" % (INDENT, self.error)
print("%s%s" % (INDENT, self.error))

if noInfo:
return

lineidx = str(lineidx + 1) + ': '
print "%s%s%s" % (INDENT, lineidx, line)
print("%s%s%s" % (INDENT, lineidx, line))
if pos is not None:
print "%s%s^" % (INDENT, ' ' * (len(lineidx) + pos))
print("%s%s^" % (INDENT, ' ' * (len(lineidx) + pos)))

def check(self, filename, content, lines):
pass
Expand Down Expand Up @@ -143,10 +148,10 @@ def check(self, filename, content, lines):
content = self.fixcontent(lines)
try:
result = pyflakes.check(content, filename)
except Exception, e:
except Exception as e:
result = "Fatal exception in pyflakes: %s" % e

if isinstance(result, basestring):
if isinstance(result, STR):
#something fatal occurred
self.error = result
self.log(noInfo=True)
Expand Down Expand Up @@ -329,7 +334,6 @@ def run(self):

for root, dirs, files in os.walk(top, topdown=True):
#keep the name order
dirs.sort()
files.sort()
for name in files:
ignoreThis = False
Expand All @@ -345,7 +349,7 @@ def run(self):

if ext in self.extensions:
#read file once, pass the content to checkers
content = open(fullname, 'rb').read()
content = open(fullname).read()

if 'checker_ignore_this_file' in content:
continue
Expand Down
14 changes: 7 additions & 7 deletions src/refline/srccheck/pyflakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Implementation of the command-line I{pyflakes} tool.
"""

import compiler, sys
import sys
import os
import _ast

Expand Down Expand Up @@ -36,7 +36,7 @@ def check(codeString, filename):
if sys.version_info[:2] == (2, 4):
raise SyntaxError(None)
raise
except (SyntaxError, IndentationError), value:
except (SyntaxError, IndentationError) as value:
msg = value.args[0]

(lineno, offset, text) = value.lineno, value.offset, value.text
Expand All @@ -46,7 +46,7 @@ def check(codeString, filename):
# Avoid using msg, since for the only known case, it contains a
# bogus message that claims the encoding the file declared was
# unknown.
return ["%s: problem decoding source" % (filename, )]
return "%s: problem decoding source" % (filename, )
else:
line = text.splitlines()[-1]

Expand All @@ -58,13 +58,13 @@ def check(codeString, filename):
if offset is not None:
result += '\n'+" " * offset+"^"

return [result]
return result
else:
# Okay, it's syntactically valid. Now parse it into an ast and check
# it.
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
w = checker.Checker(tree, filename)
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
w.messages.sort(key=lambda x: x.lineno)
return w.messages


Expand All @@ -75,8 +75,8 @@ def checkPath(filename):
@return: the number of warnings printed
"""
try:
return check(file(filename, 'U').read() + '\n', filename)
except IOError, msg:
return check(open(filename, 'U').read() + '\n', filename)
except IOError as msg:
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
return 1

Expand Down
2 changes: 1 addition & 1 deletion src/refline/srccheck/testing/bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def doit():
foo = bar

def with_tab():
print "there's a tab"
print("there's a tab")
15 changes: 9 additions & 6 deletions src/refline/srccheck/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
##############################################################################
"""
$Id$
$Id: tests.py 130168 2013-03-26 23:51:48Z alga $
"""
import unittest
import doctest
import re

from zope.testing.renormalizing import RENormalizing


def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
optionflags=doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS,
),
))
return doctest.DocFileSuite(
'README.txt',
optionflags=doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS,
checker=RENormalizing([(re.compile(u"u':'"), "':'")])
)

0 comments on commit 2786169

Please sign in to comment.