Some 2to3 changes.

Tue, 04 Sep 2018 18:14:50 +0300

author
Ioannis <ioannis@inoe.ro>
date
Tue, 04 Sep 2018 18:14:50 +0300
changeset 17
9d25bd3e15c4
parent 16
ddaea4327bd5
child 19
2a6a9e95bd16

Some 2to3 changes.

requirements.txt file | annotate | diff | comparison | revisions
scc_access/scc_access.py file | annotate | diff | comparison | revisions
--- a/requirements.txt	Wed Jan 10 18:06:02 2018 +0200
+++ b/requirements.txt	Tue Sep 04 18:14:50 2018 +0300
@@ -1,1 +1,1 @@
-requests
+.
\ No newline at end of file
--- a/scc_access/scc_access.py	Wed Jan 10 18:06:02 2018 +0200
+++ b/scc_access/scc_access.py	Tue Sep 04 18:14:50 2018 +0300
@@ -2,12 +2,17 @@
 requests.packages.urllib3.disable_warnings()
 
 import sys
-import urlparse
+
+try:
+    import urllib.parse as urlparse  # Python 3
+except ImportError:
+    import urlparse  # Python 2
+
 import argparse
 import os
 import re
 import time
-import StringIO
+from io import StringIO
 from zipfile import ZipFile
 import datetime
 import logging
@@ -128,7 +133,7 @@
             os.makedirs(local_dir)
 
         # Save the file by chunk, needed if the file is big.
-        memory_file = StringIO.StringIO()
+        memory_file = StringIO()
 
         for chunk in request.iter_content(chunk_size=1024):
             if chunk:  # filter out keep-alive new chunks
@@ -366,7 +371,7 @@
         return measurement_id
 
 
-class ApiObject:
+class ApiObject(object):
     """ A generic class object. """
 
     def __init__(self, base_url, dict_response):
@@ -375,7 +380,11 @@
         if dict_response:
             # Add the dictionary key value pairs as object properties
             for key, value in dict_response.items():
-                setattr(self, key, value)
+                # logger.debug('Setting key {0} to value {1}'.format(key, value))
+                try:
+                    setattr(self, key, value)
+                except:
+                    logger.warning('Could not set attribute {0} to value {1}'.format(key, value))
             self.exists = True
         else:
             self.exists = False

mercurial