many pep8 improvements

This commit is contained in:
mdipierro
2012-10-19 12:33:53 -05:00
parent 71ec15190b
commit 6aa5edc7ff
117 changed files with 7160 additions and 5670 deletions
+10 -7
View File
@@ -54,14 +54,14 @@ UNPICKLABLE_TYPES = (
types.TypeType,
types.ClassType,
types.FunctionType,
)
)
# Unpicklable statements to seed new historys with.
INITIAL_UNPICKLABLES = [
'import logging',
'import os',
'import sys',
]
]
class History:
@@ -154,6 +154,7 @@ class History:
if name in self.unpicklable_names:
self.unpicklable_names.remove(name)
def represent(obj):
"""Returns a string representing the given object's value, which should allow the
code below to determine whether the object changes over time.
@@ -163,6 +164,7 @@ def represent(obj):
except:
return repr(obj)
def run(history, statement, env={}):
"""
Evaluates a python statement in a given history and returns the result.
@@ -180,7 +182,6 @@ def run(history, statement, env={}):
# single-line expressions such as 'class Foo: pass' evaluate happily.
statement += '\n\n'
# log and compile the statement up front
try:
logging.info('Compiling and evaluating:\n%s' % statement)
@@ -224,7 +225,8 @@ def run(history, statement, env={}):
history.remove_global(name)
# run!
old_globals = dict((key,represent(value)) for key,value in statement_module.__dict__.items())
old_globals = dict((key, represent(
value)) for key, value in statement_module.__dict__.items())
try:
old_stdout, old_stderr = sys.stdout, sys.stderr
try:
@@ -261,6 +263,7 @@ def run(history, statement, env={}):
sys.modules['__main__'] = old_main
return output.getvalue()
if __name__=='__main__':
history=History()
while True: print run(history, raw_input('>>> ')).rstrip()
if __name__ == '__main__':
history = History()
while True:
print run(history, raw_input('>>> ')).rstrip()