本文整理匯總了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))