php-var-dump 0.1__tar.gz → 0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 1.0
1
+ Metadata-Version: 1.1
2
2
  Name: php_var_dump
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: a port of the var_dump function of php to python.
5
5
  Home-page: http://github.com/jvanasco/php_var_dump
6
6
  Author: Jonathan Vanasco
@@ -52,7 +52,7 @@ Description: php_var_dump
52
52
  You'd probable then want to save it...
53
53
 
54
54
  data_string= "<?php\n\n%s\n\n?>" % as_php
55
- open('data.php','w').write(data_string.encode( "utf-8" ))
55
+ open('data.php', 'w').write(data_string.encode( "utf-8" ))
56
56
 
57
57
  Then just include that file in your php programs.
58
58
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 1.0
1
+ Metadata-Version: 1.1
2
2
  Name: php-var-dump
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: a port of the var_dump function of php to python.
5
5
  Home-page: http://github.com/jvanasco/php_var_dump
6
6
  Author: Jonathan Vanasco
@@ -52,7 +52,7 @@ Description: php_var_dump
52
52
  You'd probable then want to save it...
53
53
 
54
54
  data_string= "<?php\n\n%s\n\n?>" % as_php
55
- open('data.php','w').write(data_string.encode( "utf-8" ))
55
+ open('data.php', 'w').write(data_string.encode( "utf-8" ))
56
56
 
57
57
  Then just include that file in your php programs.
58
58
 
@@ -1,4 +1,3 @@
1
- README
2
1
  php_var_dump.py
3
2
  setup.cfg
4
3
  setup.py
@@ -3,17 +3,17 @@ r"""
3
3
  ~~~~~~~~~~~~
4
4
 
5
5
  A port of the ``var_dump`` function of php to python.
6
-
6
+
7
7
  Why on earth would you want this?!?!?
8
8
  =====================================
9
-
9
+
10
10
  Imagine that you have to deploy something in php. You don't have a choice.
11
11
  You HAVE to.
12
-
12
+
13
13
  php_var_dump lets you do all your data processing and management in python.
14
14
  You can then convert your native python data structures into php code,
15
15
  which can then be saved as include fles for php.
16
-
16
+
17
17
  Other python modules that can accomplish the general idea:
18
18
  phpserialize
19
19
  implements the PHP serialize/unserialize functions in python
@@ -21,17 +21,17 @@ r"""
21
21
  allows you to unserialize a php data structure to Python
22
22
  simplejson
23
23
  there are json parsers in php, which can read code you save
24
-
24
+
25
25
  The main benefit of using the var_dump method, is that there is no overhead
26
- in loading/unloading/parsing/etc.
27
-
28
- This method allows you to build a php include file that simply runs fast,
26
+ in loading/unloading/parsing/etc.
27
+
28
+ This method allows you to build a php include file that simply runs fast,
29
29
  and that can use multiple includes within the filesystem as a "database"
30
- like system. This way you don't have to set up any databases, libraries,
30
+ like system. This way you don't have to set up any databases, libraries,
31
31
  or whatever - you can just deploy PHP code without coding much in PHP.
32
-
33
-
34
-
32
+
33
+
34
+
35
35
 
36
36
  Usage
37
37
  =====
@@ -41,69 +41,70 @@ r"""
41
41
  >>> as_php = php_var_dump( 'var', data )
42
42
  >>> print as_php
43
43
  $var = 'Hello World';
44
-
44
+
45
45
  You'd probable then want to save it...
46
-
46
+
47
47
  data_string= "<?php\n\n%s\n\n?>" % as_php
48
- open('data.php','w').write(data_string.encode( "utf-8" ))
49
-
48
+ open('data.php', 'w').write(data_string.encode( "utf-8" ))
49
+
50
50
  Then just include that file in your php programs.
51
-
51
+
52
52
  There's also a php_as_block function, which does the trivial encapsulation as above.
53
-
53
+
54
54
 
55
55
  :copyright: 2012 by Jonathan Vanasco
56
56
  license: BSD
57
57
  """
58
58
 
59
+
59
60
  import types
60
61
 
61
- def _php_var_dump(data,depth=0):
62
- """ utility function; recursively called. depth is used to control the amount of padding.
62
+
63
+ def _php_var_dump(data, depth=0):
64
+ """ utility function; recursively called. depth is used to control the amount of padding.
63
65
  This has a limited amount of support for data structures. functions, lambas, etc are not supported
