Skip to content

Commit e242c30

Browse files
committed
Merge pull request influxdata#296 from anonymouzz/master
Fix unicode data handling in tag's content (Thanks @anonymouzz !)
2 parents c101386 + f132aae commit e242c30

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

influxdb/line_protocol.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from numbers import Integral
88

99
from dateutil.parser import parse
10-
from six import binary_type, text_type, integer_types
10+
from six import binary_type, text_type, integer_types, PY2
1111

1212

1313
def _convert_timestamp(timestamp, precision=None):
@@ -74,7 +74,10 @@ def _get_unicode(data, force=False):
7474
elif data is None:
7575
return ''
7676
elif force:
77-
return str(data)
77+
if PY2:
78+
return unicode(data)
79+
else:
80+
return str(data)
7881
else:
7982
return data
8083

influxdb/tests/test_line_protocol.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
23

34
import sys
45
if sys.version_info < (2, 7):
@@ -55,3 +56,23 @@ def test_string_val_newline(self):
5556
line_protocol.make_lines(data),
5657
'm1 multi_line="line1\\nline1\\nline3"\n'
5758
)
59+
60+
def test_make_lines_unicode(self):
61+
data = {
62+
"tags": {
63+
"unicode_tag": "\'Привет!\'" # Hello! in Russian
64+
},
65+
"points": [
66+
{
67+
"measurement": "test",
68+
"fields": {
69+
"unicode_val": "Привет!", # Hello! in Russian
70+
}
71+
}
72+
]
73+
}
74+
75+
self.assertEqual(
76+
line_protocol.make_lines(data),
77+
'test,unicode_tag=\'Привет!\' unicode_val="Привет!"\n'
78+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy