B t `6@s8ddlZddlZddlZddlZddlZddlZddlZddlZddlZej dddkr`dZ ndZ ddl Z ddZ dd Z d d Zd d ZddZddZddZddZedZd/ddZddZddZddZde dd dfd!d"Zd#d$Zd%d&ZGd'd(d(eZGd)d*d*eZGd+d,d,eZ d-d.Z!dS)0Nwinz.execsfdd}|S)a Code slightly adapted from the Python Decorator Library This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. Example use: @deprecated def some_func ( ): ... cs.tjdjtjjjjdd||S)Nz Use of deprecated function '%s'.)categoryfilenamelineno)warnings warn_explicit__name__DeprecationWarning__code__ co_filenameco_firstlineno)argskwargs)deprecated_function6/tmp/pip-unpacked-wheel-cqckmaqz/pyutilib/misc/misc.pywrapper_function)s z$deprecated..wrapper_functionr)rrr)rr deprecateds rcCs*d}x|D]}|dt|}q W|S)z* Create a string from an array of numbers r )reprstrip)arrayZtmpstrvalrrrtostr4s rcs8fddt|tks"t|ds&|Sg}|||S)zFlatten nested iterablescsbx\|D]T}t|tk rPt|drPyt|}||WqZ||YqZXq||qWdS)N__iter__)typestrhasattriterappend)xZans_elZel_it)_flattenrrr%?s zflatten.._flattenr)rrr )r#Zansr)r%rflatten<s   r&cCspt|tk r|St|}d}xN||krjt||tkr`|t||d7}|||||d<q|d7}qW|S)zFlatten nested listsrr)rlistlen)r#x_lenirrr flatten_list[s   r+cCsJt|tk r|Sd}x0|D](}t|tkr8|t|}q||f}qW|S)z Flatten nested tuples r)rtuple flatten_tuple)rrvr*rrrrecursive_flatten_tuplejs   r/cCst|tk r|St|}d}x^||krzt||tkrp|t||d7}|d|||||dd}q|d7}qW|S)z Flatten nested tuples rrN)rr,r()r#r)r*rrrr-ws  & r-cCsN|d}|tjtjfkrH|jtjkrHt|tjtjBtj B||ndS)Nr) osrmdirremoveerrnoEACCESchmodstatS_IRWXUS_IRWXGS_IRWXO)funcpathexcZexcvaluerrrhandleRemoveReadonlys  r=cCs$tj|sdStj|dtddS)NF) ignore_errorsonerror)r0r;existsshutilrmtreer=)dirrrrrBs rBz\s+c Cs|dkr|}t}ndt|kr$|}n t|}g}d}d}d}xt|D]\}}|rZd}qH||krhd}qH|s||kr|||d} | r|||||t| }|dkrd}qH|sH|dks|d krH|}qHW|rt d |||d|S) a Split a string, but do not split the string between quotes. If only one argument is provided (the string to be split), regex_str defaults to '\s+'. In addition, regex_str can be either a regular expression string, or a compiled expression. NmatchrrF\T"'z4ERROR: unterminated quotation found in quote_split()) whitespace_rerCrecompile enumeraterDr"r(group ValueError) Z regex_strsrcregextokensstartZinQuoteZescapingidxchargrrr quote_splits8   rUcCsx|dkrt|j}y|jd}Wn tS|ds<|drH|dd}|jd}t||}td|||ftS) zr A utility for tracing Python executions. Use this function by executing: sys.settrace(traceit) line__file__z.pycz.pyoNr z %s:%s: %s)f_lineno f_globalstraceitendswith linecachegetlineprintrstrip)frameeventargrrnamerVrrrr[s   r[cCst||dkr-szsort_index..cSs|dS)Nrr)rrrr/zsort_index..)key)r'sortedrK)lrrr sort_index*srcCs$d}xt|dD] }|d}qW|S)z&Returns the number of lines in a file.rrr)open)rcountrVrrr count_lines2s rc@seZdZdZddZdS)Buncha+ A class that can be used to store a bunch of data dynamically foo = Bunch(data=y, sq=y*y, val=2) print foo.data print foo.sq print foo.val Adapted from code developed by Alex Martelli and submitted to the ActiveState Programmer Network http://aspn.activestate.com cKst|||j|dS)N)dict__init____dict__update)selfkwrrrrGs zBunch.__init__N)r __module__ __qualname____doc__rrrrrr:s rc@sbeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dddZ dS) Containerz A generalization of Bunch. This class allows all other attributes to have a default value of None. This borrows the output formatting ideas from the ActiveState Code Container (recipe 496697). cOsxx|D]p}xjtd|D]\}|d}|dkryt||dd}Wn||dd}YnX|||d|<qWqWt|||j|d|kr|jj|_ dS)Nz[ ]+=rXr_name_) rUfindevalrrrr __class__r r)rrrrcrrrrrrrSs    zContainer.__init__cCsx|D]}t||tkr.z%s(%s)z, )rritemsrr rk)rattrsrrr__repr__szContainer.__repr__cCs|S)N) as_string)rrrr__str__szContainer.__str__rrc Cs g}|d|}x|jD]\}}|ds||dg}t|trnt|dkrX|d|||dnt|trt|dkr|dqxh|D]L}|d|dt|tr|d||dq|d t |qWn|d t ||d |qW| d |S) Nz r:r rz []-rr) rrrrxrr(r"rr'rrksort) rZnestingindentr indentationrrtextZv_rrrrs*           N)rr) r rrrrrrrrrrrrrrrrrLsrc@seZdZdZddZdS)Optionsz This is a convenience class. A common use of the Container class is to manage options that are passed into a class/solver/framework. Thus, it's convenient to call this an Options object. cOs tj|f|||ddS)Nr)rrr)rrrrrrrszOptions.__init__N)r rrrrrrrrrsrcCsTtjdkrDtjdddkrDddl}|jj||dsPtd|n t ||dS)z5 Create a hard link where dst points to src. ntN)rrrz&Failed to create hard link for file %s) r0rdsys version_infoctypeswindllkernel32ZCreateHardLinkAOSErrorlink)rNdstrrrrcreate_hardlinks r)N)"rjr3r]r0rIrAr6rr platformZexecutable_extensionryrrr&r+r/r-r=rBrJrHrUr[rhrrrrrrrrrrrrrr sH    1  %f