From d0a0334f7ad0c8f51a09f0fc911463f93b951ab6 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Mon, 4 Nov 2019 21:51:20 -0600 Subject: [PATCH] compatibility to python 3.6 ... --- transport/__init__.py | 28 ++++++++++++++++++++-------- transport/couch.py | 6 +++++- transport/mongo.py | 6 +++++- transport/queue.py | 14 +++++++++----- transport/s3.py | 8 ++++++-- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/transport/__init__.py b/transport/__init__.py index 71d9570..41ba63a 100644 --- a/transport/__init__.py +++ b/transport/__init__.py @@ -45,12 +45,24 @@ __author__ = 'The Phi Technology' import numpy as np import json import importlib -from common import Reader, Writer #, factory -import disk -import queue -import couch -import mongo -import s3 +import sys + +if sys.version_info[0] > 2 : + from transport.common import Reader, Writer #, factory + from transport import disk + from transport import queue as queue + from transport import couch as couch + from transport import mongo as mongo + from transport import s3 as s3 +else: + from common import Reader, Writer #, factory + import disk + import queue + import couch + import mongo + import s3 + + class factory : @staticmethod def instance(**args): @@ -78,7 +90,7 @@ class factory : try: anObject = eval( aClassName) #setattr(anObject,'name',source) - except Exception,e: + except Exception as e: print ['Error ',e] return anObject @@ -207,4 +219,4 @@ class factory : # #setattr(anObject,'name',source) # except Exception,e: # print ['Error ',e] -# return anObject \ No newline at end of file +# return anObject diff --git a/transport/couch.py b/transport/couch.py index d3189f2..7aaf93e 100644 --- a/transport/couch.py +++ b/transport/couch.py @@ -7,7 +7,11 @@ This file is a wrapper around couchdb using IBM Cloudant SDK that has an interfa """ import cloudant import json -from common import Reader,Writer +import sys +if sys.version_info[0] > 2 : + from transport.common import Reader, Writer +else: + from common import Reader, Writer class Couch: """ This class is a wrapper for read/write against couchdb. The class captures common operations for read/write. diff --git a/transport/mongo.py b/transport/mongo.py index 48235e8..3854206 100644 --- a/transport/mongo.py +++ b/transport/mongo.py @@ -6,7 +6,11 @@ This file is a wrapper around mongodb for reading/writing content against a mong """ from pymongo import MongoClient # from transport import Reader,Writer -from common import Reader, Writer +import sys +if sys.version_info[0] > 2 : + from transport.common import Reader, Writer +else: + from common import Reader, Writer import json class Mongo : """ diff --git a/transport/queue.py b/transport/queue.py index 1199687..0b5228c 100644 --- a/transport/queue.py +++ b/transport/queue.py @@ -10,7 +10,11 @@ from datetime import datetime import re import json import os -from common import Reader, Writer +import sys +if sys.version_info[0] > 2 : + from transport.common import Reader, Writer +else: + from common import Reader, Writer import json class MessageQueue: @@ -31,9 +35,9 @@ class MessageQueue: self.close() return resp def close(self): - if self.connection.is_closed == False : - self.channel.close() - self.connection.close() + if self.connection.is_closed == False : + self.channel.close() + self.connection.close() class QueueWriter(MessageQueue,Writer): """ @@ -204,4 +208,4 @@ class QueueListener(QueueReader): self.init(self.qid) self.channel.basic_consume(self.callback,queue=self.qid,no_ack=True); self.channel.start_consuming() - \ No newline at end of file + diff --git a/transport/s3.py b/transport/s3.py index 12412d5..19d98b6 100644 --- a/transport/s3.py +++ b/transport/s3.py @@ -8,9 +8,13 @@ from datetime import datetime import boto import botocore from smart_open import smart_open -from common import Reader, Writer +import sys +if sys.version_info[0] > 2 : + from transport.common import Reader, Writer +else: + from common import Reader, Writer import json -from common import Reader, Writer + class s3 : """