|
1 | 1 | """Point data structure to represent LineProtocol."""
|
2 | 2 |
|
3 | 3 | import math
|
| 4 | +import warnings |
4 | 5 | from builtins import int
|
5 | 6 | from datetime import datetime, timedelta, timezone
|
6 | 7 | from decimal import Decimal
|
@@ -181,6 +182,13 @@ def to_line_protocol(self, precision=None):
|
181 | 182 | :param precision: required precision of LineProtocol. If it's not set then use the precision from ``Point``.
|
182 | 183 | """
|
183 | 184 | _measurement = _escape_key(self._name, _ESCAPE_MEASUREMENT)
|
| 185 | + if _measurement.startswith("#"): |
| 186 | + message = f"""The measurement name '{_measurement}' start with '#'. |
| 187 | +
|
| 188 | +The output Line protocol will be interpret as a comment by InfluxDB. For more info see: |
| 189 | + - https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/#comments |
| 190 | + """ |
| 191 | + warnings.warn(message, SyntaxWarning) |
184 | 192 | _tags = _append_tags(self._tags)
|
185 | 193 | _fields = _append_fields(self._fields)
|
186 | 194 | if not _fields:
|
@@ -249,26 +257,26 @@ def _append_fields(fields):
|
249 | 257 | return f"{','.join(_return)}"
|
250 | 258 |
|
251 | 259 |
|
252 |
| -def _append_time(time, write_precision): |
| 260 | +def _append_time(time, write_precision) -> str: |
253 | 261 | if time is None:
|
254 | 262 | return ''
|
255 | 263 | return f" {int(_convert_timestamp(time, write_precision))}"
|
256 | 264 |
|
257 | 265 |
|
258 |
| -def _escape_key(tag, escape_list=None): |
| 266 | +def _escape_key(tag, escape_list=None) -> str: |
259 | 267 | if escape_list is None:
|
260 | 268 | escape_list = _ESCAPE_KEY
|
261 | 269 | return str(tag).translate(escape_list)
|
262 | 270 |
|
263 | 271 |
|
264 |
| -def _escape_tag_value(value): |
| 272 | +def _escape_tag_value(value) -> str: |
265 | 273 | ret = _escape_key(value)
|
266 | 274 | if ret.endswith('\\'):
|
267 | 275 | ret += ' '
|
268 | 276 | return ret
|
269 | 277 |
|
270 | 278 |
|
271 |
| -def _escape_string(value): |
| 279 | +def _escape_string(value) -> str: |
272 | 280 | return str(value).translate(_ESCAPE_STRING)
|
273 | 281 |
|
274 | 282 |
|
|
0 commit comments