U
    >Ke                     @   sl   d dl Z d dlZddd Zddd Zdd Zdd	d
ZdddZG dd deZG dd dZ	e	 Z
dS )    Nz$Revision: 1.4 $   z$Date: 2007/02/11 08:57:17 $   c                 C   s2   z| d|  d W S  tk
r,   |  Y S X dS )zReturn a string without ASCII NULs.

    This function searchers for the first NUL (ASCII 0) occurrence
    and truncates string till that position.

    N    )index
ValueError)str r	   ?/tmp/pip-unpacked-wheel-5xrpv5dc/tablib/packages/dbfpy/utils.pyunzfill   s    r   c                 C   s   | dkrt j S t| t jr"| S t| t j r6|  S t| ttfrPt j| S t| tr| dd} t	| dkrt jt
| ddd  S t jt
| ddd  S t| drt j| dd  S t j|  S )	a  Return `datetime.date` instance.

    Type of the ``date`` argument could be one of the following:
        None:
            use current date value;
        datetime.date:
            this value will be returned;
        datetime.datetime:
            the result of the date.date() will be returned;
        string:
            assuming "%Y%m%d" or "%y%m%dd" format;
        number:
            assuming it's a timestamp (returned for example
            by the time.time() call;
        sequence:
            assuming (year, month, day, ...) sequence;

    Additionally, if ``date`` has callable ``ticks`` attribute,
    it will be used and result of the called would be treated
    as a timestamp value.

    N 0   z%y%m%d   z%Y%m%d__getitem__)datetimedatetoday
isinstanceintfloatfromtimestampr   replacelentimestrptimehasattrticks)r   r	   r	   r
   getDate"   s     


r   c                 C   s   | dkrt j  S t| t j r"| S t| t jr>t j |  S t| ttfrXt j | S t| t	rjt
dt| drt j t| dd  S t j |  S )a  Return `datetime.datetime` instance.

    Type of the ``value`` argument could be one of the following:
        None:
            use current date value;
        datetime.date:
            result will be converted to the `datetime.datetime` instance
            using midnight;
        datetime.datetime:
            ``value`` will be returned as is;
        string:
            *** CURRENTLY NOT SUPPORTED ***;
        number:
            assuming it's a timestamp (returned for example
            by the time.time() call;
        sequence:
            assuming (year, month, day, ...) sequence;

    Additionally, if ``value`` has callable ``ticks`` attribute,
    it will be used and result of the called would be treated
    as a timestamp value.

    Nz$Strings aren't currently implementedr   r   )r   r   r   r   fromordinal	toordinalr   r   r   r   NotImplementedErrorr   tupler   )valuer	   r	   r
   getDateTimeP   s    


r$   c                   @   s   e Zd ZdZdd ZdS )classpropertyz=Works in the same way as a ``property``, but for the classes.c                 C   s
   |  |S N)fget)selfobjclsr	   r	   r
   __get__}   s    zclassproperty.__get__N)__name__
__module____qualname____doc__r+   r	   r	   r	   r
   r%   z   s   r%   c                   @   sL   e Zd ZdZdd Zdd Zdd Zdd	 ZeZd
d Z	dd Z
dd ZdS )_InvalidValuea  Value returned from DBF records when field validation fails

    The value is not equal to anything except for itself
    and equal to all empty values: None, 0, empty string etc.
    In other words, invalid value is equal to None and not equal
    to None at the same time.

    This value yields zero upon explicit conversion to a number type,
    empty string for string types, and False for boolean.

    c                 C   s   | S r&   r	   r(   otherr	   r	   r
   __eq__   s    z_InvalidValue.__eq__c                 C   s   || k	S r&   r	   r1   r	   r	   r
   __ne__   s    z_InvalidValue.__ne__c                 C   s   dS )NFr	   r(   r	   r	   r
   __bool__   s    z_InvalidValue.__bool__c                 C   s   dS )Nr   r	   r5   r	   r	   r
   __int__   s    z_InvalidValue.__int__c                 C   s   dS )Ng        r	   r5   r	   r	   r
   	__float__   s    z_InvalidValue.__float__c                 C   s   dS )N r	   r5   r	   r	   r
   __str__   s    z_InvalidValue.__str__c                 C   s   dS )Nz	<INVALID>r	   r5   r	   r	   r
   __repr__   s    z_InvalidValue.__repr__N)r,   r-   r.   r/   r3   r4   r6   r7   Z__long__r8   r:   r;   r	   r	   r	   r
   r0      s   r0   )N)N)r   r   __version____date__r   r   r$   propertyr%   r0   ZINVALID_VALUEr	   r	   r	   r
   <module>   s   
.
*&