Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/nose/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/nose/__pycache__/util.cpython-35.pyc



�^�]nO�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZejd�Zejd�ZeefZdZye�eZWn;ek
ryddlmZWnek
r
YnXYnXded	d
ddd
d�Zdd�Zdd�Zddd�Zdd�Zdd�Zdd�Z dd�Z!e
Z"dd�Z#dd �Z$dd!d"�Z%d#d$�Z&d%d&�Z'dd'd(�Z(d)d*�Z)d+e)_*d,d-�Z+d+e+_*d.d/�Z,d0d1�Z-d2d3�Z.d4d5�Z/Gd6d7�d7e0�Z1d8d9�Z2d:d;�Z3d<d=d>�Z4d?d@�Z5e6dAkr�ddl7Z7e7j8�dS)Bz7Utility functions and classes used by nose internally.
�N)�	ClassType�TypeType�isgenerator�ismethod�nosez^[A-Za-z_][A-Za-z0-9_.]*$zE(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)|(?:.*\$py\.class)|(?:__pycache__))�Set�z|-- z|   z`-- z    cCs"djt||||||��S)N�
)�join�_ls_tree_lines)�dir_path�skip_pattern�indent�
branch_indent�last_indent�last_branch_indent�r�:/opt/alt/python35/lib/python3.5/site-packages/nose/util.py�ls_treesrc#s��dkrtj��g}tj��}|j�gg}}	xa|D]Y}
tj�|
�rfqKtjjtjj�|
��r�|j	|
�qK|	j	|
�qKWt
tjdd�|	D�dd�|D���}������fdd�}xC|dd�D]1\}
}
x"||
|
���D]}|Vq.WqW|r||d	\}
}
x"||
|
���D]}|VqmWdS)
NrcSsg|]}|df�qS)Fr)�.0�namerrr�
<listcomp><s	z"_ls_tree_lines.<locals>.<listcomp>cSsg|]}|df�qS)Tr)rrrrrr=s	c3s{|s||Vnetjj�|�}tjj|�sw||Vt|������}x|D]}||VqdWdS)N)�os�pathr
�islinkr)r�is_dir�indZ
branch_indrZsubtree�x)rrrrrr
rr�ls_entry>s		
z _ls_tree_lines.<locals>.ls_entry����r )
r�getcwd�listdir�sort�re�matchr�isdirr
�append�list�	itertools�chain)rr
rrrr�lines�names�dirs�nondirsr�entriesrr�liner)rrrrrr
rr)s,


!!
rcCsltjj|�sEtjjtjjtjjtj�|���}|dksdtjj|�rhdS|S)zUReturn absolute, normalized path to directory, if it exists; None
    otherwise.
    N)rr�isabs�normpath�abspathr
r!r&)rrrr�absdirSs$r4cCs�|}|dkrtj�}t|t�s<t|t�rpx-|D]%}t||�}|dk	rC|SqCWdStjj|�s�tjjtjj	tjj
||���}|dks�tjj|�r|tj�krtjjtjj	tjj
tj�|���}|dks2tjj|�r6dStjj|�rvtjj
|d�}tjj
|�r�|Sntjj
|�r�|SdS)z�Return absolute, normalized path to file (optionally in directory
    where), or None if the file can't be found either in where or the current
    working directory.
    Nz__init__.py)rr!�
isinstancer(�tuple�absfilerr1r2r3r
�existsr&�isfile)r�where�origZ
maybe_pathZ	maybe_abs�initrrrr7_s0
-$r7cCs%x|D]}||�rdSqWdS)NTFr)�	predicate�iterable�itemrrr�anyp�s
r@cCsQtjj|�pPtjj|�pP|jd�pPtjtjj|�d�S)z�A name is file-like if it is a path that exists, or it has a
    directory part, or it ends in .py, or it isn't a legal python
    identifier.
    z.pyr)rrr8�dirname�endswith�ident_rer%�splitext)rrrr�	file_like�srEcCsKy|jSWn9tk
rFy|jjSWntk
rAdSYnXYnXdS)zrGet the line number of a function. First looks for
    compat_co_firstlineno, then func_code.co_first_lineno.
    rNr )Zcompat_co_firstlineno�AttributeError�__code__�co_firstlineno)�funcrrr�func_lineno�s

rJcCs%t|�}|tkp$t|t�S)z|Is obj a class? Inspect's isclass is too liberal and returns True
    for objects that can't be subclasses of anything.
    )�type�class_types�
issubclass)�objZobj_typerrr�isclass�srOcCs�tjj|�r�tjj|�}tj|�r�x3dD]+}tjjtjj||��r:dSq:Wtj	j
d�r�tjjtjj|d��r�dSdS)	z�
    Is this path a package directory?

    >>> ispackage('nose')
    True
    >>> ispackage('unit_tests')
    False
    >>> ispackage('nose/plugins')
    True
    >>> ispackage('nose/loader.py')
    False
    �__init__.py�__init__.pyc�__init__.pyoT�javaz__init__$py.classF)rPrQrR)rrr&�basenamerCr%r9r
�sys�platform�
startswith)r�endr<rrr�	ispackage�s

!!rYcCst|�tkS)a
    Is this a property?

    >>> class Foo:
    ...     def got(self):
    ...         return 2
    ...     def get(self):
    ...         return 1
    ...     get = property(get)

    >>> isproperty(Foo.got)
    False
    >>> isproperty(Foo.get)
    True
    )rK�property)rNrrr�
isproperty�sr[cCs�|dkrtj�}tjj|tjj|jd���}tjj|d�r\|S|d}tjj|�r||SdS)z�Find the python source file for a package, relative to a
    particular directory (defaults to current working directory if not
    given).
    N�.z/__init__.pyz.py)rr!rr
�sep�splitr8)�packageZ
relativeTor�filenamerrr�getfilename�s*
racCst|�}tjj|�s.|jd�r?t|�r?dStjjtjj|��\}}|dkrxg}n	|g}tjjtjj|�d�\}}xN|r�ttjj	||��r�|j
|�nPtjj|�\}}q�W|j�dj	|�S)a�
    Find the full dotted package name for a given python source file
    name. Returns None if the file is not a python source file.

    >>> getpackage('foo.py')
    'foo'
    >>> getpackage('biff/baf.py')
    'baf'
    >>> getpackage('nose/util.py')
    'nose.util'

    Works for directories too.

    >>> getpackage('nose')
    'nose'
    >>> getpackage('nose/plugins')
    'nose.plugins'

    And __init__ files stuck onto directories

    >>> getpackage('nose/plugins/__init__.py')
    'nose.plugins'

    Absolute paths also work.

    >>> path = os.path.abspath(os.path.join('nose', 'plugins'))
    >>> getpackage(path)
    'nose.plugins'
    z.pyN�__init__rr\)�srcrrr&rBrYrDrTr^r
r'�reverse)r`Zsrc_file�base�extZ	mod_partsr�partrrr�
getpackage�s/$		(	
rhcCsgt|�d}d|d}dd||d|f}dt|�}|dkrc|d|}|S)z�Draw a 70-char-wide divider, with label in the middle.

    >>> ln('hello there')
    '---------------------------- hello there -----------------------------'
    ��Fz%s %s %s�-r)�len)�labelZ	label_len�chunk�out�padrrr�lnsrqcCs�|jd�}|dd�}|dkr�xY|r�y*tjd|�tdj|��}PWq.tk
r�|d=|s~�Yq.Xq.W|dd�}|}tjd||||�x|D]}t||�}q�W|S)a8Resolve a dotted name to a module and its parts. This is stolen
    wholesale from unittest.TestLoader.loadTestByName.

    >>> resolve_name('nose.util') #doctest: +ELLIPSIS
    <module 'nose.util' from...>
    >>> resolve_name('nose.util.resolve_name') #doctest: +ELLIPSIS
    <function resolve_name at...>
    r\Nz
__import__ %srzresolve: %s, %s, %s, %sr )r^�log�debug�
__import__r
�ImportError�getattr)r�module�parts�
parts_copyrNrgrrr�resolve_name)s$		

rzcCs�tjj}|}d}d|krPt|�rC||�ddfSd|dfStjj|�\}}|sy2|jd�\}}t|�r�|d}}Wqhtk
r|jd�}t|d�dkr�dj|dd��|d}}ntd|f��YqhXnQ|s&|}nBd|krJ|jd�\}}n|}tjj||g�}|r�t|�r�||�d|fSd||fSn
dd|fSdS)a3Split a test name into a 3-tuple containing file, module, and callable
    names, any of which (but not all) may be blank.

    Test names are in the form:

    file_or_module:callable

    Either side of the : may be dotted. To change the splitting behavior, you
    can alter nose.util.split_test_re.
    N�:rrzaTest name '%s' could not be parsed. Please format test names as path:callable or module:callable.r r )	rrr2rEr^�
