@@ -63,41 +63,51 @@ def make_lines(data):
63
63
Extracts the points from the given dict and returns a Unicode string
64
64
matching the line protocol introduced in InfluxDB 0.9.0.
65
65
"""
66
- lines = ""
66
+ lines = []
67
67
static_tags = data .get ('tags' , None )
68
68
for point in data ['points' ]:
69
+ elements = []
70
+
69
71
# add measurement name
70
- lines + = _escape_tag (_force_text (
72
+ measurement = _escape_tag (_force_text (
71
73
point .get ('measurement' , data .get ('measurement' ))
72
- )) + ","
74
+ ))
75
+ key_values = [measurement ]
73
76
74
77
# add tags
75
78
if static_tags is None :
76
79
tags = point .get ('tags' , {})
77
80
else :
78
81
tags = copy (static_tags )
79
82
tags .update (point .get ('tags' , {}))
83
+
80
84
# tags should be sorted client-side to take load off server
81
85
for tag_key in sorted (tags .keys ()):
82
86
key = _escape_tag (tag_key )
83
87
value = _escape_tag (tags [tag_key ])
84
88
if key != '' and value != '' :
85
- lines += "{key}={value}," .format (key = key , value = value )
86
- lines = lines [:- 1 ] + " " # strip the trailing comma
89
+ key_values .append ("{key}={value}" .format (key = key , value = value ))
90
+ key_values = ',' .join (key_values )
91
+ elements .append (key_values )
87
92
88
93
# add fields
94
+ field_values = []
89
95
for field_key in sorted (point ['fields' ].keys ()):
90
- lines += "{key}={value}, " .format (
96
+ field_values . append ( "{key}={value}" .format (
91
97
key = _escape_tag (field_key ),
92
98
value = _escape_value (point ['fields' ][field_key ]),
93
- )
94
- lines = lines [:- 1 ] # strip the trailing comma
99
+ ))
100
+ field_values = ',' .join (field_values )
101
+ elements .append (field_values )
95
102
96
103
# add timestamp
97
104
if 'time' in point :
98
- lines += " " + _force_text (str (int (
105
+ timestamp = _force_text (str (int (
99
106
_convert_timestamp (point ['time' ])
100
107
)))
108
+ elements .append (timestamp )
101
109
102
- lines += "\n "
103
- return lines
110
+ line = ' ' .join (elements )
111
+ lines .append (line )
112
+ lines = '\n ' .join (lines )
113
+ return lines + '\n '
0 commit comments