From 511f1b69a8e768392963abfa55e4700df87b11c5 Mon Sep 17 00:00:00 2001 From: Josh West Date: Fri, 1 Apr 2016 15:34:48 -0400 Subject: [PATCH 1/8] Fix for `php.echo` and `php.print` --- php/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/__init__.py b/php/__init__.py index 6bb8aa7..9aa0d99 100644 --- a/php/__init__.py +++ b/php/__init__.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import sys @@ -29,6 +31,8 @@ def call_php_function(*args): if err: raise PHPException(err) return json.loads(out) + if name in ['echo', 'print']: + return print call_php_function.name = name return call_php_function From b230cab26196e24bc644de49c0479370391f0f9e Mon Sep 17 00:00:00 2001 From: Josh West Date: Fri, 1 Apr 2016 18:38:58 -0400 Subject: [PATCH 2/8] Added support for PHP functions that output rather than returns --- php/__init__.py | 5 +++++ tests.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/php/__init__.py b/php/__init__.py index 9aa0d99..7379852 100644 --- a/php/__init__.py +++ b/php/__init__.py @@ -18,8 +18,13 @@ def call_php_function(*args): php_code = ( " test\n)\n') + if __name__ == '__main__': unittest.main() From 052988016a1e4d082afe0738184fdd3c353762e3 Mon Sep 17 00:00:00 2001 From: leovp Date: Sat, 2 Apr 2016 12:30:55 +0300 Subject: [PATCH 3/8] Fix test_strtotime failing on non-UTC systems --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index fa2f4b2..a7653df 100644 --- a/tests.py +++ b/tests.py @@ -8,7 +8,7 @@ class PythonPHPTestCase(unittest.TestCase): """Just because something is tested, doesn't mean it is safe""" def test_strtotime(self): - r = php.strtotime("2015-01-01") + r = php.strtotime("2015-01-01 UTC") self.assertEqual(r, 1420070400) def test_str_replace(self): From 05ecc23c5509f72c50f70364bbefbd64f2ac62c0 Mon Sep 17 00:00:00 2001 From: leovp Date: Sat, 2 Apr 2016 12:38:45 +0300 Subject: [PATCH 4/8] Support both Python 2 and Python 3 --- php/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/__init__.py b/php/__init__.py index 7379852..f37d02e 100644 --- a/php/__init__.py +++ b/php/__init__.py @@ -14,7 +14,7 @@ def __getattr__(self, name): import tempfile def call_php_function(*args): - with tempfile.NamedTemporaryFile() as f: + with tempfile.NamedTemporaryFile(mode='w+t') as f: php_code = ( " Date: Sat, 2 Apr 2016 12:55:28 +0300 Subject: [PATCH 5/8] Now compatible with python 2.6+, 3.3+ --- tox.ini | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..501d031 --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[tox] +envlist = py26, py27, py33, py34, py35 + +[testenv] +commands = python tests.py From 2f36b58f7941fa226b35ec80fead11367dc279f8 Mon Sep 17 00:00:00 2001 From: leovp Date: Sat, 2 Apr 2016 13:01:22 +0300 Subject: [PATCH 6/8] Readme now mentions testing with tox and compatibility --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a89bcb4..b8863c9 100644 --- a/readme.md +++ b/readme.md @@ -19,9 +19,10 @@ Python PHP supports the following types: int, string, list, and dictionaries ## Testing Of course Python-PHP has unit tests! How else would we know that it is safe to use? Run tests with `$ python tests.py` +To test with python 2.6+ and 3.3+ type `$ tox` ## Compatibility -Python-PHP is currently only compatible with Python 2.7 +Python-PHP is compatible with all relevant Python versions: 2.6, 2.7, 3.3, 3.4 and 3.5 ## Is this really a good idea What could possibly go wrong? From 7530ac6b24686b4ca6ee25055fa7c34fb88e7b8b Mon Sep 17 00:00:00 2001 From: Joshua West Date: Sat, 2 Apr 2016 14:18:34 -0400 Subject: [PATCH 7/8] Add gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a47c27d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.egg-info/ +*.pyc +.tox/ +__pycache__ From 77add23b3024a9a8f45ae0bc7b0944a0418a7f1c Mon Sep 17 00:00:00 2001 From: Joshua West Date: Sat, 2 Apr 2016 14:24:12 -0400 Subject: [PATCH 8/8] Cleaned up README, April Fools Day notice --- readme.md => README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename readme.md => README.md (63%) diff --git a/readme.md b/README.md similarity index 63% rename from readme.md rename to README.md index b8863c9..2cd1ff9 100644 --- a/readme.md +++ b/README.md @@ -1,5 +1,5 @@ # Python PHP -Have you ever wished that the Python standard library had the power and flexibilty of PHP? Now it is as simple as `import php` +Have you ever wished that the Python standard library had the power and flexibility of PHP? Now it is as simple as `import php` ## Installation Python PHP can be installed using pip @@ -18,11 +18,12 @@ php.str_replace('Python', 'PHP', 'Hello World of Python') Python PHP supports the following types: int, string, list, and dictionaries ## Testing -Of course Python-PHP has unit tests! How else would we know that it is safe to use? Run tests with `$ python tests.py` +Of course Python-PHP has unit tests! How else would we know that it is safe to use? +Run tests with `$ python tests.py` To test with python 2.6+ and 3.3+ type `$ tox` ## Compatibility Python-PHP is compatible with all relevant Python versions: 2.6, 2.7, 3.3, 3.4 and 3.5 -## Is this really a good idea -What could possibly go wrong? +## Is this really a good idea? +What could possibly go wrong? OK, probably a lot of things. First release on April Fools Day 2016, this project was designed as a tongue-in-cheek coding exercise intended more for mirth than productivity. Using this in production is probably a very bad idea.