ValueErrorrlr
r])�testZnormZfile_or_mod�fn�head�tailrxZ	file_partrrr�split_test_nameFs<

'	r�FcCs~t|d�r|j�St|�}d}}}|tjkryt|dd�}t|dd�}t|�||fS|tjks�t|t�s�|tkr#t|dd�}|dk	r�t	j
|}t|dd�}|dk	r�tjj
|�}t|dd�}t|�||fS|tjkrpt|jj�}t|d�|dd|d	|jffSt|tj�r6t|d
�s�t|d�r�yt|j�SWntk
r�t|j�SYnXt|j�}y
|j}Wntk
r|j}YnXt|d�|dd|d	|ffSt|d�rd|jjdkrdt|j�Std||f��dS)zfFind the test address for a test, which may be a module, filename,
    class, method or function.
    �addressN�__file__�__name__�
__module__rrz%s.%sri�_FunctionTestCase__testFunc�	_testFunc�	__class__�__builtin__�builtinszI don't know what %s is (%s))r�r�)�hasattrr�rK�types�
ModuleTypervrc�FunctionTyperMrU�modulesrrr3�
MethodType�test_address�__self__r�r�r5�unittest�TestCaser�rFr�Z_TestCase__testMethodName�_testMethodNamer��	TypeError)r}�t�filerw�call�mZcls_adr�method_namerrrr��sN
*




r�cCs=x6|D].}t||d�}|dk	rt|�tjkrt|tj�rptj|�\}}}}nt|d�r�tj	|�r�|j
}y,tj|�\}}}}|jd�Wn(tk
r�td||f��YnXt
|�rtjd|||�||�Stjd||�|�SqWdS)z�Given a list of possible method names, try to run them with the
    provided object. Keep going until something works. Used to run
    setup/teardown methods for module, package, and function tests.
    N�__call__rzaAttribute %s of %r is not a python function. Only functions or callables may be used as fixtures.zcall fixture %s.%s(%s)zcall fixture %s.%s)rvrKr�r�r5r��inspect�
getargspecr�rr��popr�rlrrrs)rNr,rrI�args�varargs�varkw�defaultsrrr�try_run�s&
	

r�cCs�|dkr|Stjjd�rN|jd�rNdj|dd
�df�Stjj|�\}}|dkr�dj|df�S|S)z�Find the python source file for a .pyc, .pyo or $py.class file on
    jython. Returns the filename provided if it is not a python source
    file.
    NrSz	$py.classr\�	�py�.pyc�.pyo�.pyi����)r�r�r�)rUrVrWrBr
