Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 build problem #8

Closed
LocutusOfBorg opened this issue Feb 19, 2015 · 5 comments
Closed

python3 build problem #8

LocutusOfBorg opened this issue Feb 19, 2015 · 5 comments

Comments

@LocutusOfBorg
Copy link

Hi, in my effort to make the package going into debian I did some tweaks to make it work on python-3.4

this is the patch

diff --git a/phply/phpparse.py b/phply/phpparse.py
index cde4a62..94da842 100644
--- a/phply/phpparse.py
+++ b/phply/phpparse.py
@@ -6,8 +6,8 @@

 import os
 import sys
-import phplex
-import phpast as ast
+from phply import phplex
+from phply import phpast as ast
 import ply.yacc as yacc

 # Get the token map
@@ -1336,9 +1336,9 @@ if __name__ == '__main__':
        try:
            lexer.lineno = 1
            result = parser.parse(s, lexer=lexer)
-       except SyntaxError, e:
+       except SyntaxError as e:
            if e.lineno is not None:
-               print e, 'near', repr(e.text)
+               print (e, 'near', repr(e.text))
                s = ''
            continue
        if result:
diff --git a/tests/test_lexer.py b/tests/test_lexer.py
index 5ad3781..05bacd1 100644
--- a/tests/test_lexer.py
+++ b/tests/test_lexer.py
@@ -14,13 +14,13 @@ def eq_tokens(input, expected, ignore=('WHITESPACE', 'OPEN_TAG', 'CLOSE_TAG')):
         if tok.type in ignore: continue
         output.append((tok.type, tok.value))

-    print 'Lexer output:'
+    print ('Lexer output:')
     pprint.pprint(output)
     print

-    print 'Token by token:'
+    print ('Token by token:')
     for out, exp in zip(output, expected):
-        print '\tgot:', out, '\texpected:', exp
+        print ('\tgot:', out, '\texpected:', exp)
         nose.tools.eq_(out, exp)

     assert len(output) == len(expected), \
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 4d8a537..67bb624 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -11,13 +11,13 @@ def eq_ast(input, expected, filename=None):
     output = parser.parse(input, lexer=lexer)
     resolve_magic_constants(output)

-    print 'Parser output:'
+    print ('Parser output:')
     pprint.pprint(output)
     print

-    print 'Node by node:'
+    print ('Node by node:')
     for out, exp in zip(output, expected):
-        print '\tgot:', out, '\texpected:', exp
+        print ('\tgot:', out, '\texpected:', exp)
         nose.tools.eq_(out, exp)

     assert len(output) == len(expected), \

note: I'm not a python developer.

However I'm stuck with a problem I don't know how to figure out

#python3.4 setup.py test 
running test
running egg_info
writing phply.egg-info/PKG-INFO
writing dependency_links to phply.egg-info/dependency_links.txt
writing namespace_packages to phply.egg-info/namespace_packages.txt
writing requirements to phply.egg-info/requires.txt
writing top-level names to phply.egg-info/top_level.txt
reading manifest file 'phply.egg-info/SOURCES.txt'
writing manifest file 'phply.egg-info/SOURCES.txt'
running build_ext
ERROR: tokens must be a list or tuple
tests.test_lexer.test_whitespace ... ok
tests.test_lexer.test_open_close_tags ... ok
tests.test_lexer.test_numbers ... ok
tests.test_lexer.test_strings ... ok
tests.test_lexer.test_string_backslash_escapes ... ok
tests.test_lexer.test_string_offset_lookups ... ok
tests.test_lexer.test_string_curly_dollar_expressions ... ok
tests.test_lexer.test_heredoc ... ok
tests.test_lexer.test_heredoc_backslash_newline ... ok
tests.test_lexer.test_commented_close_tag ... ok
tests.test_lexer.test_punctuation ... ok
Failure: YaccError (Unable to build parser) ... ERROR

