Current File : //usr/lib/python2.7/site-packages/nose/util.pyc
�
d�Uc@s^dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZejd�Zejd�ZeefZdZye�eZWn9ek
ryddlmZWqek
rqXnXded	d
ddd
�Zd�Zd�Zdd�Zd�Zd�Z d�Z!d�Z"e
Z#d�Z$d�Z%dd�Z&d�Z'd�Z(dd�Z)d�Z*e+e*_,d�Z-e+e-_,d�Z.d�Z/d�Z0d �Z1d!e2fd"��YZ3d#�Z4d$�Z5d%d&�Z6d'�Z7e8d(krZddl9Z9e9j:�ndS()s7Utility functions and classes used by nose internally.
i����N(t	ClassTypetTypeTypetisgeneratortismethodtnoses^[A-Za-z_][A-Za-z0-9_.]*$sE(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)|(?:.*\$py\.class)|(?:__pycache__)(tSetts|-- s|   s`-- s    cCs"djt||||||��S(Ns
(tjoint_ls_tree_lines(tdir_pathtskip_patterntindentt
branch_indenttlast_indenttlast_branch_indent((s-/usr/lib/python2.7/site-packages/nose/util.pytls_treesc#s��dkrtj��ng}tj��}|j�gg}}	xd|D]\}
tj�|
�rlqNntjjtjj�|
��r�|j	|
�qN|	j	|
�qNWt
tjg|	D]}
|
t
f^q�g|D]}
|
tf^q���}������fd�}x=|d D]1\}
}
x"||
|
���D]}|VqCWq!W|r�|d\}
}
x%||
|
���D]}|Vq�WndS(NRc3s~|s||Vnhtjj�|�}tjj|�sz||Vt|������}x|D]}||VqdWndS(N(tostpathRtislinkR(tnametis_dirtindt
branch_indRtsubtreetx(RR	RRR
R
(s-/usr/lib/python2.7/site-packages/nose/util.pytls_entry>s		
i����(RtgetcwdtlistdirtsorttretmatchRtisdirRtappendtlistt	itertoolstchaintFalsetTrue(R	R
RRR
RtlinestnamestdirstnondirsRtentriesRRtline((RR	RRR
R
s-/usr/lib/python2.7/site-packages/nose/util.pyR)s,


!%%
cCsotjj|�sHtjjtjjtjjtj�|���}n|dksgtjj|�rkdS|S(sUReturn absolute, normalized path to directory, if it exists; None
    otherwise.
    N(	RRtisabstnormpathtabspathRRtNoneR(R((s-/usr/lib/python2.7/site-packages/nose/util.pytabsdirSs$cCs�|}|dkr!tj�}nt|t�s?t|t�rsx-|D]%}t||�}|dk	rF|SqFWdStjj|�s�tjj	tjj
tjj||���}n|dks�tjj|�r|tj�krtjj	tjj
tjjtj�|���}qn|dks>tjj|�rBdStjj
|�r�tjj|d�}tjj|�r�|Sntjj|�r�|SdS(s�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.
    s__init__.pyN(R/RRt
isinstanceR!ttupletabsfileRR,R-R.RtexistsRtisfile(Rtwheretorigt
maybe_patht	maybe_abstinit((s-/usr/lib/python2.7/site-packages/nose/util.pyR3_s0
0$cCs%x|D]}||�rtSqWtS(N(R%R$(t	predicatetiterabletitem((s-/usr/lib/python2.7/site-packages/nose/util.pytanyp�s
cCsQtjj|�pPtjj|�pP|jd�pPtjtjj|�d�S(s�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.
    s.pyi(RRR4tdirnametendswithtident_reRtsplitext(R((s-/usr/lib/python2.7/site-packages/nose/util.pyt	file_like�scCsFy|jSWn4tk
rAy|jjSWqBtk
r=dSXnXdS(srGet the line number of a function. First looks for
    compat_co_firstlineno, then func_code.co_first_lineno.
    i����N(tcompat_co_firstlinenotAttributeErrort	func_codetco_firstlineno(tfunc((s-/usr/lib/python2.7/site-packages/nose/util.pytfunc_lineno�s

cCs%t|�}|tkp$t|t�S(s|Is obj a class? Inspect's isclass is too liberal and returns True
    for objects that can't be subclasses of anything.
    (ttypetclass_typest
issubclass(tobjtobj_type((s-/usr/lib/python2.7/site-packages/nose/util.pytisclass�scCs�tjj|�r�tjj|�}tj|�r�x3dD]+}tjjtjj||��r:tSq:Wt	j
jd�r�tjjtjj|d��r�tSq�ntS(s�
    Is this path a package directory?

    >>> ispackage('nose')
    True
    >>> ispackage('unit_tests')
    False
    >>> ispackage('nose/plugins')
    True
    >>> ispackage('nose/loader.py')
    False
    s__init__.pys__init__.pycs__init__.pyotjavas__init__$py.class(s__init__.pys__init__.pycs__init__.pyo(
RRRtbasenameRARR5RR%tsystplatformt
startswithR$(RtendR:((s-/usr/lib/python2.7/site-packages/nose/util.pyt	ispackage�s

!!
cCst|�tkS(s
    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
    (RJtproperty(RM((s-/usr/lib/python2.7/site-packages/nose/util.pyt
isproperty�scCs�|dkrtj�}ntjj|tjj|jd���}tjj|d�r_|S|d}tjj|�r|SdS(s�Find the python source file for a package, relative to a
    particular directory (defaults to current working directory if not
    given).
    t.s/__init__.pys.pyN(R/RRRRtseptsplitR4(tpackaget
relativeToRtfilename((s-/usr/lib/python2.7/site-packages/nose/util.pytgetfilename�s*
cCst|�}tjj|�s.|jd�r?t|�r?dStjjtjj|��\}}|dkrxg}n	|g}tjj	tjj	|�d�\}}xN|r�ttjj
||��r�|j|�nPtjj	|�\}}q�W|j�dj
|�S(s�
    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'
    s.pyt__init__iRYN(
tsrcRRRR@RVR/RBRQR[RR treverse(R^tsrc_filetbasetextt	mod_partsRtpart((s-/usr/lib/python2.7/site-packages/nose/util.pyt
getpackage�s/$		(	
cCsjt|�d}d|d}dd||d|f}dt|�}|dkrf|d|}n|S(s�Draw a 70-char-wide divider, with label in the middle.

    >>> ln('hello there')
    '---------------------------- hello there -----------------------------'
    iiFs%s %s %st-i(tlen(tlabelt	label_lentchunktouttpad((s-/usr/lib/python2.7/site-packages/nose/util.pytlnscCs�|jd�}|}|dkr�x[|ry*tjd|�tdj|��}PWq%tk
r{|d=|s|�q|q%Xq%W|d}n|}tjd||||�x|D]}t||�}q�W|S(s8Resolve 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...>
    RYs
__import__ %si����isresolve: %s, %s, %s, %sN(R[R/tlogtdebugt
__import__RtImportErrortgetattr(Rtmoduletpartst
parts_copyRMRg((s-/usr/lib/python2.7/site-packages/nose/util.pytresolve_name)s$		


cCs�tjj}|}d}d|krSt|�rC||�ddfSd|dfSntjj|�\}}|sy5|jd�\}}t|�r�|d}}nWqgtk
r|jd�}t|d�dkr�dj|d �|d}}qtd|f��qgXnQ|s%|}nBd|krI|jd�\}}n|}tj	j||g�}|r�t|�r�||�d|fSd||fSn
dd|fSdS(s3Split 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.
    t:iii����saTest name '%s' could not be parsed. Please format test names as path:callable or module:callable.N(
RRR-R/RCR[t
ValueErrorRjRRZ(ttesttnormtfile_or_modtfntheadttailRwt	file_part((s-/usr/lib/python2.7/site-packages/nose/util.pytsplit_test_nameFs<
!	cCs�t|d�r|j�St|�}d}}}|tjkryt|dd�}t|dd�}t|�||fS|tjks�t	|t�s�|tj
kr,t|dd�}|dk	rtj|}t|dd�}|dk	rt
jj|�}qnt|dd�}t|�||fS|tjkrvt|j�}t|d�|dd|d|jffSt|tj�r:t|d	�s�t|d
�r�yt|j�SWq�tk
r�t|j�SXnt|j�}y
|j}Wntk
r|j}nXt|d�|dd|d|ffSt|d�rh|jjdkrht|j�Std||f��dS(sfFind the test address for a test, which may be a module, filename,
    class, method or function.
    taddresst__file__t__name__t
__module__iis%s.%sit_FunctionTestCase__testFunct	_testFunct	__class__t__builtin__tbuiltinssI don't know what %s is (%s)N(s__builtin__R�(thasattrR�RJR/ttypest
ModuleTypeRuRatFunctionTypeRLRRRtmodulesRRR.t
MethodTypettest_addresstim_classR�R1tunittesttTestCaseR�RER�R�t_TestCase__testMethodNamet_testMethodNameR�t	TypeError(R|tttfileRvtcalltmtcls_adrtmethod_name((s-/usr/lib/python2.7/site-packages/nose/util.pyR��sN
-





cCsBx;|D]3}t||d�}|dk	rt|�tjkr t|tj�rptj|�\}}}}n�t	|d�r�tj
|�r�|j}ny,tj|�\}}}}|jd�Wn't
k
r�t
d||f��nXt|�r tjd|||�||�Sntjd||�|�SqWdS(s�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.
    t__call__isaAttribute %s of %r is not a python function. Only functions or callables may be used as fixtures.scall fixture %s.%s(%s)scall fixture %s.%sN(RuR/RJR�R�R1R�tinspectt
getargspecR�RR�tpopR�RjRqRr(RMR'RRHtargstvarargstvarkwtdefaults((s-/usr/lib/python2.7/site-packages/nose/util.pyttry_run�s&


cCs�|d	kr|Stjjd�rH|jd�rHdj|d df�Stjj|�\}}|d
krdj|df�S|S(s�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.
    RPs	$py.classRYi����tpys.pycs.pyos.pyN(s.pycs.pyos.py(	R/RRRSRTR@RRRRB(R^RdRe((s-/usr/lib/python2.7/site-packages/nose/util.pyRa�s!cs�fd�}|S(s�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(Nii(tsearch(RM(tregex(s-/usr/lib/python2.7/site-packages/nose/util.pytk�s
((R�R�((R�s-/usr/lib/python2.7/site-packages/nose/util.pytregex_last_key�s
cCsl|dkrdSy|jg�|SWntk
r8nXytjd|�SWntk
rgt|�SXdS(swConvert 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']
    s\s*,\s*N(R/textendRERR[R�R!(tval((s-/usr/lib/python2.7/site-packages/nose/util.pyttolist�s


todictcBsteZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Z
d�ZRS(
svSimple ordered dict implementation, based on:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
    cOs&g|_tt|�j||�dS(N(t_keystsuperR�R`(tselftargtkw((s-/usr/lib/python2.7/site-packages/nose/util.pyR`s	cCs*tt|�j|�|jj|�dS(N(R�R�t__delitem__R�tremove(R�tkey((s-/usr/lib/python2.7/site-packages/nose/util.pyR�!scCs?tt|�j||�||jkr;|jj|�ndS(N(R�R�t__setitem__R�R (R�R�R=((s-/usr/lib/python2.7/site-packages/nose/util.pyR�%scCs:ddjg|j�D]\}}d||f^q�S(Ns{%s}s, s%r: %r(Rtitems(R�R�tv((s-/usr/lib/python2.7/site-packages/nose/util.pyt__str__*scCs tt|�j�g|_dS(N(R�R�tclearR�(R�((s-/usr/lib/python2.7/site-packages/nose/util.pyR�-scCs&tt|�j�}|j|_|S(N(R�R�tcopyR�(R�td((s-/usr/lib/python2.7/site-packages/nose/util.pyR�1s
cCst|j|j��S(N(tzipR�tvalues(R�((s-/usr/lib/python2.7/site-packages/nose/util.pyR�6scCs|jS(N(R�(R�((s-/usr/lib/python2.7/site-packages/nose/util.pytkeys9scCsAtt|�j||�}||jkr=|jj|�n|S(N(R�R�t
setdefaultR�R (R�R�tfailobjR=((s-/usr/lib/python2.7/site-packages/nose/util.pyR�<scCsStt|�j|�x6|j�D](}||jkr#|jj|�q#q#WdS(N(R�R�tupdateR�R�R (R�tdictR�((s-/usr/lib/python2.7/site-packages/nose/util.pyR�BscCst|j|j�S(N(tmaptgetR�(R�((s-/usr/lib/python2.7/site-packages/nose/util.pyR�HsN(R�R�t__doc__R`R�R�R�R�R�R�R�R/R�R�R�(((s-/usr/lib/python2.7/site-packages/nose/util.pyR�s									cs\ddlm}t��r.�fd�}n�fd�}|��|�}||_|S(s�
    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]

    i����(tmake_decoratorc?s#x�||�D]}|VqWdS(N((R�R�R�(RH(s-/usr/lib/python2.7/site-packages/nose/util.pytnewfuncgscs
�||�S(N((R�R�(RH(s-/usr/lib/python2.7/site-packages/nose/util.pyR�ks(t
nose.toolsR�RR�(RHRvR�R�((RHs-/usr/lib/python2.7/site-packages/nose/util.pyttransplant_funcLs	cCs/d|fd��Y}||_|j|_|S(sB
    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'

    tCcBseZRS((R�R�(((s-/usr/lib/python2.7/site-packages/nose/util.pyR��s(R�R�(tclsRvR�((s-/usr/lib/python2.7/site-packages/nose/util.pyttransplant_classss	sutf-8cCsnyt|�SWnYtk
rit|t�rVdjg|D]}t||�^q:�St|�j|�SXdS(Nt (tstrtUnicodeEncodeErrorR1t	ExceptionRtsafe_strtunicodetencode(R�tencodingR�((s-/usr/lib/python2.7/site-packages/nose/util.pyR��s
	 cCsGtjj|�stStj|�}t|jtjtjBtj	B@�S(N(
RRR4R$tstattbooltst_modetS_IXUSRtS_IXGRPtS_IXOTH(R�tst((s-/usr/lib/python2.7/site-packages/nose/util.pyt
is_executable�st__main__(;R�R�R"tloggingR�RRRRR�R�tnose.pyversionRRRRt	getLoggerRqtcompileRARKR
tsett	NameErrortsetsRRtRRR0R/R3R>RCRIROtis_generatorRVRXR_RhRpRyR�R$t__test__R�R�RaR�R�R�R�R�R�R�R�R�tdoctestttestmod(((s-/usr/lib/python2.7/site-packages/nose/util.pyt<module>sp"


	*	!			
					1		<		1		!			4	'