本文整理汇总了Python中arrow.parser.ParserError方法的典型用法代码示例。如果您正苦于以下问题:Python parser.ParserError方法的具体用法?Python parser.ParserError怎么用?Python parser.ParserError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.parser
的用法示例。
在下文中一共展示了parser.ParserError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_workflow_id
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def check_workflow_id(ctx, workflow_id):
"""Verifies that a workflow id matches the desired format"""
if workflow_id is None:
ctx.fail('Invalid ID. None is not a valid workflow ID.')
if '__' not in workflow_id:
ctx.fail('Invalid ID. The ID must cotain a double underscore '
'separating the workflow name from the execution date')
input_date_string = workflow_id.split('__')[1]
date_format_ok = True
try:
parsed_dt = arrow.get(input_date_string)
if input_date_string != parsed_dt.format('YYYY-MM-DDTHH:mm:ss.SSSSSS'):
date_format_ok = False
except ParserError:
date_format_ok = False
if not date_format_ok:
ctx.fail('Invalid ID. The date portion of the ID must conform to '
'YYYY-MM-DDTHH:mm:ss.SSSSSS')
示例2: _get_threshold_date
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def _get_threshold_date(since_iso8601=None):
# generates the threshold date from the input. Defaults to
# 30 days prior to UTC now.
threshold_date = None
if since_iso8601 is None:
threshold_date = arrow.utcnow().shift(days=-30)
else:
try:
threshold_date = arrow.get(since_iso8601)
except ParserError as parser_err:
LOG.error(
'Unable to parse date from %s. Error: %s, defaulting to '
'now minus 30 days',
since_iso8601,
str(parser_err)
)
threshold_date = arrow.utcnow().shift(days=-30)
return threshold_date.naive
示例3: iso8601_to_dt
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def iso8601_to_dt(iso8601):
"""Given an ISO8601 string as returned by Device Cloud, convert to a datetime object"""
# We could just use arrow.get() but that is more permissive than we actually want.
# Internal (but still public) to arrow is the actual parser where we can be
# a bit more specific
parser = DateTimeParser()
try:
arrow_dt = arrow.Arrow.fromdatetime(parser.parse_iso(iso8601))
return arrow_dt.to('utc').datetime
except ParserError as pe:
raise ValueError("Provided was not a valid ISO8601 string: %r" % pe)
示例4: set_attributes
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def set_attributes(self, data):
self.data = data
for key, val in data.items():
try:
setattr(self, key, arrow.get(val) if is_date(key) else val)
except ParserError:
setattr(self, key, val)
示例5: timestamp_converter
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def timestamp_converter(timestamp_string):
"""
Converts timestamps in nyiso data into aware datetime objects.
"""
try:
dt_naive = arrow.get(timestamp_string, 'MM/DD/YYYY HH:mm:ss')
except ParserError:
dt_naive = arrow.get(timestamp_string, 'MM/DD/YYYY HH:mm')
dt_aware = dt_naive.replace(tzinfo='America/New_York').datetime
return dt_aware
示例6: insert
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def insert(self):
if DEBUG:
print('Adding date...')
try:
formatted_date = get_formatted_date(self.section.contents,
self.section.layout)
except ParserError as e:
formatted_date = 'n/a'
insert_text(self.cell_object, formatted_date)
示例7: test_get_formatted_date_invalid
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def test_get_formatted_date_invalid():
default_date_format = ''
with pytest.raises(ParserError):
get_formatted_date('wowowowow', default_date_format)
示例8: _get_tzinfo
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def _get_tzinfo(tz_expr):
if tz_expr is None:
return dateutil_tz.tzutc()
if isinstance(tz_expr, tzinfo):
return tz_expr
else:
try:
return parser.TzinfoParser.parse(tz_expr)
except parser.ParserError:
raise ValueError('\'{0}\' not recognized as a timezone'.format(
tz_expr))
示例9: timestamp
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def timestamp(value, key):
try:
return arrow.get(value).datetime
except ValueError:
raise ValueError('Invalid timestamp value {} for {}'.
format(value, key))
except ParserError:
raise ValueError('Invalid datetime value {} for {}'.format(value, key))
示例10: valid_when
# 需要导入模块: from arrow import parser [as 别名]
# 或者: from arrow.parser import ParserError [as 别名]
def valid_when(when):
try:
parse_as_when(when)
except (ValueError, ParserError) as e:
raise InputError(str(e))