summaryrefslogtreecommitdiff
path: root/pyinfluxtools
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2015-08-14 20:20:37 +0200
committerYves Fischer <yvesf-git@xapek.org>2015-08-14 20:20:37 +0200
commit72f76fd2b55271fd6aa8609e6dbda6011caad0a1 (patch)
tree7ab0e44995e90a7acebc235fb1a0c117971bd985 /pyinfluxtools
parent34b4ce45511cf26a7846bb3524581c97a158e868 (diff)
downloadpyinflux-72f76fd2b55271fd6aa8609e6dbda6011caad0a1.tar.gz
pyinflux-72f76fd2b55271fd6aa8609e6dbda6011caad0a1.zip
treat '=' in measurement and floats properly
Diffstat (limited to 'pyinfluxtools')
-rw-r--r--pyinfluxtools/__init__.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/pyinfluxtools/__init__.py b/pyinfluxtools/__init__.py
index 7ce39aa..543b7b2 100644
--- a/pyinfluxtools/__init__.py
+++ b/pyinfluxtools/__init__.py
@@ -49,7 +49,7 @@ class Write(object):
('Equal', (r'=',)),
('Quote', (r'"',)),
('Escape', (r'\\',)),
- ('Int', (r'[0-9]+',)),
+ ('Int', (r'[0-9]+(?![0-9\.])',)),
('Float', (r'-?(\.[0-9]+)|([0-9]+(\.[0-9]*)?)',)),
('Char', (r'.',)),
]
@@ -70,6 +70,9 @@ class Write(object):
>>> print(Write.parse('cpu a=1'))
cpu a=1
+ >>> print(Write.parse('yahoo.CHFGBP=X.ask,tag=foobar value=10.2'))
+ yahoo.CHFGBP=X.ask,tag="foobar" value=10.2
+
>>> Write.parse('cpu,host=serverA,region=us-west foo=bar')
<Write key=cpu tags=[('host', 'serverA'), ('region', 'us-west')] fields=[('foo', 'bar')] timestamp=None>
@@ -172,7 +175,7 @@ class Write(object):
plain_float_text = someToken('Float') >> tokval
plain_float = plain_float_text >> (lambda v: float(v))
- identifier = many(char | escape_space | escape_comma |
+ identifier = many(char | equal | escape_space | escape_comma |
escape_escape | plain_int_text | quote) >> joinval
quoted_text_ = many(escape_quote | space | plain_int_text |
plain_float_text | char | comma |
@@ -216,6 +219,9 @@ class Write(object):
self.__class__.__name__, self.key, self.tags, self.fields, self.timestamp)
def __str__(self):
+ def escape_identifier(string):
+ return re.sub(r'([\\, ])', '\\\\\\1', string)
+
def escape_key(string):
return re.sub(r'([\\,= ])', '\\\\\\1', string)
@@ -231,7 +237,7 @@ class Write(object):
map(lambda kv: escape_key(kv[0]) + "=" + escape_value(kv[1]),
kvlist))
- result = escape_key(self.key)
+ result = escape_identifier(self.key)
if self.tags:
result += ","