1
1
import base64
2
2
import codecs
3
3
import csv as csv_parser
4
+ import sys
4
5
from enum import Enum
5
6
from typing import List
6
7
7
- import ciso8601
8
+ from dateutil import parser
8
9
from urllib3 import HTTPResponse
9
10
10
11
from influxdb_client .client .flux_table import FluxTable , FluxColumn , FluxRecord
@@ -194,7 +195,7 @@ def _to_value(self, str_val, column):
194
195
if "dateTime:RFC3339" == column .data_type or "dateTime:RFC3339Nano" == column .data_type :
195
196
# todo nanosecods precision
196
197
# return str_val
197
- return ciso8601 . parse_datetime (str_val )
198
+ return parse_string_to_datetime (str_val )
198
199
# return timestamp_parser(str_val)
199
200
200
201
if "duration" == column .data_type :
@@ -230,4 +231,31 @@ def add_column_names_and_tags(table, csv):
230
231
231
232
def _insert_table (self , table , table_index ):
232
233
if self ._serialization_mode is FluxSerializationMode .tables :
233
- self .tables .insert (table_index , table )
234
+ self .tables .insert (table_index , table )
235
+
236
+
237
+ def parse_string_to_datetime (date ):
238
+ if is_module_available ("ciso8601" ):
239
+ import ciso8601
240
+ return ciso8601 .parse_datetime (date )
241
+ else :
242
+ return parser .parse (date )
243
+
244
+
245
+ def is_module_available (module_name ):
246
+ module = None
247
+
248
+ if sys .version_info < (3 , 0 ):
249
+ # python 2
250
+ import importlib
251
+ module = importlib .find_loader (module_name )
252
+ elif sys .version_info <= (3 , 3 ):
253
+ # python 3.0 to 3.3
254
+ import pkgutil
255
+ module = pkgutil .find_loader (module_name )
256
+ elif sys .version_info >= (3 , 4 ):
257
+ # python 3.4 and above
258
+ import importlib
259
+ module = importlib .util .find_spec (module_name )
260
+
261
+ return module is not None
0 commit comments