Current File : //proc/self/root/proc/self/root/lib64/python2.7/site-packages/numpy/lib/_iotools.pyc
�
E�`Qc@s�dZdZddlZddlZddljjZddl	m
Z
mZmZm
Z
mZmZmZmZddlmZmZmZejddkr�d�Zd	�ZneZeZd
�Zd�Zded
�Zd�Zed�Zdefd��YZdefd��YZ d�Z!de"fd��YZ#de#fd��YZ$de%fd��YZ&defd��YZ'e(dd�Z)dS(s@A collection of functions designed to help I/O with ascii files.srestructuredtext eni����N(tbooltinttlongtfloattcomplextobjecttunicodetstr(tasbytestbytestasbytes_nestediicCst|jd��S(Ntascii(Rtdecode(ts((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_bytes_to_complexscCs
|jd�S(NR(R(R
((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_bytes_to_namescCs+y|dWnttfk
r&tSXtS(s2
    Check whether obj behaves like a string.
    t(t	TypeErrort
ValueErrortFalsetTrue(tobj((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_is_string_likes
cCs1y|td�Wnttfk
r,tSXtS(s8
    Check whether obj behaves like a bytes object.
    R(RRRRR(R((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_is_bytes_likes
trcCs�t|�r�|jd�r<ddl}|j||�}n<|jd�riddl}|j|�}nt||�}t}n*t|d�r�|}t	}nt
d��|r�||fS|S(s�
    Returns the filehandle corresponding to a string or a file.
    If the string ends in '.gz', the file is automatically unzipped.

    Parameters
    ----------
    fname : string, filehandle
        Name of the file whose filehandle must be returned.
    flag : string, optional
        Flag indicating the status of the file ('r' for read, 'w' for write).
    return_opened : boolean, optional
        Whether to return the opening status of the file.
    s.gzi����Ns.bz2tseeks%fname must be a string or file handle(Rtendswithtgziptopentbz2tBZ2FiletfileRthasattrRR(tfnametflagt
return_openedRtfhdRtopened((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_to_filehandle)s 		
cCs/x(|jpdD]}||jrtSqWtS(s�
    Returns whether one or several fields of a dtype are nested.

    Parameters
    ----------
    ndtype : dtype
        Data-type of a structured array.

    Raises
    ------
    AttributeError : If `ndtype` does not have a `names` attribute.

    Examples
    --------
    >>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float)])
    >>> np.lib._iotools.has_nested_fields(dt)
    False

    ((tnamesRR(tndtypetname((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pythas_nested_fieldsKs
cCs�|j}|dkrE|r;|jgttj|j��S|jgSg}x;|D]3}|j|}t|d|�}|j	|�qRW|SdS(s6
    Unpack a structured data-type by collapsing nested fields and/or fields
    with a shape.

    Note that the field names are lost.

    Parameters
    ----------
    ndtype : dtype
        The datatype to collapse
    flatten_base : {False, True}, optional
        Whether to transform a field with a shape into several fields or not.

    Examples
    --------
    >>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float),
    ...                ('block', int, (2, 3))])
    >>> np.lib._iotools.flatten_dtype(dt)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32')]
    >>> np.lib._iotools.flatten_dtype(dt, flatten_base=True)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32'),
     dtype('int32'), dtype('int32'), dtype('int32'), dtype('int32'),
     dtype('int32')]

    iN(
R'tNonetbaseRtnptprodtshapetfieldst
flatten_dtypetextend(R(tflatten_baseR'ttypestfieldtinfotflat_dt((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR1es	 


tLineSplittercBsSeZdZd�Zded�ed�Zd�Zd�Z	d�Z
d�ZRS(	s�
    Object to split a string at a given delimiter or at given places.

    Parameters
    ----------
    delimiter : str, int, or sequence of ints, optional
        If a string, character used to delimit consecutive fields.
        If an integer or a sequence of integers, width(s) of each field.
    comment : str, optional
        Character used to mark the beginning of a comment. Default is '#'.
    autostrip : bool, optional
        Whether to strip each individual field. Default is True.

    cs
�fd�S(s�
        Wrapper to strip each member of the output of `method`.

        Parameters
        ----------
        method : function
            Function that takes a single argument and returns a sequence of
            strings.

        Returns
        -------
        wrapped : function
            The result of wrapping `method`. `wrapped` takes a single input
            argument and returns a list of strings that are stripped of
            white-space.

        cs#g�|�D]}|j�^q
S(N(tstrip(tinputt_(tmethod(s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt<lambda>�s((tselfR<((R<s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt	autostrip�st#cCs0||_t|t�r*|jd�}n|dksBt|�rZ|pKd}|j}n�t|d�r�|j}t	j
dgt|��}gt|d |d�D]\}}t
||�^q�}n5t|�r�|jt|�}}n|jd}}||_|r#|j|�|_n	||_dS(NRt__iter__ii����i(tcommentst
isinstanceRtencodeR+Rt_delimited_splitterR t_variablewidth_splitterR-tcumsumtlisttziptsliceRt_fixedwidth_splittert	delimiterR?t	_handyman(R>RLRBR?RMtidxtitj((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt__init__�s"		<	cCsW|jdk	r(|j|j�d}n|jtd��}|sGgS|j|j�S(Nis 
(RBR+tsplitR9RRL(R>tline((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRE�scCs�|jdk	r(|j|j�d}n|jtd��}|sGgS|j}gtdt|�|�D]}t|||�^qi}g|D]}||^q�S(Nis
(	RBR+RRR9RRLtrangetlenRJ(R>RStfixedROtslicesR
((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRK�s	8cCsV|jdk	r(|j|j�d}n|s2gS|j}g|D]}||^qBS(Ni(RBR+RRRL(R>RSRWR
((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRF�s	cCs
|j|�S(N(RM(R>RS((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt__call__�sN(t__name__t
__module__t__doc__R?R+RRRQRERKRFRX(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR8�s			
	t
NameValidatorcBs\eZdZdddgZed�Zd
d
d
dd�Zdd
d�Zdd
d	�Z	RS(s!
    Object to validate a list of strings to use as field names.

    The strings are stripped of any non alphanumeric character, and spaces
    are replaced by '_'. During instantiation, the user can define a list of
    names to exclude, as well as a list of invalid characters. Names in the
    exclusion list are appended a '_' character.

    Once an instance has been created, it can be called with a list of names,
    and a list of valid names will be created.
    The `__call__` method accepts an optional keyword "default" that sets
    the default name in case of ambiguity. By default this is 'f', so
    that names will default to `f0`, `f1`, etc.

    Parameters
    ----------
    excludelist : sequence, optional
        A list of names to exclude. This list is appended to the default list
        ['return', 'file', 'print']. Excluded names are appended an underscore:
        for example, `file` becomes `file_` if supplied.
    deletechars : str, optional
        A string combining invalid characters that must be deleted from the
        names.
    casesensitive : {True, False, 'upper', 'lower'}, optional
        * If True, field names are case-sensitive.
        * If False or 'upper', field names are converted to upper case.
        * If 'lower', field names are converted to lower case.

        The default value is True.
    replace_space: '_', optional
        Character(s) used in replacement of white spaces.

    Notes
    -----
    Calling an instance of `NameValidator` is the same as calling its method
    `validate`.

    Examples
    --------
    >>> validator = np.lib._iotools.NameValidator()
    >>> validator(['file', 'field2', 'with space', 'CaSe'])
    ['file_', 'field2', 'with_space', 'CaSe']

    >>> validator = np.lib._iotools.NameValidator(excludelist=['excl'],
                                                  deletechars='q',
                                                  case_sensitive='False')
    >>> validator(['excl', 'field2', 'no_q', 'with space', 'CaSe'])
    ['excl_', 'field2', 'no_', 'with_space', 'case']

    treturnRtprints~!@#$%^&*()-=+~\|]}[{';: /?.>,<R;cCs�|dkrg}n|j|j�||_|dkrF|j}nt|�}|jd�||_|dks�|tkr�d�|_	nN|t
ks�d|kr�d�|_	n'd|kr�d�|_	nd�|_	||_dS(Nt"cSs|S(N((tx((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR=3stucSs
|j�S(N(tupper(R`((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR=5stlcSs
|j�S(N(tlower(R`((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR=7scSs|S(N((R`((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR=9s(R+R2tdefaultexcludelisttexcludelisttdefaultdeletecharstsettaddtdeletecharsRtcase_converterRt
replace_space(R>RfRjtcase_sensitiveRltdelete((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRQ#s"		
	sf%icCs|dkr%|dkrdSg}nt|t�r@|g}n|dk	r�t|�}||kr�t|�dg||}q�||kr�|| }q�n|j}|j}|j}|j}g}	t	�}
