Beispiel #1
0
def known_fmt_handler_mdY_IMS_p(date_str, cls,
                                tzinfo=__tz_info,
                                parse=_mdY_IMS_handler_re.match,
                                _len=len, _int=int):
    """
    Handler for '%m/%d/%Y %I:%M:%S %p' format

    @param date_str: date string to parse
    @type date_str: str
    @param cls: cls to return. Datetime.Datetime.
    @type cls: datetime.datetime
    @param parse: re to use to match. Do not use- arg present for speed.
    @type parse: _sre.SRE_Pattern
    @return:git
    @rtype:
    """
    
    result = parse(date_str)
    if not result or result.end() != _len(date_str):
        raise HandlerMismatch

    month, day, year, hour, minute, second, ampm = result.groups()

    # Fix hour for ampm
    hour = _int(hour)
    if ampm == 'PM':
        if hour != 12:
            hour += 12
    elif hour == 12:
        hour = 0

    # noinspection PyCallingNonCallable
    return cls(_int(year), _int(month), _int(day), hour, _int(minute), _int(second), 0, tzinfo)
Beispiel #2
0
def __fast_parse_date(date_string, fmt, regex_cache=_regex_cache, TimeRE_cache=_TimeRE_cache, _len=_len):
    """

    Delve into the innards of _strptime.py to find the logic
    for determining whether a datestring is valid or not.


    @param date_string: date string to scan
    @type date_string: str
    @param fmt: strptime format use for scan
    @type fmt: str
    @return: True/False
    @rtype: bool

    """

    format_regex = regex_cache.get(fmt)
    if not format_regex:
        try:
            format_regex = TimeRE_cache.compile(fmt)
        except:
            return False
        regex_cache[fmt] = format_regex

    # Check against match.end() to ensure the full string matched
    # see _strptime line 340

    match = format_regex.match(date_string)
    return match and _len(date_string) == match.end()
Beispiel #3
0
def known_fmt_handler_mdY_HM(date_str, cls,
                             tzinfo=__tz_info,
                             parse=_mdY_HMhandler_re.match,
                             _len=len,
                             _int=int):
    """
    Handler for "%m/%d/%Y %H:%M" format

    @param date_str: date string to parse
    @type date_str: str
    @param cls: cls to return. Datetime.Datetime.
    @type cls: datetime.datetime
    @param parse: re to use to match. Do not use- arg present for speed.
    @type parse: _sre.SRE_Pattern
    @return:
    @rtype:
    """
    
    result = parse(date_str)
    if not result or result.end() != _len(date_str):
        raise HandlerMismatch
    month, day, year, hour, minute = result.groups()

    # noinspection PyCallingNonCallable
    return cls(_int(year), _int(month), _int(day), _int(hour), _int(minute), 0, 0, tzinfo)
Beispiel #4
0
def known_fmt_handler_mdY(date_str, cls,
                          tzinfo=__tz_info,
                          parse=_mdYhandler_re.match,
                          _len=len,
                          _int=int):
    """
    Handler for "%m/%d/%Y" format. This format often pops up when
    time turns over to at midnight.

    @param date_str: date string to parse
    @type date_str: str
    @param cls: cls to return. Datetime.Datetime.
    @type cls: datetime.datetime
    @param parse: re to use to match. Do not use- arg present for speed.
    @type parse: _sre.SRE_Pattern
    @return:
    @rtype:
    """

    result = parse(date_str)
    if not result or result.end() != _len(date_str):
        raise HandlerMismatch

    month, day, year = result.groups()

    # noinspection PyCallingNonCallable
    return cls(_int(year), _int(month), _int(day), 0, 0, 0, 0, tzinfo)
def len(obj):
    try:
        return _len(obj)
    except TypeError:
        try:
            # note: this is an internal undocumented API,
            # don't rely on it in your own programs
            return obj.__length_hint__()
        except AttributeError:
            raise TypeError
Beispiel #6
0
def len(obj):
    try:
        return _len(obj)
    except TypeError:
        try:
            # note: this is an internal undocumented API,
            # don't rely on it in your own programs
            return obj.__length_hint__()
        except AttributeError:
            raise TypeError