======================================================================
ERROR: Failure: YaccError (Unable to build parser)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3/dist-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python3/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python3/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 2, in <module>
    from phply.phpparse import parser
  File "/home/locutus/branches/ongoing/phply-0.9.1/phply/phpparse.py", line 1316, in <module>
    parser = yacc.yacc(debug=False)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 3066, in yacc
    raise YaccError("Unable to build parser")
ply.yacc.YaccError: Unable to build parser

----------------------------------------------------------------------
Ran 12 tests in 0.044s

FAILED (errors=1)
@drnlm
Copy link

drnlm commented Feb 19, 2015

The problem you're seeing is because of the:

tokens = filter(lambda token: token not in unparsed, tokens)

statememnt in phplexpy. In python3, this returns an iterator object rather than the tuple/list returned in python 2.

A simple fix is to change

tokens = phplex.tokens

in phpparse.py to

tokens = tuple(phplex.tokens)

@LocutusOfBorg
Copy link
Author

ok thanks! changing that makes the build fail just after

tests.test_parser.test_echo ... ERROR
tests.test_parser.test_open_tag_with_echo ... ERROR
tests.test_parser.test_exit ... ok
tests.test_parser.test_isset ... ok
tests.test_parser.test_namespace_names ... ok
tests.test_parser.test_unary_ops ... ok
tests.test_parser.test_assignment_ops ... ok
tests.test_parser.test_object_properties ... ok
tests.test_parser.test_string_unescape ... ERROR
tests.test_parser.test_string_offset_lookups ... ERROR
tests.test_parser.test_string_curly_dollar_expressions ... ERROR
tests.test_parser.test_heredoc ... ERROR
tests.test_parser.test_function_calls ... ok
tests.test_parser.test_method_calls ... ok
tests.test_parser.test_if ... ok
tests.test_parser.test_foreach ... ERROR
tests.test_parser.test_global_variables ... ok
tests.test_parser.test_variable_variables ... ok
tests.test_parser.test_classes ... ok
tests.test_parser.test_new ... ok
tests.test_parser.test_exceptions ... ERROR
tests.test_parser.test_declare ... ok
tests.test_parser.test_instanceof ... ok
tests.test_parser.test_static_members ... ok
tests.test_parser.test_casts ... ok
tests.test_parser.test_namespaces ... ok
tests.test_parser.test_use_declarations ... ok
tests.test_parser.test_constant_declarations ... ERROR
tests.test_parser.test_closures ... ERROR
tests.test_parser.test_magic_constants ... ERROR
tests.test_parser.test_type_hinting ... ok