d}x|D]}||�j
�}|r|jd|�}ndjg|D]}
|
|kr|
^q�}|dkr�||}x$||kr{|d7}||}qXW|d7}n||kr�|d7}n|
j
|d�}|dkr�|	j|d|�n
|	j|�|d|
|<q�Wt|	�S(s

        Validate a list of strings to use as field names for a structured array.

        Parameters
        ----------
        names : sequence of str
            Strings to be validated.
        defaultfmt : str, optional
            Default format string, used if validating a given string reduces its
            length to zero.
        nboutput : integer, optional
            Final number of validated names, used to expand or shrink the initial
            list of names.

        Returns
        -------
        validatednames : list of str
            The list of validated field names.

        Notes
        -----
        A `NameValidator` instance can be called directly, which is the same as
        calling `validate`. For examples, see `NameValidator`.

        Rit iR;s_%dN(R+RCt
basestringRURHRjRfRkRltdictR9treplacetjointgettappendttuple(R>R't
defaultfmttnbfieldstnbnamesRjRfRkRltvalidatednamestseentnbemptytitemtctcnt((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pytvalidate=sL						
.




cCs|j|d|d|�S(NRwRx(R�(R>R'RwRx((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRX�sN(
RYRZR[ReRhRgR+RQR�RX(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR\�s2FcCsH|j�}|td�kr"tS|td�kr8tStd��dS(s�
    Tries to transform a string supposed to represent a boolean to a boolean.

    Parameters
    ----------
    value : str
        The string that is transformed to a boolean.

    Returns
    -------
    boolval : bool
        The boolean representation of `value`.

    Raises
    ------
    ValueError
        If the string is not 'True' or 'False' (case independent)

    Examples
    --------
    >>> np.lib._iotools.str2bool('TRUE')
    True
    >>> np.lib._iotools.str2bool('false')
    False

    tTRUEtFALSEsInvalid booleanN(RbRRRR(tvalue((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pytstr2bool�stConverterErrorcBseZdZRS(sR
    Exception raised when an error occurs in a converter for string values.

    (RYRZR[(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��stConverterLockErrorcBseZdZRS(sR
    Exception raised when an attempt is made to upgrade a locked converter.

    (RYRZR[(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��stConversionWarningcBseZdZRS(s�
    Warning issued when a string converter has a problem.

    Notes
    -----
    In `genfromtxt` a `ConversionWarning` is issued if raising exceptions
    is explicitly suppressed with the "invalid_raise" keyword.

    (RYRZR[(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��s	tStringConvertercBseZdZejeefejedfej	e
ejfee
ejdfejeed�fgZee�\ZZZed��Zed��Zed��Zedd��Zddded�Zd	�Zd
�Zd�Zd�Z d
�Z!dded�ed�Z"RS(s�
    Factory class for function transforming a string into another object (int,
    float).

    After initialization, an instance can be called to transform a string
    into another object. If the string is recognized as representing a missing
    value, a default value is returned.

    Attributes
    ----------
    func : function
        Function used for the conversion.
    default : any
        Default value to return when the input corresponds to a missing value.
    type : type
        Type of the output.
    _status : int
        Integer representing the order of the conversion.
    _mapper : sequence of tuples
        Sequence of tuples (dtype, function, default value) to evaluate in
        order.
    _locked : bool
        Holds `locked` parameter.

    Parameters
    ----------
    dtype_or_func : {None, dtype, function}, optional
        If a `dtype`, specifies the input data type, used to define a basic
        function and a default value for missing data. For example, when
        `dtype` is float, the `func` attribute is set to `float` and the
        default value to `np.nan`.
        If a function, this function is used to convert a string to another
        object. In this case, it is recommended to give an associated default
        value as input.
    default : any, optional
        Value to return by default, that is, when the string to be converted
        is flagged as missing. If not given, `StringConverter` tries to supply
        a reasonable default value.
    missing_values : sequence of str, optional
        Sequence of strings indicating a missing value.
    locked : bool, optional
        Whether the StringConverter should be locked to prevent automatic
        upgrade or not. Default is False.

    i����ys???cCstj|�jS(s(Returns the dtype of the input variable.(R-tarraytdtype(tclstval((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt	_getdtype�scCstj|�jjS(s4Returns the type of the dtype of the input variable.(R-R�R�ttype(R�R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_getsubdtypescCs|jtjkr|S|jS(s9Returns dtype for datetime64 and type of dtype otherwise.(R�R-t
datetime64(R�R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_dtypeortypescCs&t|d�r8|jjd|j|�||f�dSt|d�r"t|dttf�r�x!|D]}|jjd|�qgWdS|dkr�dgt|�}n0t|�}|j	dgt|�t|��xEt
||�D]1\}}|jjd|j|�||f�q�WndS(s�
    Upgrade the mapper of a StringConverter by adding a new function and its
    corresponding default.

    The input function (or sequence of functions) and its associated default
    value (if any) is inserted in penultimate position of the mapper.
    The corresponding type is estimated from the dtype of the default value.

    Parameters
    ----------
    func : var
        Function, or sequence of functions

    Examples
    --------
    >>> import dateutil.parser
    >>> import datetime
    >>> dateparser = datetustil.parser.parse
    >>> defaultdate = datetime.date(2000, 1, 1)
    >>> StringConverter.upgrade_mapper(dateparser, default=defaultdate)
        RXi����NRAi(R t_mappertinsertR�RCRvRHR+RURuRI(R�tfunctdefaultR;tfcttdft((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pytupgrade_mappers%
$cCst|t�rt|�}n$t|ttf�rBt|�}nt|�|_|dkr�t	|_
d|_|pxt|_
tjd�}n�yd|_
tj|�}Wn�tk
rGt|d�s�d}t|t|���n||_
|dkr5y|j
td��}Wq5tk
r1d}q5Xn|j|�}nXd}xft|j�D]U\}\}	}
}tj|j|	�r^|}|dkr�||_
n	||_
Pq^q^W|dkr�d}||_
n||_|j
dkr�|
|_
n|j
|jddkrjt|jtj�r7tj|_
qjt|jtj�r[tj|_
qjd�|_
n|dkr�ttd	�g�|_nIt|t�r�|jtd
��}ntt|�td	�g�|_|j|_ |j!|�|_t|_"||_#dS(NiRRXsNThe input argument `dtype` is neither a function or a dtype (got '%s' instead)t0i����icSstt|��S(N(RR(R`((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR=wsRt,($RCRRRHRvR
Rt_lockedR+R�R�t_statusRR�R-R�RR R�RR�t	enumerateR�t
issubdtypet
issubclasstuint64tint64Rhtmissing_valuesR	RRt_strict_callt_callingfunctionR�t_checkedt_initial_default(R>t
dtype_or_funcR�R�tlockedR�terrmsgR�ROtdeftypeR�tdefault_def((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRQ:sj			
	

%		"	cCs-y|j|�SWntk
r(|jSXdS(N(R�RR�(R>R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt_loose_call�s
cCsjy|j|�SWnRtk
re|j�|jkrR|jsKt|_n|jStd|��nXdS(NsCannot convert string '%s'(R�RR9R�R�RR�R�(R>R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��s
	cCs
|j|�S(N(R�(R>R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyRX�scCs�t|_y|j|�Wn�tk
r�|jrHd}t|��nt|j�}|j}||kr�d}t	|��n||dkr�|d7}n|j|\|_
|_}||_|jdk	r�|j|_n	||_|j|�nXdS(s�
        Try to find the best converter for a given string, and return the result.

        The supplied string `value` is converted by testing different
        converters in order. First the `func` method of the `StringConverter`
        instance is tried, if this fails other available converters are tried.
        The order in which these other converters are tried is determined by the
        `_status` attribute of the instance.

        Parameters
        ----------
        value : str
            The string to convert.

        Returns
        -------
        out : any
            The result of converting `value` with the appropriate converter.

        s*Converter is locked and cannot be upgradeds*Could not find a valid conversion functioniN(RR�R�RR�R�RUR�R�R�R�R�R�R+R�tupgrade(R>R�R�t
_statusmaxR�R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��s(	
		
		cCst|_t|d�s$|f}n|j}yt||�Wn�tk
r|jrld}t|��nt|j	�}|j
}||kr�td��n||dkr�|d7}n|j	|\|_|_
}|jdk	r�|j|_n	||_||_
|j|�nXdS(NRAs*Converter is locked and cannot be upgradeds*Could not find a valid conversion functioni(RR�R R�tmapRR�R�RUR�R�R�R�R�R�R+R�titerupgrade(R>R�R�R�R�R�R�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��s,		
		
		RcCs
||_||_|dk	rE||_|j|j|��|_nWy||pZtd��}Wntt	fk
r�d}nX|j|j|��|_|dk	r�t
|�r�|jj|�qt
|d�rx!|D]}|jj|�q�Wqn	g|_dS(s/
        Set StringConverter attributes directly.

        Parameters
        ----------
        func : function
            Conversion function.
        default : any, optional
            Value to return by default, that is, when the string to be converted
            is flagged as missing. If not given, `StringConverter` tries to supply
            a reasonable default value.
        testing_value : str, optional
            A string representing a standard input value of the converter.
            This string is used to help defining a reasonable default value.
        missing_values : sequence of str, optional
            Sequence of strings indicating a missing value.
        locked : bool, optional
            Whether the StringConverter should be locked to prevent automatic
            upgrade or not. Default is False.

        Notes
        -----
        `update` takes the same parameters as the constructor of `StringConverter`,
        except that `func` does not accept a `dtype` whereas `dtype_or_func` in
        the constructor does.

        t1RAN(R�R�R+R�R�R�R�RRRRR�RiR (R>R�R�t
testing_valueR�R�ttesterR�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pytupdate�s"			

N(#RYRZR[tnxtbool_R�RtintegerRtfloatingRtnanRRtstring_R	RR�RIt_defaulttypet_defaultfunct_defaultfilltclassmethodR�R�R�R+R�RQR�R�RXR�R�R�(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyR��s*-'	J		
		-	sf%icKs�ytj|�}Wn�tk
r�t|�}t|�}|d
kr]dgt|�}n!t|t�r~|jd�}n||d|d|�}tjt	d|d|��}n<Xt|�}|d
k	rpt|�}t|t�r�|jd�}n|dkrRt
|jgt|��}||d|�}tjt||��}q�||d|d|�|_
n�|dkr�t|�}|j
t
d�t|�D��kr�|d	kr�|dg|d|�|_
q�||j
d|�|_
n|S(s.
    Convenience function to create a `np.dtype` object.

    The function processes the input `dtype` and matches it with the given
    names.

    Parameters
    ----------
    ndtype : var
        Definition of the dtype. Can be any string or dictionary
        recognized by the `np.dtype` function, or a sequence of types.
    names : str or sequence, optional
        Sequence of strings to use as field names for a structured dtype.
        For convenience, `names` can be a string of a comma-separated list of
        names.
    defaultfmt : str, optional
        Format string used to define missing names, such as ``"f%i"``
        (default) or ``"fields_%02i"``.
    validationargs : optional
        A series of optional arguments used to initialize a `NameValidator`.

    Examples
    --------
    >>> np.lib._iotools.easy_dtype(float)
    dtype('float64')
    >>> np.lib._iotools.easy_dtype("i4, f8")
    dtype([('f0', '<i4'), ('f1', '<f8')])
    >>> np.lib._iotools.easy_dtype("i4, f8", defaultfmt="field_%03i")
    dtype([('field_000', '<i4'), ('field_001', '<f8')])

    >>> np.lib._iotools.easy_dtype((int, float, float), names="a,b,c")
    dtype([('a', '<i8'), ('b', '<f8'), ('c', '<f8')])
    >>> np.lib._iotools.easy_dtype(float, names="a,b,c")
    dtype([('a', '<f8'), ('b', '<f8'), ('c', '<f8')])

    RR�RxRwtformatsR'icss|]}d|VqdS(sf%iN((t.0RO((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pys	<genexpr>Yssf%iN(R-R�RR\RUR+RCRpRRRqRvR�RIR'RT(R(R'RwtvalidationargsR�RxtnbtypesR�((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt
easy_dtypes:%
"%(*R[t
__docformat__tsystnumpyR-tnumpy.core.numerictcoretnumericR�t__builtin__RRRRRRRRtnumpy.compatRR	R
tversion_infoRRRRRR&R*R1R8R\R�t	ExceptionR�R�tUserWarningR�R�R+R�(((s8/usr/lib64/python2.7/site-packages/numpy/lib/_iotools.pyt<module>s2:		
	"	,[�	$�N