php
Advanced tools
+114
| from unittest import TestCase | ||
| from . import Php | ||
| class TestPhp(TestCase): | ||
| maxDiff = None | ||
| def test_http_build_query(self): | ||
| self.assertEqual( | ||
| Php.http_build_query({"alpha": "bravo"}), "alpha=bravo&") | ||
| test = Php.http_build_query({"charlie": ["delta", "echo", "foxtrot"]}) | ||
| self.assertTrue("charlie[0]=delta" in test) | ||
| self.assertTrue("charlie[1]=echo" in test) | ||
| self.assertTrue("charlie[2]=foxtrot" in test) | ||
| test = Php.http_build_query({ | ||
| "golf": [ | ||
| "hotel", | ||
| {"india": "juliet", "kilo": ["lima", "mike"]}, | ||
| "november", "oscar" | ||
| ] | ||
| }) | ||
| self.assertTrue("golf[0]=hotel" in test) | ||
| self.assertTrue("golf[1][india]=juliet" in test) | ||
| self.assertTrue("golf[1][kilo][0]=lima" in test) | ||
| self.assertTrue("golf[1][kilo][1]=mike" in test) | ||
| self.assertTrue("golf[2]=november" in test) | ||
| self.assertTrue("golf[3]=oscar" in test) | ||
| def test_parse_ini_file(self): | ||
| ini_file = "/tmp/python-php-test.ini" | ||
| ini = """ | ||
| [section alpha] | ||
| bravo = 7 | ||
| charlie = "delta" | ||
| echo[] = 1 | ||
| echo[] = 2 | ||
| echo[] = 3 | ||
| [section foxtrot] | ||
| golf[hotel] = 1 | ||
| golf[juliet] = 2 | ||
| golf[kilo] = "3" | ||
| """.replace(" ", "") | ||
| with open(ini_file, "w") as f: | ||
| f.write(ini) | ||
| self.assertEqual(Php.parse_ini_file(ini_file), { | ||
| 'section foxtrot': { | ||
| 'golf': {'kilo': 3, 'hotel': 1, 'juliet': 2} | ||
| }, | ||
| 'section alpha': { | ||
| 'bravo': 7, | ||
| 'echo': [1, 2, 3], | ||
| 'charlie': 'delta' | ||
| } | ||
| }) | ||
| self.assertEqual(Php.parse_ini_file(ini_file, strip_quotes=False), { | ||
| 'section foxtrot': { | ||
| 'golf': {'kilo': '"3"', 'hotel': 1, 'juliet': 2} | ||
| }, | ||
| 'section alpha': { | ||
| 'bravo': 7, | ||
| 'echo': [1, 2, 3], | ||
| 'charlie': '"delta"' | ||
| } | ||
| }) | ||
| def test__parse_ini_loop(self): | ||
| self.assertEqual( | ||
| Php._parse_ini_loop("a = b", None, {}, True), ({"a": "b"}, None)) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop("a=b", None, {}, True), ({"a": "b"}, None)) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop("a =b", None, {}, True), ({"a": "b"}, None)) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop("a= b", None, {}, True), ({"a": "b"}, None)) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop('a = "b"', None, {}, True), | ||
| ({"a": "b"}, None) | ||
| ) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop('a = "b"', None, {}, False), | ||
| ({"a": '"b"'}, None) | ||
| ) | ||
| self.assertEqual( | ||
| Php._parse_ini_loop("a = 1", None, {}, True), ({"a": 1}, None)) | ||
| def test_parse_ini_file_special_case(self): | ||
| ini_file = "/tmp/python-php-test.ini" | ||
| ini = """ | ||
| alpha = 7 | ||
| bravo = "charlie" | ||
| delta[] = 1 | ||
| delta[] = 2 | ||
| """.replace(" ", "") | ||
| with open(ini_file, "w") as f: | ||
| f.write(ini) | ||
| self.assertEqual( | ||
| Php.parse_ini_file(ini_file), | ||
| {"alpha": 7, "bravo": "charlie", "delta": [1, 2]} | ||
| ) | ||
| self.assertEqual( | ||
| Php.parse_ini_file(ini_file, strip_quotes=False), | ||
| {"alpha": 7, "bravo": '"charlie"', "delta": [1, 2]} | ||
| ) |
| Metadata-Version: 1.1 | ||
| Name: php | ||
| Version: 1.1.7 | ||
| Version: 1.2.0 | ||
| Summary: Handle some of the strange standards in PHP projects | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/danielquinn/python-php |
| README.rst | ||
| setup.py | ||
| php/__init__.py | ||
| php/test_php.py | ||
| php.egg-info/PKG-INFO | ||
@@ -5,0 +6,0 @@ php.egg-info/SOURCES.txt |
+21
-15
@@ -8,4 +8,5 @@ import re | ||
| __version__ = "1.1.7" | ||
| __version__ = "1.2.0" | ||
| class Php(object): | ||
@@ -55,6 +56,4 @@ | ||
| output = output + cls.http_build_query( | ||
| new_params, | ||
| convention % key + "[%s]" | ||
| ) | ||
| output += cls.http_build_query( | ||
| new_params, convention % key + "[%s]") | ||
@@ -70,8 +69,8 @@ else: | ||
| @classmethod | ||
| def parse_ini_file(cls, filename, strip_quotes=False): | ||
| def parse_ini_file(cls, filename, strip_quotes=True): | ||
| """ | ||
| A hacked-together attempt at making an .ini file parser that's compatible | ||
| with the "standards" that PHP follows in its parse_ini_file() function. | ||
| Among the handy features included are: | ||
| A hacked-together attempt at making an .ini file parser that's | ||
| compatible with the "standards" that PHP follows in its | ||
| parse_ini_file() function. Among the handy features included are: | ||
@@ -107,3 +106,2 @@ * List notation (varname[] = value) | ||
| @classmethod | ||
@@ -129,17 +127,25 @@ def _parse_ini_loop(cls, line, header_key, ini, strip_quotes): | ||
| target = ini | ||
| if header_key: | ||
| target = ini[header_key] | ||
| value = keyval.group(2).rstrip("\n") | ||
| if value.isdigit(): | ||
| value = int(value) | ||
| elif value.isdecimal(): | ||
| value = float(value) | ||
| if indexed_array: | ||
| try: | ||
| ini[header_key][indexed_array.group(1)].append(value) | ||
| target[indexed_array.group(1)].append(value) | ||
| except KeyError: | ||
| ini[header_key][indexed_array.group(1)] = [value] | ||
| target[indexed_array.group(1)] = [value] | ||
| elif associative_array: | ||
| try: | ||
| ini[header_key][associative_array.group(1)][associative_array.group(2)] = value | ||
| target[associative_array.group(1)][associative_array.group(2)] = value | ||
| except KeyError: | ||
| ini[header_key][associative_array.group(1)] = {associative_array.group(2): value} | ||
| target[associative_array.group(1)] = {associative_array.group(2): value} | ||
| else: | ||
| ini[header_key][keyval.group(1)] = value | ||
| target[keyval.group(1)] = value | ||
| return ini, header_key | ||
+1
-1
| Metadata-Version: 1.1 | ||
| Name: php | ||
| Version: 1.1.7 | ||
| Version: 1.2.0 | ||
| Summary: Handle some of the strange standards in PHP projects | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/danielquinn/python-php |
+1
-1
| [egg_info] | ||
| tag_svn_revision = 0 | ||
| tag_build = | ||
| tag_date = 0 | ||
| tag_svn_revision = 0 | ||
+2
-4
@@ -7,4 +7,4 @@ import os | ||
| version_file = os.path.join( | ||
| os.path.dirname(__file__), | ||
| 'php', | ||
| os.path.dirname(__file__), | ||
| 'php', | ||
| '__init__.py' | ||
@@ -36,4 +36,2 @@ ) | ||
| maintainer_email="code@danielquinn.org", | ||
| tests_require=["nose"], | ||
| test_suite="nose.collector", | ||
| packages=["php"], | ||
@@ -40,0 +38,0 @@ classifiers=[ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
16300
28.75%10
11.11%248
67.57%