======================================================================
ERROR: tests.test_parser.test_echo
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 34, in test_echo
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_open_tag_with_echo
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 43, in test_open_tag_with_echo
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_string_unescape
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 145, in test_string_unescape
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_string_offset_lookups
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 178, in test_string_offset_lookups
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1262, in p_encaps_list_string
    p[0] = ast.BinaryOp('.', p[1], p[2].decode('string_escape'),
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_string_curly_dollar_expressions
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 211, in test_string_curly_dollar_expressions
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_heredoc
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 238, in test_heredoc
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_foreach
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 359, in test_foreach
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1262, in p_encaps_list_string
    p[0] = ast.BinaryOp('.', p[1], p[2].decode('string_escape'),
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_exceptions
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 487, in test_exceptions
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_constant_declarations
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 630, in test_constant_declarations
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1192, in p_static_scalar
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_closures
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 659, in test_closures
    eq_ast(input, expected)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

======================================================================
ERROR: tests.test_parser.test_magic_constants
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 699, in test_magic_constants
    eq_ast(input, expected, filename='/my/dir/file.php')
  File "/home/locutus/branches/ongoing/phply-0.9.1/tests/test_parser.py", line 11, in eq_ast
    output = parser.parse(input, lexer=lexer)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 269, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
    p.callable(pslice)
  File "/home/locutus/branches/ongoing/phply-0.9.1/.pybuild/pythonX.Y_3.4/build/phply/phpparse.py", line 1260, in p_encaps_list_string
    p[0] = p[2].decode('string_escape')
AttributeError: 'str' object has no attribute 'decode'

----------------------------------------------------------------------
Ran 43 tests in 1.983s

FAILED (errors=11)

they seems all related to the same error

@LocutusOfBorg
Copy link
Author

I fixed the other problems in this patch (I guess)

Description: This patch makes the package python3 ready
Author: Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
        Neil Muller
Forwarded: https://github.com/ramen/phply/issues/8
Last-Update: 2015-02-19

Index: python-phply/phply/phpparse.py
===================================================================
--- python-phply.orig/phply/phpparse.py 2015-02-21 16:44:56.306062304 +0100
+++ python-phply/phply/phpparse.py  2015-02-21 16:44:56.302062296 +0100
@@ -6,12 +6,12 @@

 import os
 import sys
-import phplex
-import phpast as ast
+from phply import phplex
+from phply import phpast as ast
 import ply.yacc as yacc

 # Get the token map
-tokens = phplex.tokens
+tokens = tuple(phplex.tokens)

 precedence = (
     ('left', 'INCLUDE', 'INCLUDE_ONCE', 'EVAL', 'REQUIRE', 'REQUIRE_ONCE'),
@@ -1189,7 +1189,10 @@
     elif len(p) == 3:
         p[0] = ''
     else:
-        p[0] = p[2].decode('string_escape')
+        if (sys.version_info > (3, 0)):
+           p[0] = bytes(p[2], "utf-8").decode('unicode_escape')
+        else:
+           p[0] = p[2].decode('string_escape')

 def p_static_scalar_namespace_name(p):
     '''static_scalar : namespace_name
@@ -1257,10 +1260,17 @@
 def p_encaps_list_string(p):
     'encaps_list : encaps_list ENCAPSED_AND_WHITESPACE'
     if p[1] == '':
-        p[0] = p[2].decode('string_escape')
+        if (sys.version_info > (3, 0)):
+           p[0] = bytes(p[2], "utf-8").decode('unicode_escape')
+        else:
+           p[0] = p[2].decode('string_escape')
     else:
-        p[0] = ast.BinaryOp('.', p[1], p[2].decode('string_escape'),
-                            lineno=p.lineno(2))
+        if (sys.version_info > (3, 0)):
+           p[0] = ast.BinaryOp('.', p[1], bytes(p[2], "utf-8").decode('unicode_escape'),
+                               lineno=p.lineno(2))
+        else:
+           p[0] = ast.BinaryOp('.', p[1], p[2].decode('string_escape'),
+                               lineno=p.lineno(2))

 def p_encaps_var(p):
     'encaps_var : VARIABLE'
@@ -1336,9 +1346,9 @@
        try:
            lexer.lineno = 1
            result = parser.parse(s, lexer=lexer)
-       except SyntaxError, e:
+       except SyntaxError as e:
            if e.lineno is not None:
-               print e, 'near', repr(e.text)
+               print (e, 'near', repr(e.text))
                s = ''
            continue
        if result:
Index: python-phply/tests/test_lexer.py
===================================================================
--- python-phply.orig/tests/test_lexer.py   2015-02-21 16:44:56.306062304 +0100
+++ python-phply/tests/test_lexer.py    2015-02-21 16:44:56.302062296 +0100
@@ -14,13 +14,13 @@
         if tok.type in ignore: continue
         output.append((tok.type, tok.value))

-    print 'Lexer output:'
+    print ('Lexer output:')
     pprint.pprint(output)
     print

-    print 'Token by token:'
+    print ('Token by token:')
     for out, exp in zip(output, expected):
-        print '\tgot:', out, '\texpected:', exp
+        print ('\tgot:', out, '\texpected:', exp)
         nose.tools.eq_(out, exp)

     assert len(output) == len(expected), \
Index: python-phply/tests/test_parser.py
===================================================================
--- python-phply.orig/tests/test_parser.py  2015-02-21 16:44:56.306062304 +0100
+++ python-phply/tests/test_parser.py   2015-02-21 16:44:56.302062296 +0100
@@ -11,13 +11,13 @@
     output = parser.parse(input, lexer=lexer)
     resolve_magic_constants(output)

-    print 'Parser output:'
+    print ('Parser output:')
     pprint.pprint(output)
     print

-    print 'Node by node:'
+    print ('Node by node:')
     for out, exp in zip(output, expected):
-        print '\tgot:', out, '\texpected:', exp
+        print ('\tgot:', out, '\texpected:', exp)
         nose.tools.eq_(out, exp)

     assert len(output) == len(expected), \
Index: python-phply/tools/phpshell.py
===================================================================
--- python-phply.orig/tools/phpshell.py 2015-02-21 16:44:56.306062304 +0100
+++ python-phply/tools/phpshell.py  2015-02-21 16:44:56.302062296 +0100
@@ -21,11 +21,11 @@
     sys.stdout.write(obj)

 def XXX(obj):
-    print 'Not implemented:\n ', obj
+    print ('Not implemented:\n ', obj)

 def ast_dump(code):
-    print 'AST dump:'
-    print ' ', ast.dump(code, include_attributes=True)
+    print ('AST dump:')
+    print (' ', ast.dump(code, include_attributes=True))

 def php_eval(nodes):
     body = []
@@ -63,7 +63,7 @@
            lexer.lineno = 1
            result = parser.parse(s, lexer=lexer)
            php_eval(result)
-       except SyntaxError, e:
+       except SyntaxError as e:
            # Parsing failed. See if it can be parsed as an expression.
            try:
                lexer.lineno = 1
@@ -81,7 +81,7 @@
                    if e.lineno is None:
                        continue
                    else:
-                       print e, 'near', repr(e.text)
+                       print (e, 'near', repr(e.text))
                        s = ''
    except:
        traceback.print_exc()
Index: python-phply/tools/unparse.py
===================================================================
--- python-phply.orig/tools/unparse.py  2015-02-21 16:44:56.306062304 +0100
+++ python-phply/tools/unparse.py   2015-02-21 16:44:56.302062296 +0100
@@ -28,7 +28,7 @@
         self.f = file
         self._indent = 0
         self.dispatch(tree)
-        print >>self.f,""
+        self.f.write("")
         self.f.flush()

     def fill(self, text = ""):
@@ -492,17 +492,17 @@
     try:
         names = [n for n in os.listdir(a) if n.endswith('.py')]
     except OSError:
-        print >> sys.stderr, "Directory not readable: %s" % a
+        print ("Directory not readable: %s" % a, file=sys.stderr)
     else:
         for n in names:
             fullname = os.path.join(a, n)
             if os.path.isfile(fullname):
                 output = cStringIO.StringIO()
-                print 'Testing %s' % fullname
+                print ('Testing %s' % fullname)
                 try:
                     roundtrip(fullname, output)
-                except Exception, e:
-                    print '  Failed to compile, exception is %s' % repr(e)
+                except Exception as e:
+                    print ('  Failed to compile, exception is %s' % repr(e))
             elif os.path.isdir(fullname):
                 testdir(fullname)

LocutusOfBorg added a commit to LocutusOfBorg/phply that referenced this issue Jun 16, 2015
LocutusOfBorg added a commit to LocutusOfBorg/phply that referenced this issue Aug 26, 2015
@viraptor
Copy link
Owner

viraptor commented Nov 7, 2016

Thank you for raising this @LocutusOfBorg !

Another series of patches has been merged for py3 support and it should be pretty much equivalent. If you see other py3 issues, please raise them :)

@viraptor viraptor closed this as completed Nov 7, 2016
@LocutusOfBorg
Copy link
Author

Hi, just release a new version and I'll notify/report them :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants