Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/301137

Change subject: Bring over other previously reverted changes
......................................................................

Bring over other previously reverted changes

These are needed for confluent-kafka handler

Change-Id: Iab5875e3ab719bae7fd3dca5e112e92527930f88
---
M eventlogging/factory.py
M requirements.txt
M tests/test_factory.py
3 files changed, 20 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/eventlogging 
refs/changes/37/301137/1

diff --git a/eventlogging/factory.py b/eventlogging/factory.py
index 43d7ac7..f169834 100644
--- a/eventlogging/factory.py
+++ b/eventlogging/factory.py
@@ -6,6 +6,7 @@
   This module implements a factory-like map of URI scheme handlers.
 
 """
+import ast
 import contextlib
 import inspect
 
@@ -34,7 +35,7 @@
         'false': False
     }.get(v.lower(), v)
 
-    # Else try to convert v to an int or float
+    # Else try to convert v to an int or float or array or dict.
     if type(v) is not bool:
         try:
             v = int(v)
@@ -42,7 +43,14 @@
             try:
                 v = float(v)
             except ValueError:
-                pass
+                # If this looks like it could be an array or a dict, then try
+                # to parse it with ast.literal_eval.
+                if v.startswith('[') or v.startswith('{'):
+                    try:
+                        v = ast.literal_eval(v)
+                    except ValueError:
+                        pass
+
     return v
 
 
diff --git a/requirements.txt b/requirements.txt
index 49ec4fd..c79e24e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,7 @@
 python-dateutil>=1.5
 jsonschema>=0.7
-kafka-python>=0.9.4
+confluent-kafka>=0.9.1.2
+kafka-python==0.9.4
 mysqlclient>=1.3.7
 pygments>=1.5
 pykafka>=2.1.0
diff --git a/tests/test_factory.py b/tests/test_factory.py
index c9e9ce5..b78e4f0 100644
--- a/tests/test_factory.py
+++ b/tests/test_factory.py
@@ -84,3 +84,11 @@
             True,
             eventlogging.factory.cast_string("True")
         )
+        self.assertEqual(
+            ['string', 10],
+            eventlogging.factory.cast_string('["string", 10]')
+        )
+        self.assertEqual(
+            {'string': 10},
+            eventlogging.factory.cast_string('{"string": 10}')
+        )

-- 
To view, visit https://gerrit.wikimedia.org/r/301137
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab5875e3ab719bae7fd3dca5e112e92527930f88
Gerrit-PatchSet: 1
Gerrit-Project: eventlogging
Gerrit-Branch: master
Gerrit-Owner: Ottomata <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to