Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: python
python:
- 3.5
- 3.4
- 3.3
- 2.7
- 2.6
install:
- pip install pep8
- pip install nose
Expand Down
7 changes: 5 additions & 2 deletions bin/pythonect
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ import pprint

try:

import _preamble
import pythonect._preamble

except ImportError:

sys.exc_clear()
try:
sys.exc_clear()
except AttributeError:
pass


import pythonect
Expand Down
4 changes: 2 additions & 2 deletions bin/test/foobar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

if __name__ == "__main__":

print "Goodbye, world"
print("Goodbye, world")

else:

print "Hello, world"
print("Hello, world")
1 change: 0 additions & 1 deletion bin/test/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import sys
import re
import copy
import imp
import shlex
import os
Expand Down
2 changes: 1 addition & 1 deletion examples/palindrome.dia
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dia:attribute name="text">
<dia:composite type="text">
<dia:attribute name="string">
<dia:string>#raw_input("Please enter a word or a number: ")#</dia:string>
<dia:string>#six.moves.input("Please enter a word or a number: ")#</dia:string>
</dia:attribute>
<dia:attribute name="font">
<dia:font family="sans" style="0" name="Helvetica"/>
Expand Down
2 changes: 1 addition & 1 deletion examples/repl.dia
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dia:attribute name="text">
<dia:composite type="text">
<dia:attribute name="string">
<dia:string>#raw_input('$ ')#</dia:string>
<dia:string>#six.moves.input('$ ')#</dia:string>
</dia:attribute>
<dia:attribute name="font">
<dia:font family="sans" style="0" name="Helvetica"/>
Expand Down
4 changes: 2 additions & 2 deletions pythonect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

"""Parse and execute Pythonect code"""

from _version import __version__
from pythonect._version import __version__


# API

from internal.eval import eval, parse
from pythonect.internal.eval import eval, parse
2 changes: 1 addition & 1 deletion pythonect/internal/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

# Local imports

import _ordereddict
from pythonect.internal import _ordereddict


class Graph(networkx.DiGraph):
Expand Down
44 changes: 26 additions & 18 deletions pythonect/internal/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import __builtin__ as python
import six.moves.builtins as python
import threading
import copy
import logging
import importlib
import site
import os
import multiprocessing
import multiprocessing.dummy
Expand All @@ -40,13 +39,21 @@
import networkx
import re
import pprint
import six


try:
# Python 3.4+
import _sitebuiltins as __sitebuiltins
except ImportError:
import site as __sitebuiltins


# Local imports

import parsers
import lang
import _graph
from pythonect.internal import parsers
from pythonect.internal import lang
from pythonect.internal import _graph


# Consts
Expand Down Expand Up @@ -112,7 +119,7 @@ def __pickle_safe_dict(locals_or_globals):

result = dict(locals_or_globals)

for k, v in locals_or_globals.iteritems():
for k, v in six.iteritems(locals_or_globals):

try:

Expand Down Expand Up @@ -175,7 +182,7 @@ def _run_next_virtual_nodes(graph, node, globals_, locals_, flags, pool, result)

# "Hello, world" or {...}

if isinstance(result, (basestring, dict)) or not __isiter(result):
if isinstance(result, (six.string_types, dict)) or not __isiter(result):

not_safe_to_iter = True

Expand Down Expand Up @@ -292,7 +299,8 @@ def __import_module_from_exception(exception, globals_):
# - OR -
# NameError: global name 'os' is not defined

mod_name = exception.message[exception.message.index("'") + 1:exception.message.rindex("'")]
exception_message = str(exception)
mod_name = exception_message[exception_message.index("'") + 1:exception_message.rindex("'")]

globals_.update({mod_name: importlib.import_module(mod_name)})

Expand Down Expand Up @@ -402,7 +410,7 @@ def __node_main(current_value, last_value, globals_, locals_):

# Due to eval()?

if (e.message == 'eval() arg 1 must be a string or code object'):
if (str(e) == 'eval() arg 1 must be a string or code object'):

return_value = current_value

Expand Down Expand Up @@ -432,7 +440,7 @@ def __node_main(current_value, last_value, globals_, locals_):

# Ignore "copyright", "credits", "license", and "help"

if isinstance(return_value, (site._Printer, site._Helper)):
if isinstance(return_value, (__sitebuiltins._Printer, __sitebuiltins._Helper)):

return_value = return_value()

Expand All @@ -444,7 +452,7 @@ def __node_main(current_value, last_value, globals_, locals_):

except TypeError as e:

if e.args[0].find('takes no arguments') != -1:
if any(x in e.args[0] for x in ('takes no arguments', 'takes 0 positional arguments')):

return_value = return_value()

Expand All @@ -464,7 +472,7 @@ def __node_main(current_value, last_value, globals_, locals_):

try:

exec current_value in globals_, locals_
six.exec_(current_value, globals_, locals_)

# Autoloader Try & Catch

Expand All @@ -474,7 +482,7 @@ def __node_main(current_value, last_value, globals_, locals_):

__import_module_from_exception(e, globals_)

exec current_value in globals_, locals_
six.exec_(current_value, globals_, locals_)

except Exception as e1:

Expand Down Expand Up @@ -686,9 +694,9 @@ def __extend_builtins(globals_):

# Fix "copyright", "credits", and "license"

setattr(globals_['__builtins__'], 'copyright', site._Printer("copyright", "Copyright (c) 2012-2013 by Itzik Kotler and others.\nAll Rights Reserved."))
setattr(globals_['__builtins__'], 'credits', site._Printer("credits", "See www.pythonect.org for more information."))
setattr(globals_['__builtins__'], 'license', site._Printer("license", "See https://github.com/ikotler/pythonect/blob/master/LICENSE", ["LICENSE"], [os.path.abspath(__file__ + "/../../../")]))
setattr(globals_['__builtins__'], 'copyright', __sitebuiltins._Printer("copyright", "Copyright (c) 2012-2013 by Itzik Kotler and others.\nAll Rights Reserved."))
setattr(globals_['__builtins__'], 'credits', __sitebuiltins._Printer("credits", "See www.pythonect.org for more information."))
setattr(globals_['__builtins__'], 'license', __sitebuiltins._Printer("license", "See https://github.com/ikotler/pythonect/blob/master/LICENSE", ["LICENSE"], [os.path.abspath(__file__ + "/../../../")]))

# Map eval() to Pythonect's eval, and __eval__ to Python's eval

Expand All @@ -697,7 +705,7 @@ def __extend_builtins(globals_):

# Default `iterate_literal_arrays`

if not '__ITERATE_LITERAL_ARRAYS__' in globals_:
if '__ITERATE_LITERAL_ARRAYS__' not in globals_:

globals_['__ITERATE_LITERAL_ARRAYS__'] = True

Expand Down Expand Up @@ -915,7 +923,7 @@ def eval(source, globals_={}, locals_={}):

if reduces:

for return_item_idx in xrange(0, len(return_value)):
for return_item_idx in six.moves.range(0, len(return_value)):

if isinstance(return_value[return_item_idx], _PythonectLazyRunner):

Expand Down
14 changes: 7 additions & 7 deletions pythonect/internal/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"""This file content extends the Python's __builtins__"""

import __builtin__
from six.moves import builtins


# Functions
Expand All @@ -41,7 +41,7 @@ def print_(object_):

# START OF CRITICAL SECTION

__builtin__.__GIL__.acquire()
builtins.__GIL__.acquire()

try:

Expand All @@ -61,7 +61,7 @@ def print_(object_):

sys.stdout.flush()

__builtin__.__GIL__.release()
builtins.__GIL__.release()

# END OF CRITICAL SECTION

Expand All @@ -82,7 +82,7 @@ def __repr__(self):

def __call__(self, globals_, locals_):

import eval
from pythonect.internal import eval

return eval.eval(self.__expression, globals_, locals_)

Expand Down Expand Up @@ -125,7 +125,7 @@ def evaluate_host(self, globals_, locals_):

self.__host = eval(self.__host, globals_, locals_)

except SyntaxError as e:
except SyntaxError:

# CONST? As it is

Expand Down Expand Up @@ -153,11 +153,11 @@ def __call__(self, *args, **kwargs):

elif self.__host.startswith('xmlrpc://'):

import xmlrpclib
from six.moves import xmlrpc_client

# xmlrpc:// = http://, xmlrpcs:// = https://

remote_srv = xmlrpclib.ServerProxy(self.__host.replace('xmlrpc', 'http', 1))
remote_srv = xmlrpc_client.ServerProxy(self.__host.replace('xmlrpc', 'http', 1))

self.__remote_fcn = getattr(remote_srv, self.__name)

Expand Down
17 changes: 9 additions & 8 deletions pythonect/internal/parsers/dia.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import networkx
import xml.sax
import gzip
import StringIO

import six
from six import BytesIO

# Local imports

Expand Down Expand Up @@ -134,15 +133,17 @@ def parse(self, source):

# UTF-8?

try:
if isinstance(source, six.text_type):

try:

source = source.encode('utf-8')
source = source.encode('utf-8')

except UnicodeDecodeError:
except UnicodeDecodeError:

pass
pass

source = gzip.GzipFile(fileobj=StringIO.StringIO(source), mode='rb').read()
source = gzip.GzipFile(fileobj=BytesIO(source), mode='rb').read()

except IOError:

Expand Down
7 changes: 4 additions & 3 deletions pythonect/internal/parsers/p2y.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

import networkx
import tokenize
import StringIO
from six import StringIO
from six.moves import reduce
import re


Expand Down Expand Up @@ -69,7 +70,7 @@ def _make_graph(code, node_prefix='', depth=0, in_brackets=False):

graph = pythonect.internal._graph.Graph()

tokens = tokenize.generate_tokens(StringIO.StringIO(code).readline)
tokens = tokenize.generate_tokens(StringIO(code).readline)

token_pos = -1

Expand Down Expand Up @@ -155,7 +156,7 @@ def _make_graph(code, node_prefix='', depth=0, in_brackets=False):

# '->' Operator?

if tokval == '>' and previous_tokval == '-':
if tokval == "->" or tokval == '>' and previous_tokval == '-':

meaningful_graph = True

Expand Down
2 changes: 1 addition & 1 deletion pythonect/internal/parsers/test/test_dia.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_gzipped_odd_expr_atom_op_expr(self):

g.add_edge('2', '3')

self.assertEqual(len(pythonect.internal.parsers.dia.PythonectDiaParser().parse(open(TEST_DIR + os.sep + 'dia_examples' + os.sep + 'odd_expr_atom_op_expr_gzipped.dia').read()).edges()) == len(g.edges()), True)
self.assertEqual(len(pythonect.internal.parsers.dia.PythonectDiaParser().parse(open(TEST_DIR + os.sep + 'dia_examples' + os.sep + 'odd_expr_atom_op_expr_gzipped.dia', 'rb').read()).edges()) == len(g.edges()), True)

def test_program_expr_list(self):

Expand Down
Loading