݁[c@sdZdZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl m Z ddlZ ddlmZmZde fdYZd e fd YZd dBd YZd e fdYZdefdYZdefdYZdefdYZdZdZdZde fdYZdZdZdZddZ!dZ"dZ#dd Z$d!Z%d"Z&d#Z'd$Z(d%Z)e*e*d&Z+d'Z,d(Z-d)Z.d*Z/id+d,6d+d-6d.d/6d.d06d.d16d.d26Z0d3Z1d4Z2d5Z3d6Z4d7e5fd8YZ6id9d:6d;d<6d=d>6d?d@6Z7ddAZ8dS(Cs: Miscellaneous utilities for the documentation utilities. treStructuredTextiN(tApplicationErrort DataErrort__version_info__(tnodes(t ErrorOutputt SafeStringt SystemMessagecBseZdZRS(cCs#tj||j||_dS(N(t Exceptiont__init__tastexttlevel(tselftsystem_messageR ((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyR s(t__name__t __module__R (((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRstSystemMessagePropagationcBseZRS((RR(((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyR stReportercBseZdZdjZed\ZZZZ Z de dddZ de dZdZdZdZd Zd Zd Zd Zd ZdZRS(sq Info/warning/error reporter and ``system_message`` element generator. Five levels of system messages are defined, along with corresponding methods: `debug()`, `info()`, `warning()`, `error()`, and `severe()`. There is typically one Reporter object per process. A Reporter object is instantiated with thresholds for reporting (generating warnings) and halting processing (raising exceptions), a switch to turn debug output on or off, and an I/O stream for warnings. These are stored as instance attributes. When a system message is generated, its level is compared to the stored thresholds, and a warning or error is generated as appropriate. Debug messages are produced if the stored debug switch is on, independently of other thresholds. Message output is sent to the stored warning stream if not set to ''. The Reporter class also employs a modified form of the "Observer" pattern [GoF95]_ to track system messages generated. The `attach_observer` method should be called before parsing, with a bound method or function which accepts system messages. The observer can be removed with `detach_observer`, and another added in its place. .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, 1995. sDEBUG INFO WARNING ERROR SEVEREitbackslashreplacecCs||_||_||_||_||_t|tsQt|||}n||_|pot|dd|_ g|_ d|_ dS(s7 :Parameters: - `source`: The path to or description of the source data. - `report_level`: The level at or above which warning output will be sent to `stream`. - `halt_level`: The level at or above which `SystemMessage` exceptions will be raised, halting execution. - `debug`: Show debug (level=0) system messages? - `stream`: Where warning output is sent. Can be file-like (has a ``.write`` method), a string (file name, opened for writing), '' (empty string) or `False` (for discarding all stream messages) or `None` (implies `sys.stderr`; default). - `encoding`: The output encoding. - `error_handler`: The error handler for stderr output encoding. tencodingtasciiiN( tsourcet error_handlert debug_flagt report_levelt halt_levelt isinstanceRtstreamtgetattrRt observerst max_level(R RRRRtdebugRR((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyR Ls        cCshtjdtdd||_||_t|tsRt||j|j}n||_ ||_ dS(Nshdocutils.utils.Reporter.set_conditions deprecated; set attributes via configuration settings or directlyt stackleveli( twarningstwarntDeprecationWarningRRRRRRRR(R tcategoryRRRR((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytset_conditionss     cCs|jj|dS(s The `observer` parameter is a function or bound method which takes one argument, a `nodes.system_message` instance. N(Rtappend(R tobserver((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytattach_observerscCs|jj|dS(N(Rtremove(R R'((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytdetach_observerscCs"x|jD]}||q WdS(N(R(R tmessageR'((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytnotify_observerssc Ost|trt|}n|j}d|krt|d\}}|d=|dk rr|jd|n|dk r|jd|qnd|kry"|j|jd\}}Wnt k rd\}}nX|dk r||dt|n||kr]td|ny||||>> from docutils.utils import find_combining_chars >>> find_combining_chars(u'A t̆ab̆lĕ') [3, 6, 9] ii(ii(RRXRoRt enumerateRR(RtiR((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytfind_combining_chars^scCsVtt|}xt|D]}d||>> from docutils.utils import column_indices >>> column_indices(u'A t̆ab̆lĕ') [0, 1, 2, 4, 5, 7, 8] N(RJRWRR2(Rtstring_indicestindexR((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytcolumn_indicesjs itWtFitNatHtNtAcCst|tr(tjdkr(t|Sy0tg|D]}ttj|^q5}Wnt k rwt|}nX|tt |8}|S(sqReturn the column width of text. Correct ``len(text)`` for wide East Asian and combining Unicode chars. ii(ii( RRXRoRRWtsumteast_asian_widthsRteast_asian_widthR6R(RRtwidth((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyt column_widths * cCs7g}x*|D]"}||kr |j|q q W|S(N(R&(tLtrtitem((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytuniqs   ccss|dkrgVn[xXtt||dD]<}x3t||d|dD]}||g|VqQWq/WdS(s=Return n-length tuples, in sorted order, no repeated elementsiiN(txrangeRWtunique_combinations(titemstnRtcc((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRs  !"cCs|jjdd}tjdd|}g|jdD] }|^q=}|jdg}g}xTtt|ddD]:}x1t||D] }|j dj ||qWqW||7}|S(sWReturn a list of normalized combinations for a `BCP 47` language tag. Example: >>> from docutils.utils import normalize_language_tag >>> normalize_language_tag('de_AT-1901') ['de-at-1901', 'de-at', 'de-1901', 'de'] >>> normalize_language_tag('de-CH-x_altquot') ['de-ch-x-altquot', 'de-ch', 'de-x-altquot', 'de'] t-t_s_([a-zA-Z0-9])_s_\1-ii( RYRltreRRIRRJRWRR&Re(ttagtsubtagtsubtagstbase_tagttaglistRttags((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytnormalize_language_tags "" tDependencyListcBsAeZdZdgdZdZdZdZdZRS(s List of dependencies, with file recording support. Note that the output file is not automatically closed. You have to explicitly call the close() method. cCs/|j|x|D]}|j|qWdS(s Initialize the dependency list, automatically setting the output file to `output_file` (see `set_output()`) and adding all supplied dependencies. N(t set_outputtadd(R t output_filet dependenciesR((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyR s  cCs^g|_|rQ|dkr$d}n|}tjjd|dddt|_n d|_dS(sH Set the output file and clear the list of already added dependencies. `output_file` must be a string. The specified file is immediately overwritten. If output_file is '-', the output will be written to stdout. If it is None, no file output is done when calling add(). Rtdestination_pathRtutf8t autocloseN(RR2Rtiot FileOutputRKtfile(R Rtof((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRs   cGs]xV|D]N}||jkr|jj||jdk rU|jj|dqUqqWdS(s If the dependency `filename` has not already been added, append it to self.list and print it to self.file if self.file is not None. s N(RR&RR2R9(R t filenamestfilename((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRs  cCs|jjd|_dS(s( Close the output file. N(RtcloseR2(R ((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRs cCsDy|jj}Wntk r)d}nXd|jj||jfS(Ns %s(%r, %s)(RR]R6R2RdRR(R R((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyt__repr__s   N( RRRHR2R RRRR(((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pyRs   tatalphatbtbetatrct candidateRvtfinalcCs|d krt}n|dr0d|d}nd}t|d}|dr[|d}nd}|drtd}nd}d|d |d ||||f}|S( s~ Given a `version_info` tuple (default is docutils.__version_info__), build & return a version identifier string. is.%sRviiis.devs %s.%s%s%s%s%siiN(R2Rtrelease_level_abbreviations(Rtmicrot releaseleveltserialtdevtversion((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytversion_identifier s*         ((9RHt __docformat__RoRtos.pathRRR!RRRRRRt docutils.iotdocutils.utils.error_reportingRRRRRRLRMRNRORVRPRQRjRtRRR2RRRRRRRR1RRKRRRRRRRRRRtobjectRR R(((so/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/docutils/docutils/utils/__init__.pytsr          !  ,               D