�9�c@sCdZddlZddlZddlZddlZddlZddlZddlZddlZddl m
Z
mZmZej
d�Zejd�Ze
efZdZye�eZWn9ek
r�yddlmZWq�k
r�q�Xded d
ddd
�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Z eZ!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�Z.d �Z/d!e0fd"��YZ1d#�Z2d$�Z3d%d&�Z4e5d'kr?ddl6Z6e6j7�ndS((s7Utility functions and classes used by nose internally.
i�N(t ClassTypetTypeTypetisgeneratortnoses^[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_pathtskip_patterntindentt
branch_indenttlast_indenttlast_branch_indent((s-/sys/lib/python2.7/site-packages/nose/util.pytls_treesc#s��dkrtj��ng}tj��}|j�gg}} xd|D]\}
tj�|
�rlqNntjjtjj�|
��r�|j |
�qN| j |
�qNWt
tjg| 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(RRR
R
RR (s-/sys/lib/python2.7/site-packages/nose/util.pytls_entry=s
i�(RtgetcwdtlistdirtsorttretmatchRtisdirRtappendtlistt itertoolstchaintFalsetTrue(RR R
RRR
tlinestnamestdirstnondirsRtentriesRRtline((RRR
R
RR s-/sys/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-/sys/lib/python2.7/site-packages/nose/util.pytabsdirRs$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-/sys/lib/python2.7/site-packages/nose/util.pyR2^s0
0$cCs%x|D]}||�rtSqWtS(N(R$R#(t predicatetiterabletitem((s-/sys/lib/python2.7/site-packages/nose/util.pytanyps
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(RRR3tdirnametendswithtident_reRtsplitext(R((s-/sys/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-/sys/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-/sys/lib/python2.7/site-packages/nose/util.pytisclass�scCs�tjj|�r�tjj|�}tj|�r�x3dD]+}tjjtjj||��r:tSq:Wt j
jd�r�tjjtjj|d��r�tSq�ntS(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(
RRRtbasenameR@RR4RR$tsystplatformt
startswithR#(RtendR9((s-/sys/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
(RItproperty(RL((s-/sys/lib/python2.7/site-packages/nose/util.pyt
isproperty�scCs�|dkrtj�}ntjj|tjj|jd���}d}x.|D]&}||}tjj|�rR|SqRWdS(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(s/__init__.pys.py(R.RRRRtseptsplitR3(tpackaget
relativeToRtsuffixestsuffixtfilename((s-/sys/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�tjj
||��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__iRXN(
tsrcRRRR?RUR.RARPRZRRtreverse(R_tsrc_filetbasetextt mod_partsRtpart((s-/sys/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-/sys/lib/python2.7/site-packages/nose/util.pytlnscCs�|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...>
RXs
__import__ %si�isresolve: %s, %s, %s, %sN(RZR.tlogtdebugt
__import__RtImportErrortgetattr(Rtmoduletpartst
parts_copyRLRh((s-/sys/lib/python2.7/site-packages/nose/util.pytresolve_name(s$
cCs�tjj}|}d}d|krSt|�rC||�ddfSd|dfSntjj|�\}}|sy5|jd�\}}t|�r�|d}}nWq`tk
r|jd�}t|d�dkr�j|d �|d}}qtd��q`XnQ|s|}nBd|krB|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.RBRZt
ValueErrorRkRRY(ttesttnormtfile_or_modtfntheadttailRxt file_part((s-/sys/lib/python2.7/site-packages/nose/util.pytsplit_test_nameEs:
! 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�RIR.ttypest
ModuleTypeRvRbtFunctionTypeRKRRQtmodulesRRR-t
MethodTypettest_addresstim_classR�R0tunittesttTestCaseR�RDR�R�t_TestCase__testMethodNamet_testMethodNameR�t TypeError(R}tttfileRwtcalltmtcls_adrtmethod_name((s-/sys/lib/python2.7/site-packages/nose/util.pyR��sN
-
cCs5x.|D]&}t||d�}|dk rt|�tjkrytj|�\}}}}Wn�tk
r�t|d�r�|j }ny,tj|�\}}}}|j
d�Wq�tk
r�td||f��q�nXt|�rtj
d|||�||�Sntj
d||�|�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(RvR.RIR�R�tinspectt
getargspecR�R�R�tpopRkRrRs(RLR&RRGtargstvarargstvarkwtdefaults((s-/sys/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.
ROs $py.classRXi�tpys.pycs.pyos.pyN(s.pycs.pyos.py( R.RQRRRSR?RRRRA(R_ReRf((s-/sys/lib/python2.7/site-packages/nose/util.pyRb�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(RL(tregex(s-/sys/lib/python2.7/site-packages/nose/util.pytk�s
((R�R�((R�s-/sys/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.textendRDRRZR�R (tval((s-/sys/lib/python2.7/site-packages/nose/util.pyttolist�s
todictcBsteZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
dd �Zd
�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�Ra(tselftargtkw((s-/sys/lib/python2.7/site-packages/nose/util.pyRas cCs*tt|�j|�|jj|�dS(N(R�R�t__delitem__R�tremove(R�tkey((s-/sys/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-/sys/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-/sys/lib/python2.7/site-packages/nose/util.pyt__str__(scCs tt|�j�g|_dS(N(R�R�tclearR�(R�((s-/sys/lib/python2.7/site-packages/nose/util.pyR�+scCs&tt|�j�}|j|_|S(N(R�R�tcopyR�(R�td((s-/sys/lib/python2.7/site-packages/nose/util.pyR�/s
cCst|j|j��S(N(tzipR�tvalues(R�((s-/sys/lib/python2.7/site-packages/nose/util.pyR�4scCs|jS(N(R�(R�((s-/sys/lib/python2.7/site-packages/nose/util.pytkeys7scCsAtt|�j||�}||jkr=|jj|�n|S(N(R�R�t
setdefaultR�R(R�R�tfailobjR<((s-/sys/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-/sys/lib/python2.7/site-packages/nose/util.pyR�@scCst|j|j�S(N(tmaptgetR�(R�((s-/sys/lib/python2.7/site-packages/nose/util.pyR�FsN(R�R�t__doc__RaR�R�R�R�R�R�R�R.R�R�R�(((s-/sys/lib/python2.7/site-packages/nose/util.pyR�s cs>ddlm}�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_decoratorcs
�||�S(N((R�R�(RG(s-/sys/lib/python2.7/site-packages/nose/util.pytnewfuncds(t
nose.toolsR�R�(RGRwR�R�((RGs-/sys/lib/python2.7/site-packages/nose/util.pyttransplant_funcJs
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-/sys/lib/python2.7/site-packages/nose/util.pyR�{s(R�R�(tclsRwR�((s-/sys/lib/python2.7/site-packages/nose/util.pyttransplant_classls sutf-8cCsnyt|�SWnYtk
rit|t�rVdjg|D]}t||�^q:�St|�j|�SXdS(Nt (tstrtUnicodeEncodeErrorR0t ExceptionRtsafe_strtunicodetencode(R�tencodingR�((s-/sys/lib/python2.7/site-packages/nose/util.pyR��s
t__main__(8R�R�R!tloggingRRRQR�R�tnose.pyversionRRRt getLoggerRrtcompileR@RJR tsett NameErrortsetsRRuRRR/R.R2R=RBRHRNtis_generatorRURWR`RiRqRzR�R#t__test__R�R�RbR�R�R�R�R�R�R�R�tdoctestttestmod(((s-/sys/lib/python2.7/site-packages/nose/util.pyt<module>sl
* !
1 < 1 4 "
|