î
lÐR\  ã               @   s¡   d  Z  d d d … Z d d d … Z d d l Z d d l Z d d	 „  Z d d
 d „ Z d d d „ Z Gd d „  d e ƒ Z	 Gd d „  d e
 ƒ Z e ƒ  Z d S)zCString utilities.

TODO:
  - allow strings in getDateTime routine;
z$Revision: 1.4 $é   é   z$Date: 2007/02/11 08:57:17 $é   é    Nc             C   s8   y |  d |  j  d ƒ … SWn t k
 r3 |  SYn Xd S)z™Return a string without ASCII NULs.

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

    Ns    )ÚindexÚ
ValueError)Ústr© r   úQ/var/www/dbchiro/venv/lib/python3.4/site-packages/tablib/packages/dbfpy3/utils.pyÚunzfill   s    r
   c             C   s%  |  d k r t  j j ƒ  St |  t  j ƒ r/ |  St |  t  j  ƒ rK |  j ƒ  St |  t t f ƒ rp t  j j |  ƒ St |  t ƒ ré |  j d d ƒ }  t	 |  ƒ d k rÆ t  j t
 j |  d ƒ d d … Œ  St  j t
 j |  d ƒ d d … Œ  St |  d ƒ rt  j |  d d … Œ  St  j j |  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;

    Additionaly, 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  j ƒ  St |  t  j  ƒ r/ |  St |  t  j ƒ rW t  j  j |  j ƒ  ƒ St |  t t f ƒ r| t  j  j |  ƒ St |  t	 ƒ rš t
 d ƒ ‚ n  t |  d ƒ rÆ t  j  t |  ƒ d d … Œ  St  j  j |  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;

    Additionaly, 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	   ÚgetDateTimeO   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   |  j  | ƒ S)N)Úfget)ÚselfÚobjÚclsr   r   r	   Ú__get__|   s    zclassproperty.__get__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r   r   r   r	   r$   y   s   r$   c               @   s|   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 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)Nr   )r&   Úotherr   r   r	   Ú__eq__Ž   s    z_InvalidValue.__eq__c             C   s
   | |  k	 S)Nr   )r&   r/   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   )r&   r   r   r	   Ú__int__—   s    z_InvalidValue.__int__c             C   s   d S)Ng        r   )r&   r   r   r	   Ú	__float__›   s    z_InvalidValue.__float__c             C   s   d S)NÚ r   )r&   r   r   r	   Ú__str__ž   s    z_InvalidValue.__str__c             C   s   d S)Nr5   r   )r&   r   r   r	   Ú__unicode__¡   s    z_InvalidValue.__unicode__c             C   s   d S)Nz	<INVALID>r   )r&   r   r   r	   Ú__repr__¤   s    z_InvalidValue.__repr__N)r*   r+   r,   r-   r0   r1   r2   r3   Z__long__r4   r6   r7   r8   r   r   r   r	   r.   €   s   r.   éþÿÿÿr9   )r-   Ú__version__Ú__date__r   r   r
   r   r#   Úpropertyr$   Úobjectr.   ZINVALID_VALUEr   r   r   r	   Ú<module>   s   .*(