U
    ]W                     @   s   d Z ddlmZ ddlmZ ddlZdZdZdZdZd	Z	d
Z
dd Zdjeeeeeeeeee	ee
dZeddddddgZdd Zdd ZdS )z
timeparse.py
(c) Will Roberts <wildwilhelm@gmail.com>  1 February, 2014

This is a vendored and modified copy of:
github.com/wroberts/pytimeparse @ cc0550d

It has been modified to mimic the behaviour of
https://golang.org/pkg/time/#ParseDuration
    )absolute_import)unicode_literalsNz(?P<hours>[\d.]+)hz(?P<mins>[\d.]+)mz(?P<secs>[\d.]+)sz(?P<milli>[\d.]+)msu   (?P<micro>[\d.]+)(?:us|µs)z(?P<nano>[\d.]+)nsc                 C   s   dj | dS )Nz(?:{x})?x)formatr    r   3/usr/lib/python3/dist-packages/compose/timeparse.pyopt/   s    r	   z'{HOURS}{MINS}{SECS}{MILLI}{MICRO}{NANO})HOURSMINSSECSMILLIMICRONANO)Zhoursi  )Zmins<   )Zsecs   )ZmilligMbP?)microgư>)Znanog&.>c                 C   sL   t dt d | t j}|r*|d s.dS | }tdd | D S )a  Parse a time expression, returning it as a number of seconds.  If
    possible, the return value will be an `int`; if this is not
    possible, the return will be a `float`.  Returns `None` if a time
    expression cannot be parsed from the given string.

    Arguments:
    - `sval`: the string value to parse

    >>> timeparse('1m24s')
    84
    >>> timeparse('1.2 minutes')
    72
    >>> timeparse('1.2 seconds')
    1.2
    z\s*z\s*$r   Nc                 s   s*   | ]"\}}|d k	rt | t| V  qd S )N)MULTIPLIERScast).0kvr   r   r   	<genexpr>[   s     ztimeparse.<locals>.<genexpr>)	rematch
TIMEFORMATIgroupstrip	groupdictsumitems)Zsvalr   Zmdictr   r   r   	timeparseF   s    r"   c                 C   s   |   rt| dS t| S )N
   )isdigitintfloat)valuer   r   r   r   _   s    r   )__doc__Z
__future__r   r   r   r
   r   r   r   r   r   r	   r   r   dictr   r"   r   r   r   r   r   <module>   s8   	
