ó 4­¯\c @s¾dZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd l m Z dd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%dd lm&Z&ddlZd!„Zd"„Z'e rPe"j(d#ƒd$j)d#d%ƒZ*n e"d$Z*d&e+fd'„ƒYZ,e%j-eoe$d(ƒe%j-eo”e$d)ƒe%j-ed*ƒe%j-e'e#ƒ d+ƒd,e,e%j.fd-„ƒYƒƒƒƒZ/e%j-eoöe$d(ƒe%j-eo e$d)ƒe%j-e'e*ƒ d.ƒd/e,e%j.fd0„ƒYƒƒƒZ0e%j-e d1ƒd2e%j.fd3„ƒYƒZ1d4e%j.fd5„ƒYZ2e3d6krºdd7l4m5Z5e5e6ƒndS(8só Notes about unicode handling in psutil ====================================== In psutil these are the APIs returning or dealing with a string ('not tested' means they are not tested to deal with non-ASCII strings): * Process.cmdline() * Process.connections('unix') * Process.cwd() * Process.environ() * Process.exe() * Process.memory_maps() * Process.name() * Process.open_files() * Process.username() (not tested) * disk_io_counters() (not tested) * disk_partitions() (not tested) * disk_usage(str) * net_connections('unix') * net_if_addrs() (not tested) * net_if_stats() (not tested) * net_io_counters() (not tested) * sensors_fans() (not tested) * sensors_temperatures() (not tested) * users() (not tested) * WindowsService.binpath() (not tested) * WindowsService.description() (not tested) * WindowsService.display_name() (not tested) * WindowsService.name() (not tested) * WindowsService.status() (not tested) * WindowsService.username() (not tested) In here we create a unicode path with a funky non-ASCII name and (where possible) make psutil return it back (e.g. on name(), exe(), open_files(), etc.) and make sure that: * psutil never crashes with UnicodeDecodeError * the returned path matches For a detailed explanation of how psutil handles unicode see: - https://github.com/giampaolo/psutil/issues/1040 - http://psutil.readthedocs.io/#unicode iÿÿÿÿN(tclosing(tBSD(tMACOS(tOPENBSD(tPOSIX(tWINDOWS(tPY3(tu(tAPPVEYOR(tASCII_FS(tbind_unix_socket(tchdir(tcopyload_shared_lib(t create_exe(tget_test_subprocess(tHAS_CONNECTIONS_UNIX(t HAS_ENVIRON(tHAS_MEMORY_MAPS(tmock(tPYPY(t reap_children(t safe_mkdir(t safe_rmpath(tskip_on_access_denied(tTESTFILE_PREFIX(tTESTFN(tTESTFN_UNICODE(tTRAVIS(tunittest(tunix_socket_pathcCsCtr5yt|ƒSWq?tk r1tjƒq?Xn t|ƒSdS(N(Rt _safe_rmpatht WindowsErrort tracebackt print_exc(tpath((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR\s   cCs^tr tSzEy(t|ƒt|ƒtd|gƒWntk rItSXtSWdtƒXdS(s`Return True if both the fs and the subprocess module can deal with a unicode file name. tcmdN(RtTrueRR RtUnicodeEncodeErrortFalseR(tname((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pytsubprocess_supports_unicodeps   tutf8sfÀ€tsurrogateescapet_BaseFSAPIsTestscBs÷eZdZed„ƒZed„ƒZd„Zd„Zd„Z d„Z d„Z d„Z d„Z eje d ƒd „ƒZeje d ƒeje d ƒeƒd „ƒƒƒZd „Zeje dƒeje dƒd„ƒƒZRS(cCst|jƒt|jƒdS(N(Rt funky_nameR (tcls((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyt setUpClass’s cCstƒt|jƒdS(N(RRR,(R-((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyt tearDownClass—scCs tƒdS(N(R(tself((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttearDownœscCstdƒ‚dS(Nsmust be implemented in subclass(tNotImplementedError(R0((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pytexpect_exact_path_matchŸscCsitd|jgƒ}tj|jƒ}|jƒ}|j|tƒ|jƒre|j ||jƒndS(NR#( RR,tpsutiltProcesstpidtexetassertIsInstancetstrR3t assertEqual(R0tsubptpR7((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyt test_proc_exe¢s   cCsÌtd|jgƒ}trrtjddtjtjƒƒƒ.}tj |j ƒj ƒ}|j sit ‚WdQXntj |j ƒj ƒ}|j|tƒ|jƒrÈ|j|tjj|jƒƒndS(NR#s psutil._psplatform.cext.proc_exet side_effect(RR,RRtpatchR4t AccessDeniedtostgetpidR5R6R'tcalledtAssertionErrorR8R9R3R:R"tbasename(R0R;tmR'((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_proc_nameªs  cCs}td|jgƒ}tj|jƒ}|jƒ}x|D]}|j|tƒq:W|jƒry|j ||jgƒndS(NR#( RR,R4R5R6tcmdlineR8R9R3R:(R0R;R<RHtpart((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_proc_cmdlineºs   cCs‹|jd}|jt|ƒt|ƒt|ƒtjƒ}|jƒ}WdQX|j|jƒt ƒ|j ƒr‡|j ||ƒndS(Nt2( R,t addCleanupRRR R4R5tcwdR8R9R3R:(R0tdnameR<RM((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyt test_proc_cwdÃs     cCsÄtjƒ}t|jƒƒ}t|jdƒt|jƒƒ}WdQX||jƒj}|j|t ƒt r†| r†|j dƒS|j ƒrÀ|j tjj|ƒtjj|jƒƒndS(Ntrbsopen_files on BSD is broken(R4R5tsett open_filestopenR,tpopR"R8R9RtskipTestR3R:RAtnormcase(R0R<tstarttnewR"((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_proc_open_filesÎs    s POSIX onlyc CsËtjj|jƒ}td|ƒ¡}yt|ƒ}Wn,tk retrS‚qftj dƒ‚nXt |ƒMt j ƒj dƒd}|j|jtƒts»|j|j|ƒnWdQXWdQXdS(Ntsuffixs not supportedtunixi(RAR"RER,RR R%RRtSkipTestRR4R5t connectionsR8tladdrR9RR:(R0RZR'tsocktconn((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_proc_connectionsÜs  scan't list UNIX socketsc CsÙd„}tjj|jƒ}td|ƒ¦}yt|ƒ}Wn,tk rntr\‚qotj dƒ‚nXt |ƒRt j ddƒ}t sÉ||ƒ}|j|jtƒ|j|j|ƒnWdQXWdQXdS(NcSsCx0|D](}tjj|jƒjtƒr|SqWtdƒ‚dS(Nsconnection not found(RAR"RER^t startswithRt ValueError(tconsR`((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyt find_sockòs RZs not supportedtkindR[(RAR"RER,RR R%RRR\RR4tnet_connectionsRR8R^R9R:(R0ReRZR'R_RdR`((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_net_connectionsîs    cCs8|jd}|jt|ƒt|ƒtj|ƒdS(NRK(R,RLRRR4t disk_usage(R0RN((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_disk_usage s  s not supporteds&ctypes does not support unicode on PY2cCs²td|jƒš}d„}gtjƒjƒD]}||jƒ^q1}g|D]}t|krS|^qS}|j||ƒ|ƒx|D]}|j|t ƒqŽWWdQXdS(Nt dst_prefixcSstjjtjj|ƒƒS(N(RAR"trealpathRV(R<((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pytnormpaths( R R,R4R5t memory_mapsR"RtassertInR8R9(R0t funky_pathRmtxtlibpathsR"((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_memory_mapss +% N(t__name__t __module__tNoneR,t classmethodR.R/R1R3R=RGRJRORYRtskipIfRRaRRRhRjRRRs(((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR+s"      sunreliable on PYPY + TRAVISsunreliable on TRAVISsASCII fss"subprocess can't deal with unicodet TestFSAPIscBs#eZdZeZed„ƒZRS(s1Test FS APIs with a funky, valid, UTF8 path name.cCshtr tSt|jtƒr"dn tdƒ}tjƒ(tjdƒ|jt j |ƒkSWdQXdS(Nt.tignore( RR$t isinstanceR,R9Rtwarningstcatch_warningst simplefilterRAtlistdir(R-there((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR3*s $  (RtRut__doc__RR,RwR3(((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyRy!ss*subprocess can't deal with invalid unicodetTestFSAPIsWithInvalidPathcBs#eZdZeZed„ƒZRS(s-Test FS APIs with a funky, invalid path name.cCstS(N(R$(R-((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR3?s(RtRuR‚t INVALID_NAMER,RwR3(((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyRƒ7ss WINDOWS onlytTestWinProcessNamecBseZd„ZRS(cCs\tjddtjtjƒƒƒ2}|jtjƒjƒt ƒ|j sRt ‚WdQXdS(Ns psutil._psplatform.cext.proc_exeR>( RR?R4R@RARBR8R5R'R9RCRD(R0RF((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyttest_name_typeHs (RtRuR†(((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR…Est TestNonFSAPIScBs3eZdZd„Zeje dƒd„ƒZRS(s&Unicode tests for non fs-related APIs.cCs tƒdS(N(R(R0((s?/usr/lib64/python2.7/site-packages/psutil/tests/test_unicode.pyR1Zss not supportedcCs­tjjƒ}trtnd}||d5st       ’ % "