pyjavaproperties-0.7/0000775000175000017500000000000013422552550015160 5ustar anandanand00000000000000pyjavaproperties-0.7/CHANGELOG.txt0000664000175000017500000000231613422551752017215 0ustar anandanand00000000000000Changelog ========= version 0.7 ----------- - Long doc from README.rst instead of README.md. [Anand B Pillai] - Updates for release 0.7. [Anand B Pillai] - Updated README.rst. [Anand B Pillai] - Updated README.md. [Anand B Pillai] - Added changelog.txt. [Anand B Pillai] - Updated MANIFEST. [Anand B Pillai] - PROPs updated. [Anand B Pillai] - Added README.rst. [Anand B Pillai] - CHANGELOG file. [Anand B Pillai] - Setup.py for release 0.7. [Anand B Pillai] - Updated README.md showing tests, changes section and updates to author etc. [Anand B Pillai] - Updtas to README. [Anand B Pillai] - README.md. [Anand B Pillai] - README.md. [Anand B Pillai] - Adding MIT LICENSE. [Anand B Pillai] - Relicensing to MIT. [Anand B Pillai] - Basic python3 support plus python2/3 cross compatibility. [Anand B Pillai] - Basic Python3 port plus cross Python2 & 3 compatibility. [Anand B Pillai] - Absorbing TODO in README.md. [Anand B Pillai] - README => README.md. [Anand B Pillai] - Adding README.md. [Anand B Pillai] - Added ref properties. [Anand B Pillai] - Added tests for referenced properties and saving as well. [Anand B Pillai] - Minor tweaks in code. [Anand B Pillai] - Initial commit for new git repo. [Anand B Pillai] pyjavaproperties-0.7/LICENSE0000664000175000017500000000203613402166260016163 0ustar anandanand00000000000000Copyright 2018 Anand B Pillai Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.pyjavaproperties-0.7/MANIFEST.in0000664000175000017500000000016313422550720016713 0ustar anandanand00000000000000include README.md include README.rst include LICENSE include CHANGELOG.txt recursive-include testdata *.properties pyjavaproperties-0.7/PKG-INFO0000664000175000017500000001020113422552550016247 0ustar anandanand00000000000000Metadata-Version: 1.1 Name: pyjavaproperties Version: 0.7 Summary: Python replacement for java.util.Properties. Home-page: https://bitbucket.org/skeptichacker/pyjavaproperties/ Author: Anand B Pillai Author-email: anandpillai@letterboxes.org License: MIT License Description: About ----- This is a fork of "python replacement for java.util.Properties" recipe on ASPN: http://code.activestate.com/recipes/496795/ The project is maintained by Anand B Pillai anandpillai@letterboxes.org, anand@anvetsu.com . License ------- The code is re-licensed under MIT License. See ``LICENSE`` file for more details. What this is ------------ This module is designed to be a python equivalent to the ``java.util.Properties ``\ \_ class. Currently, the basic input/output methods are supported. Fundamentally, this module is designed so that users can easily parse and manipulate Java Properties files - that's it. There's a fair number of us pythonistas who work in multi-language shops, and constantly writing your own parsing mechanism is just painful. Not to mention Java guys are notoriously unwilling to use anything which is cross-language for configuration, unless it's XML, which is a form of self-punishment. :) Python support -------------- The module is cross Python2 and Python3 compatible. This module has basic support for Python3. It means the tests should pass under any version of Python3 though it has been tested only for versions >= Python 3.6.6. Due to the changes for Python3, this should work under any Python2 version >= Python 2.7. Caveats ------- The code still uses Python2 type strings inside. In other words proper unicode support is still missing. Plans ----- Here is a plan for the current version which runs under Python2 in approximate decreasing priority order. 1. Keep/maintain blank lines and comments found in the original file 2. Add unicode support 3. Provide python property access on top of direct dictionary get/set 4. Make the module compatible with the new methods in latest J2SE. Usage ----- :: from pyjavaproperties import Properties p = Properties() p.load(open('test.properties')) p.list() print p print p.items() print p['name3'] p['name3'] = 'changed = value' print p['name3'] p['new key'] = 'new value' p.store(open('test2.properties','w')) See also the Properties.list() method, which will return an iterator over the property keys Tests ----- :: $ python pyjavaproperties_test.py Changes & News -------------- version 0.7 ----------- - Setup.py for release 0.7. - Created CHANGELOG.txt - Updated README.md showing tests, changes section and updates to author etc. - Relicensed to MIT from PSF. - Rewrote N.B's patch to relicense repo under MIT. - Basic python3 support plus python2/3 cross compatibility. - Absorbing TODO in README.md. - README => README.md. - Added support for referenced properties. - Added tests for referenced properties and saving as well. - Minor tweaks in code. - Code moved to new git repo. Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules pyjavaproperties-0.7/README.md0000664000175000017500000000533513422551644016450 0ustar anandanand00000000000000## About This is a fork of "python replacement for java.util.Properties" recipe on ASPN: The project is maintained by Anand B Pillai , . ## License The code is re-licensed under MIT License. See `LICENSE` file for more details. ## What this is This module is designed to be a python equivalent to the `java.util.Properties `_ class. Currently, the basic input/output methods are supported. Fundamentally, this module is designed so that users can easily parse and manipulate Java Properties files - that's it. There's a fair number of us pythonistas who work in multi-language shops, and constantly writing your own parsing mechanism is just painful. Not to mention Java guys are notoriously unwilling to use anything which is cross-language for configuration, unless it's XML, which is a form of self-punishment. :) ## Python support The module is cross Python2 and Python3 compatible. This module has basic support for Python3. It means the tests should pass under any version of Python3 though it has been tested only for versions >= Python 3.6.6. Due to the changes for Python3, this should work under any Python2 version >= Python 2.7. ## Caveats The code still uses Python2 type strings inside. In other words proper unicode support is still missing. ## Plans Here is a plan for the current version which runs under Python2 in approximate decreasing priority order. 1. Keep/maintain blank lines and comments found in the original file 2. Add unicode support 3. Provide python property access on top of direct dictionary get/set 4. Make the module compatible with the new methods in latest J2SE. ## Usage ``` from pyjavaproperties import Properties p = Properties() p.load(open('test.properties')) p.list() print p print p.items() print p['name3'] p['name3'] = 'changed = value' print p['name3'] p['new key'] = 'new value' p.store(open('test2.properties','w')) ``` See also the Properties.list() method, which will return an iterator over the property keys ## Tests $ python pyjavaproperties_test.py ## Changes & News version 0.7 ----------- - Setup.py for release 0.7. - Created CHANGELOG.txt - Updated README.md showing tests, changes section and updates to author etc. - Relicensed to MIT from PSF. - Rewrote N.B's patch to relicense repo under MIT. - Basic python3 support plus python2/3 cross compatibility. - Absorbing TODO in README.md. - README => README.md. - Added support for referenced properties. - Added tests for referenced properties and saving as well. - Minor tweaks in code. - Code moved to new git repo. pyjavaproperties-0.7/README.rst0000664000175000017500000000550013422552002016637 0ustar anandanand00000000000000About ----- This is a fork of "python replacement for java.util.Properties" recipe on ASPN: http://code.activestate.com/recipes/496795/ The project is maintained by Anand B Pillai anandpillai@letterboxes.org, anand@anvetsu.com . License ------- The code is re-licensed under MIT License. See ``LICENSE`` file for more details. What this is ------------ This module is designed to be a python equivalent to the ``java.util.Properties ``\ \_ class. Currently, the basic input/output methods are supported. Fundamentally, this module is designed so that users can easily parse and manipulate Java Properties files - that's it. There's a fair number of us pythonistas who work in multi-language shops, and constantly writing your own parsing mechanism is just painful. Not to mention Java guys are notoriously unwilling to use anything which is cross-language for configuration, unless it's XML, which is a form of self-punishment. :) Python support -------------- The module is cross Python2 and Python3 compatible. This module has basic support for Python3. It means the tests should pass under any version of Python3 though it has been tested only for versions >= Python 3.6.6. Due to the changes for Python3, this should work under any Python2 version >= Python 2.7. Caveats ------- The code still uses Python2 type strings inside. In other words proper unicode support is still missing. Plans ----- Here is a plan for the current version which runs under Python2 in approximate decreasing priority order. 1. Keep/maintain blank lines and comments found in the original file 2. Add unicode support 3. Provide python property access on top of direct dictionary get/set 4. Make the module compatible with the new methods in latest J2SE. Usage ----- :: from pyjavaproperties import Properties p = Properties() p.load(open('test.properties')) p.list() print p print p.items() print p['name3'] p['name3'] = 'changed = value' print p['name3'] p['new key'] = 'new value' p.store(open('test2.properties','w')) See also the Properties.list() method, which will return an iterator over the property keys Tests ----- :: $ python pyjavaproperties_test.py Changes & News -------------- version 0.7 ----------- - Setup.py for release 0.7. - Created CHANGELOG.txt - Updated README.md showing tests, changes section and updates to author etc. - Relicensed to MIT from PSF. - Rewrote N.B's patch to relicense repo under MIT. - Basic python3 support plus python2/3 cross compatibility. - Absorbing TODO in README.md. - README => README.md. - Added support for referenced properties. - Added tests for referenced properties and saving as well. - Minor tweaks in code. - Code moved to new git repo. pyjavaproperties-0.7/pyjavaproperties.egg-info/0000775000175000017500000000000013422552550022261 5ustar anandanand00000000000000pyjavaproperties-0.7/pyjavaproperties.egg-info/PKG-INFO0000664000175000017500000001020113422552550023350 0ustar anandanand00000000000000Metadata-Version: 1.1 Name: pyjavaproperties Version: 0.7 Summary: Python replacement for java.util.Properties. Home-page: https://bitbucket.org/skeptichacker/pyjavaproperties/ Author: Anand B Pillai Author-email: anandpillai@letterboxes.org License: MIT License Description: About ----- This is a fork of "python replacement for java.util.Properties" recipe on ASPN: http://code.activestate.com/recipes/496795/ The project is maintained by Anand B Pillai anandpillai@letterboxes.org, anand@anvetsu.com . License ------- The code is re-licensed under MIT License. See ``LICENSE`` file for more details. What this is ------------ This module is designed to be a python equivalent to the ``java.util.Properties ``\ \_ class. Currently, the basic input/output methods are supported. Fundamentally, this module is designed so that users can easily parse and manipulate Java Properties files - that's it. There's a fair number of us pythonistas who work in multi-language shops, and constantly writing your own parsing mechanism is just painful. Not to mention Java guys are notoriously unwilling to use anything which is cross-language for configuration, unless it's XML, which is a form of self-punishment. :) Python support -------------- The module is cross Python2 and Python3 compatible. This module has basic support for Python3. It means the tests should pass under any version of Python3 though it has been tested only for versions >= Python 3.6.6. Due to the changes for Python3, this should work under any Python2 version >= Python 2.7. Caveats ------- The code still uses Python2 type strings inside. In other words proper unicode support is still missing. Plans ----- Here is a plan for the current version which runs under Python2 in approximate decreasing priority order. 1. Keep/maintain blank lines and comments found in the original file 2. Add unicode support 3. Provide python property access on top of direct dictionary get/set 4. Make the module compatible with the new methods in latest J2SE. Usage ----- :: from pyjavaproperties import Properties p = Properties() p.load(open('test.properties')) p.list() print p print p.items() print p['name3'] p['name3'] = 'changed = value' print p['name3'] p['new key'] = 'new value' p.store(open('test2.properties','w')) See also the Properties.list() method, which will return an iterator over the property keys Tests ----- :: $ python pyjavaproperties_test.py Changes & News -------------- version 0.7 ----------- - Setup.py for release 0.7. - Created CHANGELOG.txt - Updated README.md showing tests, changes section and updates to author etc. - Relicensed to MIT from PSF. - Rewrote N.B's patch to relicense repo under MIT. - Basic python3 support plus python2/3 cross compatibility. - Absorbing TODO in README.md. - README => README.md. - Added support for referenced properties. - Added tests for referenced properties and saving as well. - Minor tweaks in code. - Code moved to new git repo. Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules pyjavaproperties-0.7/pyjavaproperties.egg-info/SOURCES.txt0000664000175000017500000000045413422552550024150 0ustar anandanand00000000000000CHANGELOG.txt LICENSE MANIFEST.in README.md README.rst setup.py ./pyjavaproperties.py ./pyjavaproperties_test.py pyjavaproperties.egg-info/PKG-INFO pyjavaproperties.egg-info/SOURCES.txt pyjavaproperties.egg-info/dependency_links.txt pyjavaproperties.egg-info/top_level.txt testdata/complex.propertiespyjavaproperties-0.7/pyjavaproperties.egg-info/dependency_links.txt0000664000175000017500000000000113422552550026327 0ustar anandanand00000000000000 pyjavaproperties-0.7/pyjavaproperties.egg-info/top_level.txt0000664000175000017500000000002213422552550025005 0ustar anandanand00000000000000 pyjavaproperties pyjavaproperties-0.7/pyjavaproperties.py0000664000175000017500000002471513402165746021157 0ustar anandanand00000000000000#! /usr/bin/env python """ A Python replacement for java.util.Properties class This is modelled as closely as possible to the Java original. Created - Anand B Pillai """ from __future__ import print_function import sys,os import re import time class Properties(object): """ A Python replacement for java.util.Properties """ def __init__(self, props=None, verbose=False): # Note: We don't take a default properties object # as argument yet # Dictionary of properties. self._props = {} # Dictionary of properties with 'pristine' keys # This is used for dumping the properties to a file # using the 'store' method self._origprops = {} self._keyorder = [] # Dictionary mapping keys from property # dictionary to pristine dictionary self._keymap = {} # All regexs moved here self.othercharre = re.compile(r'(? {}'.format(ref_key, ref_val)) value = value.replace(ref, ref_val, 1) self._props[key] = value.strip() # Check if an entry exists in pristine keys if key in self._keymap: oldkey = self._keymap.get(key) self._origprops[oldkey] = oldvalue.strip() else: self._origprops[oldkey] = oldvalue.strip() # Store entry in keymap self._keymap[key] = oldkey if key not in self._keyorder: self._keyorder.append(key) def escape(self, value): """ Escaping some chars """ # Java escapes the '=' and ':' in the value # string with backslashes in the store method. # So let us do the same. newvalue = value.replace(':','\:') newvalue = newvalue.replace('=','\=') return newvalue def unescape(self, value): """ Unescaping some chars """ # Reverse of escape newvalue = value.replace('\:',':') newvalue = newvalue.replace('\=','=') return newvalue def load(self, stream): """ Load properties from an open file stream """ with stream as fp: lines = fp.readlines() self.__parse(lines) def getProperty(self, key): """ Return a property for the given key """ return self._props.get(key) def setProperty(self, key, value): """ Set the property for the given key """ if type(key) is str and type(value) is str: self.process_pair(key, value) else: raise TypeError('both key and value should be strings!') def propertyNames(self): """ Return an iterator over all the keys of the property dictionary, i.e the names of the properties """ return self._props.keys() def list(self, out=sys.stdout): """ Prints a listing of the properties to the stream 'out' which defaults to the standard output """ out.write('-- listing properties --\n') for key,value in self._props.items(): out.write(''.join((key,'=',value,'\n'))) def store(self, out, header="", timestamp=True): """ Write the properties list to the stream 'out' along with the optional 'header' """ with out as fp: if header: out.write(''.join(('#',header,'\n'))) # Write timestamp if timestamp: tstamp = time.strftime('%a %b %d %H:%M:%S %Z %Y', time.localtime()) out.write(''.join(('#',tstamp,'\n'))) # Write properties from the pristine dictionary for prop in self._keyorder: if prop in self._origprops: val = self._origprops[prop] out.write(''.join((prop,'=',self.escape(val),'\n'))) def __contains__(self, key): return key in self._props def getPropertyDict(self): return self._props def __getitem__(self, name): """ To support direct dictionary like access """ return self.getProperty(name) def __setitem__(self, name, value): """ To support direct dictionary like access """ self.setProperty(name, value) def __getattr__(self, name): """ For attributes not found in self, redirect to the properties dictionary """ try: return self.__dict__[name] except KeyError as e: if hasattr(self._props,name): return getattr(self._props, name) if __name__=="__main__": p = Properties() p.load(open('testdata/complex.properties')) p.list() print(p) print(p.items()) print(p['name3']) p['name3'] = 'changed = value' print(p['name3']) p['new key'] = 'new value' p.store(open('test.properties','w')) pyjavaproperties-0.7/pyjavaproperties_test.py0000664000175000017500000000503713402165551022204 0ustar anandanand00000000000000#! /usr/bin/env python """Basic tests to ensure pyjavaproperties behaves like java.util.Properties. Created - Pepper Lebeck-Jobe (eljobe@gmail.com) """ import os import unittest from pyjavaproperties import Properties class PyJavaPropertiesTest(unittest.TestCase): """Tests pyjavaproperties complies to java.util.Properties contract.""" def setUp(self): test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'testdata') self.properties_file = os.path.join(test_dir, 'complex.properties') def testParsePropertiesInput(self): properties = Properties() properties.load(open(self.properties_file)) self.assertEqual(25, len(properties.items())) self.assertEqual('Value00', properties['Key00']) self.assertEqual('Value01', properties['Key01']) self.assertEqual('Value02', properties['Key02']) self.assertEqual('Value03', properties['Key03']) self.assertEqual('Value04', properties['Key04']) self.assertEqual('Value05a, Value05b, Value05c', properties['Key05']) self.assertEqual('Value06a, Value06b, Value06c', properties['Key06']) self.assertEqual('Value07b', properties['Key07']) self.assertEqual( 'Value08a, Value08b, Value08c, Value08d, Value08e, Value08f', properties['Key08']) self.assertEqual( 'Value09a, Value09b, Value09c, Value09d, Value09e, Value09f', properties['Key09']) self.assertEqual('Value10', properties['Key10']) self.assertEqual('', properties['Key11']) self.assertEqual('Value12a, Value12b, Value12c', properties['Key12']) self.assertEqual('Value13 With Spaces', properties['Key13']) self.assertEqual('Value14 With Spaces', properties['Key14']) self.assertEqual('Value15 With Spaces', properties['Key15']) self.assertEqual('Value16', properties['Key16 With Spaces']) self.assertEqual('Value17', properties['Key17 With Spaces']) self.assertEqual('Value18 # Not a comment.', properties['Key18']) self.assertEqual('Value19 ! Not a comment.', properties['Key19']) # Single referenced property self.assertEqual('Value19 ! Not a comment.Value20', properties['Key20']) self.assertEqual('Value21', properties['Key21=WithEquals']) self.assertEqual('Value22', properties['Key22:WithColon']) self.assertEqual('Value23', properties['Key23']) # Multiple referenced properties with separator self.assertEqual('Value18 # Not a comment.-separator-Value19 ! Not a comment.', properties['Key24']) properties.store(open('saved.properties','w')) if __name__ == '__main__': unittest.main() pyjavaproperties-0.7/setup.cfg0000664000175000017500000000004613422552550017001 0ustar anandanand00000000000000[egg_info] tag_build = tag_date = 0 pyjavaproperties-0.7/setup.py0000664000175000017500000000170713422552521016675 0ustar anandanand00000000000000import os import sys from setuptools import setup # Use a cute trick to include the rest-style docs as the long_description # therefore having it self-doc'ed and hosted on pypi with open("README.rst", "r") as fh: long_description = fh.read() setup( name='pyjavaproperties', version='0.7', author='Anand B Pillai', author_email = 'anandpillai@letterboxes.org', description = 'Python replacement for java.util.Properties.', long_description = long_description, url='https://bitbucket.org/skeptichacker/pyjavaproperties/', license = 'MIT License', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', ], py_modules=['pyjavaproperties'], packages=[''], package_dir={'': '.'}, ) pyjavaproperties-0.7/testdata/0000775000175000017500000000000013422552550016771 5ustar anandanand00000000000000pyjavaproperties-0.7/testdata/complex.properties0000664000175000017500000000224013401700607022547 0ustar anandanand00000000000000# notKey00:notValue00 This is a comment and ignored. ! notKey01:notValue01 This is a comment and ignored. # notKey02=notValue02 This is a comment and ignored. ! notKey03=notValue03 This is a comment and ignored. Key00:Value00 Key01=Value01 Key02:Value02 Key03 : Value03 Key04 = Value04 Key05: Value05a, Value05b, Value05c Key06 = Value06a, Value06b, Value06c Key07 = Value07a Key07 = Value07b Key08: Value08a, Value08b, \ Value08c, Value08d, \ Value08e, Value08f Key09 = Value09a, Value09b, \ Value09c, Value09d, \ Value09e, Value09f # notKey04=notValue04 This is a comment and ignored. Key10 Value10 ! notKey05=notValue05 This is a comment and ignored. Key11 Key12 Value12a, Value12b, Value12c Key13:Value13 With Spaces Key14=Value14 With Spaces Key15 Value15 With Spaces Key16\ With\ Spaces:Value16 Key17\ With\ Spaces=Value17 Key18 = Value18 # Not a comment. Key19 : Value19 ! Not a comment. # Referencing previous properties Key20 = {Key19}Value20 Key21\=WithEquals = Value21 Key22\:WithColon : Value22 Key23 Value23 # Referencing previous multiple properties Key24 {Key18}-separator-{Key19}