64
66
  """
65
- padding= " "*depth
66
- keypadding= " "*(depth+1)
67
- depth+= 1
68
- if ( type(data) == types.DictType ) or ( type(data) == types.DictionaryType ):
67
+ padding = " " * depth
68
+ keypadding = " " * (depth + 1)
69
+ depth += 1
70
+ if isinstance(data, (types.DictType, types.DictionaryType)):
69
71
  items = []
70
- for i in data :
71
- item = keypadding + "'%s' => %s" % (i,_php_var_dump(data[i],depth=depth))
72
+ for i in data:
73
+ item = keypadding + "'%s' => %s" % (i, _php_var_dump(data[i], depth=depth))
72
74
  items.append(item)
73
75
  items = ',\n'.join(items)
74
- return '%sArray(\n%s\n%s)' % ( padding, items, padding)
75
- elif ( type(data) == types.ListType ) or ( type(data) == types.TupleType ):
76
+ return '%sArray(\n%s\n%s)' % (padding, items, padding)
77
+ if isinstance(data, (types.ListType, types.TupleType)):
76
78
  items = []
77
- for i in data :
78
- items.append(_php_var_dump(i,depth=depth))
79
+ for i in data:
80
+ items.append(_php_var_dump(i, depth=depth))
79
81
  items = ',\n'.join(items)
80
- return '%sArray(\n%s\n%s)' % ( padding, items, padding)
81
- elif type(data) == types.StringType :
82
+ return '%sArray(\n%s\n%s)' % (padding, items, padding)
83
+ elif isinstance(data, types.StringType):
82
84
  return padding + "'%s'" % data
83
- elif type(data) == types.UnicodeType :
85
+ elif isinstance(data, types.UnicodeType):
84
86
  return padding + "'%s'" % data
85
- elif type(data) == types.IntType :
87
+ elif isinstance(data, types.IntType):
86
88
  return padding + "%s" % data
87
- elif type(data) == types.BooleanType :
89
+ elif isinstance(data, types.BooleanType):
88
90
  return padding + "%s" % data
89
- elif type(data) == types.NoneType :
91
+ elif isinstance(data, types.NoneType):
90
92
  return padding + "null"
91
- elif type(data) == types.LongType :
93
+ elif isinstance(data, types.LongType):
92
94
  return padding + "%s" % data
93
- elif type(data) == types.FloatType :
95
+ elif isinstance(data, types.FloatType):
94
96
  return padding + "%s" % data
95
97
  else:
96
- raise ValueError("Unsupported data type (%s) for data : '%s'" % ( type(data) , data ))
98
+ raise ValueError("Unsupported data type (%s) for data: '%s'" % (type(data), data))
97
99
 
98
100
 
99
- def php_var_dump(name,data):
101
+ def php_var_dump(name, data):
100
102
  """ php_var_dump """
101
- depth=0
102
- if type(data) == types.DictType:
103
- depth= 1
104
- return "$%s = %s;" % ( name , _php_var_dump(data,depth=depth) )
105
-
103
+ depth = 0
104
+ if isinstance(data, types.DictType):
105
+ depth = 1
106
+ return "$%s = %s;" % (name, _php_var_dump(data, depth=depth))
107
+
106
108
 
107
109
  def php_as_block(stringed_var):
108
110
  return "<?php\n\n%s\n\n?>" % stringed_var
109
-
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  from setuptools import setup
3
3
 
4
+
4
5
  def get_docs():
5
6
  result = []
6
7
  in_docs = False
@@ -17,11 +18,12 @@ def get_docs():
17
18
  f.close()
18
19
  return '\n'.join(result)
19
20
 
21
+
20
22
  setup(
21
23
  name='php_var_dump',
22
24
  author='Jonathan Vanasco',
23
25
  author_email='jonathan@findmeon.com',
24
- version='0.1',
26
+ version='0.2',
25
27
  url='http://github.com/jvanasco/php_var_dump',
26
28
  py_modules=['php_var_dump'],
27
29
  description='a port of the var_dump function of php to python.',
php_var_dump-0.1/README DELETED
@@ -1,5 +0,0 @@
1
- a port of the var_dump function of php to python.
2
-
3
- This module allows you to dump python objects into PHP code.
4
-
5
- docs are inline
File without changes