139924aceaed — Carsten Grohmann 9 months ago
Add support for Python3
4 files changed, 22 insertions(+), 17 deletions(-)

M .build.yml
M JsonDottedReadAccess.py
M README.md
M test.py
M .build.yml +1 -0
@@ 28,6 28,7 @@ tasks:
   - unittests: |
       cd JsonDottedReadAccess
       python2 ./test.py
+      python3 ./test.py
 triggers:
   - action: email
     condition: failure

          
M JsonDottedReadAccess.py +5 -2
@@ 17,10 17,13 @@ 
 # 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.
 
-import UserDict
+try:
+    from UserDict import UserDict
+except:
+    from collections import UserDict
 
 
-class JsonDottedReadAccess(UserDict.UserDict):
+class JsonDottedReadAccess(UserDict):
     """
     Extended dictionary implementation to simplify access nested elements
     by a single key. Nested items separated by a dot "." in the key.

          
M README.md +4 -3
@@ 6,10 6,11 @@ Json Dotted Read Access
 Simplify deep access to JSON structures by introduce a dotted access notation. 
 
 ## Supported and tested Python versions
- * Python 2.7
+ * Python 2.7, tested with 2.7.17
+ * Python 3, tested with 3.8.1
  
 ## Requirements
-There are no additional requirements. All you need is Python2.
+There are no additional requirements. All you need is Python.
 
 ## Installation
 Add the file `JsonDottedReadAccess.py` to your project and activate it like described in the "Usage" section.

          
@@ 30,7 31,7 @@ Add the file `JsonDottedReadAccess.py` t
 [{'level3-b': 1}]
 ```
 
-## Project page and feedback
+## Project repository
 * [Mercurial Repository](https://hg.sr.ht/~carstengrohmann/JsonDottedReadAccess)
 
 ## License

          
M test.py +12 -12
@@ 25,31 25,31 @@ from JsonDottedReadAccess import JsonDot
 class MyTestCase(unittest.TestCase):
 
     def test_JsonDottedReadAccess(self):
-        simple_dict = {u'level1': {u'level21': None,
-                                   u'level22': [{'level3': 1}, ],
-                                   u'level23': {'level3': 1},
-                                   u'level24': 'level24',
-                                   }}
+        simple_dict = {'level1': {'level21': None,
+                                  'level22': [{'level3': 1}, ],
+                                  'level23': {'level3': 1},
+                                  'level24': 'level24',
+                                  }}
         json_access = JsonDottedReadAccess(simple_dict)
 
         # simple access
-        self.failUnlessEqual(json_access['level1.level21'], None)
-        self.failUnlessEqual(json_access['level1.level24'], 'level24')
+        self.assertEqual(json_access['level1.level21'], None)
+        self.assertEqual(json_access['level1.level24'], 'level24')
 
         # check if ValueError is raised for access with non-numeric value to a list
         def raiseKeyError1():
             json_access['level1.level22.A']
-        self.failUnlessRaises(KeyError, raiseKeyError1)
+        self.assertRaises(KeyError, raiseKeyError1)
 
         def raiseKeyError2():
             json_access['non-existing']
-        self.failUnlessRaises(KeyError, raiseKeyError2)
-        self.failUnlessEqual(json_access.get('non-existing'), None)
+        self.assertRaises(KeyError, raiseKeyError2)
+        self.assertEqual(json_access.get('non-existing'), None)
 
         def raiseKeyError3():
             json_access['level1.non-existing.level3']
-        self.failUnlessRaises(KeyError, raiseKeyError3)
-        self.failUnlessEqual(json_access.get('level1.non-existing.level3'), None)
+        self.assertRaises(KeyError, raiseKeyError3)
+        self.assertEqual(json_access.get('level1.non-existing.level3'), None)
 
 
 if __name__ == '__main__':