소스 검색

HUE-8737 [core] Futurize desktop/libs/kafka for Python 3.5

Ying Chen 6 년 전
부모
커밋
8930373b1d
2개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 6 5
      desktop/libs/kafka/src/kafka/kafka_api.py
  2. 3 2
      desktop/libs/kafka/src/kafka/kafka_client.py

+ 6 - 5
desktop/libs/kafka/src/kafka/kafka_api.py

@@ -16,6 +16,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import print_function
 import json
 import logging
 
@@ -44,12 +45,12 @@ def error_handler(view_fn):
 
     try:
       return view_fn(*args, **kwargs)
-    except KafkaApiException, e:
+    except KafkaApiException as e:
       try:
         response['message'] = json.loads(e.message)
       except Exception:
         response['message'] = force_unicode(e.message)
-    except Exception, e:
+    except Exception as e:
       message = force_unicode(e)
       response['message'] = message
       LOG.exception(message)
@@ -105,9 +106,9 @@ def get_topics():
     try:
       manager = ManagerApi()
       broker_host = manager.get_kafka_brokers().split(',')[0].split(':')[0]
-      return [name for name in manager.get_kafka_topics(broker_host).keys() if not name.startswith('__')]
-    except Exception, e:
-      print e
+      return [name for name in list(manager.get_kafka_topics(broker_host).keys()) if not name.startswith('__')]
+    except Exception as e:
+      print(e)
       return ["traffic", "hueAccessLogs"]
 
 

+ 3 - 2
desktop/libs/kafka/src/kafka/kafka_client.py

@@ -16,6 +16,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 import json
 
@@ -63,7 +64,7 @@ class KafkaApi(object):
     try:
       response = self._root.get('topics')
       return json.loads(response)
-    except RestException, e:
+    except RestException as e:
       raise KafkaApiException(e)
 
 
@@ -78,5 +79,5 @@ class KafkaApi(object):
            'partitions': partitions,
            'replication_factor': replication_factor
       })
-    except RestException, e:
+    except RestException as e:
       raise KafkaApiException(e)