rrrD)r`rerfrrrrc�s!rccs�fdd�}|S)a�Sort key function factory that puts items that match a
    regular expression last.

    >>> from nose.config import Config
    >>> from nose.pyversion import sort_list
    >>> c = Config()
    >>> regex = c.testMatch
    >>> entries = ['.', '..', 'a_test', 'src', 'lib', 'test', 'foo.py']
    >>> sort_list(entries, regex_last_key(regex))
    >>> entries
    ['.', '..', 'foo.py', 'lib', 'src', 'a_test', 'test']
    cs#�j|�rd|fSd|fS)Nrr)�search)rN)�regexrr�k�s
zregex_last_key.<locals>.kr)r�r�r)r�r�regex_last_key�s
r�cCsq|dkrdSy|jg�|SWntk
r9YnXytjd|�SWntk
rlt|�SYnXdS)awConvert a value that may be a list or a (possibly comma-separated)
    string into a list. The exception: None is returned as None, not [None].

    >>> tolist(["one", "two"])
    ['one', 'two']
    >>> tolist("hello")
    ['hello']
    >>> tolist("separate,values, with, commas,  spaces , are    ,ok")
    ['separate', 'values', 'with', 'commas', 'spaces', 'are', 'ok']
    Nz\s*,\s*)�extendrFr$r^r�r()�valrrr�tolist�s


r�cs�eZdZdZ�fdd�Z�fdd�Z�fdd�Zdd	�Z�fd
d�Z�fdd
�Z	dd�Z
dd�Zd�fdd�Z�fdd�Z
dd�Z�S)�odictzvSimple ordered dict implementation, based on:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
    cs&g|_tt|�j||�dS)N)�_keys�superr�rb)�self�arg�kw)r�rrrbs	zodict.__init__cs*tt|�j|�|jj|�dS)N)r�r��__delitem__r��remove)r��key)r�rrr�!szodict.__delitem__cs<tt|�j||�||jkr8|jj|�dS)N)r�r��__setitem__r�r')r�r�r?)r�rrr�%szodict.__setitem__cCs*ddjdd�t|j��D��S)Nz{%s}z, cSs&g|]\}}d||f�qS)z%r: %rr)rr��vrrrr+s	z!odict.__str__.<locals>.<listcomp>)r
r(�items)r�rrr�__str__*sz
odict.__str__cs tt|�j�g|_dS)N)r�r��clearr�)r�)r�rrr�-szodict.clearcs/tt|�j�}|jdd�|_|S)N)r�r��copyr�)r��d)r�rrr�1sz
odict.copycCs"tt|jt|j����S)N)r(�zipr��values)r�rrrr�6szodict.itemscCs|jdd�S)N)r�)r�rrr�keys9sz
odict.keysNcs>tt|�j||�}||jkr:|jj|�|S)N)r�r��
setdefaultr�r')r�r��failobjr?)r�rrr�<szodict.setdefaultcsVtt|�j|�x9t|j��D]%}||jkr)|jj|�q)WdS)N)r�r��updater(r�r�r')r��dictr�)r�rrr�Bszodict.updatecCstt|j|j��S)N)r(�map�getr�)r�rrrr�Hszodict.values)r�r��__qualname__�__doc__rbr�r�r�r�r�r�r�r�r�r�rr)r�rr�sr�csbddlm}t��r1�fdd�}n�fdd�}|��|�}||_|S)a�
    Make a function imported from module A appear as if it is located
    in module B.

    >>> from pprint import pprint
    >>> pprint.__module__
    'pprint'
    >>> pp = transplant_func(pprint, __name__)
    >>> pp.__module__
    'nose.util'

    The original function is not modified.

    >>> pprint.__module__
    'pprint'

    Calling the transplanted function calls the original.

    >>> pp([1, 2])
    [1, 2]
    >>> pprint([1,2])
    [1, 2]

    r)�make_decoratorc?s#x�||�D]}|VqWdS)Nr)r�r�r�)rIrr�newfuncgsz transplant_func.<locals>.newfunccs
�||�S)Nr)r�r�)rIrrr�ks)Z
nose.toolsr�rr�)rIrwr�r�r)rIr�transplant_funcLs	r�cCs/Gdd�d|�}||_|j|_|S)aB
    Make a class appear to reside in `module`, rather than the module in which
    it is actually defined.

    >>> from nose.failure import Failure
    >>> Failure.__module__
    'nose.failure'
    >>> Nf = transplant_class(Failure, __name__)
    >>> Nf.__module__
    'nose.util'
    >>> Nf.__name__
    'Failure'

    c@seZdZdS)ztransplant_class.<locals>.CN)r�r�r�rrrr�C�sr�)r�r�)�clsrwr�rrr�transplant_classss	r�zutf-8csiyt|�SWnTtk
rdt|t�rMdj�fdd�|D��St|�j��SYnXdS)N� csg|]}t|���qSr)�safe_str)rr�)�encodingrrr�s	zsafe_str.<locals>.<listcomp>)�str�UnicodeEncodeErrorr5�	Exceptionr
�encode)r�r�r)r�rr��s
r�cCsGtjj|�sdStj|�}t|jtjtjBtjB@�S)NF)	rrr8�stat�bool�st_mode�S_IXUSR�S_IXGRP�S_IXOTH)r��strrr�
is_executable�sr��__main__)9r�r�r)�loggingr�rr$rUr�r�Znose.pyversionrrrr�	getLoggerrr�compilerCrLr
�set�	NameErrorZsetsrrurrr4r7r@rErJrOZis_generatorrYr[rarhrqrzr�Z__test__r�r�rcr�r�r�r�r�r�r�r�r��doctest�testmodrrrr�<module>sp"



*!
	1<	1	!4'