當前位置: 首頁>>代碼示例>>Python>>正文


Python parser.ParserError方法代碼示例

本文整理匯總了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') 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:21,代碼來源:input_checks.py

示例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 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:20,代碼來源:workflow_helper.py

示例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) 
開發者ID:digidotcom,項目名稱:python-devicecloud,代碼行數:13,代碼來源:util.py

示例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) 
開發者ID:magnific0,項目名稱:nokia-weight-sync,代碼行數:9,代碼來源:nokia.py

示例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 
開發者ID:tmrowco,項目名稱:electricitymap-contrib,代碼行數:13,代碼來源:US_NY.py

示例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) 
開發者ID:demisto,項目名稱:dockerfiles,代碼行數:13,代碼來源:date.py

示例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) 
開發者ID:demisto,項目名稱:dockerfiles,代碼行數:6,代碼來源:test_utils.py

示例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)) 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:14,代碼來源:arrow.py

示例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)) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:10,代碼來源:validation.py

示例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)) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:7,代碼來源:validation.py


注:本文中的arrow.parser.ParserError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。