z]c@sdZdZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl m Z ddlmZddlZ ddlmZmZde fd YZd e fd YZd dBd YZde fdYZdefdYZdefdYZdefdYZdZdZdZde fdYZdZdZ dZ!ddZ#dZ$d Z%dd!Z&d"Z'd#Z(d$Z)d%Z*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(tunescape(t ErrorOutputt SafeStringt SystemMessagecBseZdZRS(cCs#tj||j||_dS(N(t Exceptiont__init__tastexttlevel(tselftsystem_messageR ((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyR s(t__name__t __module__R (((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyRstSystemMessagePropagationcBseZRS((RR(((s9/tmp/pip-build-kBFYxq/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((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyR Ms        cCshtjdtdd||_||_t|tsRt||j|j}n||_ ||_ dS(Nshdocutils.utils.Reporter.set_conditions deprecated; set attributes via configuration settings or directlyt stackleveli( twarningstwarntDeprecationWarningRRRRRRRR(R tcategoryRRRR ((s9/tmp/pip-build-kBFYxq/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((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytattach_observerscCs|jj|dS(N(Rtremove(R R(((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytdetach_observerscCs"x|jD]}||q WdS(N(R(R tmessageR(((s9/tmp/pip-build-kBFYxq/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(RRYRpRt enumerateRR(RtiR((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytfind_combining_charsUscCsVtt|}xt|D]}d||>> from docutils.utils import column_indices >>> column_indices(u'A t̆ab̆lĕ') [0, 1, 2, 4, 5, 7, 8] N(RKRXRR3(Rtstring_indicestindexR((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytcolumn_indicesas itWtFitNatHtNtAcCsnt|tr(tjdkr(t|Stg|D]}ttj|^q2}|tt |8}|S(sqReturn the column width of text. Correct ``len(text)`` for wide East Asian and combining Unicode chars. ii(ii( RRYRpRRXtsumteast_asian_widthsRteast_asian_widthR(RRtwidth((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyt column_widthzs  &cCs7g}x*|D]"}||kr |j|q q W|S(N(R'(tLtrtitem((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytuniqs   cCs&tjdtddtj||S(s Return `itertools.combinations`.sVdocutils.utils.unique_combinations is deprecated; use itertools.combinations directly.R!i(R"R#R$Rt combinations(titemstn((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytunique_combinationss  cCs|jjdd}tjdd|}g|jdD] }|^q=}|jdf}g}xWtt|ddD]=}x4tj ||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( RZRmtreRRJRRKRXRRR'Rf(ttagtsubtagtsubtagstbase_tagttaglistRttags((s9/tmp/pip-build-kBFYxq/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((s9/tmp/pip-build-kBFYxq/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(RR3Rtiot FileOutputRLtfile(R Rtof((s9/tmp/pip-build-kBFYxq/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'RR3R:(R t filenamestfilename((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyRs  cCs|jjd|_dS(s( Close the output file. N(RtcloseR3(R ((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyRs cCsDy|jj}Wntk r)d}nXd|jj||jfS(Ns %s(%r, %s)(RR^R7R3ReRR(R R((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyt__repr__s   N( RRRIR3R RRRR(((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pyRs   tatalphatbtbetatrct candidateRwtfinalcCs|dkrt}n|jr.d|j}nd}t|j}|jrV|j}nd}|jrnd}nd}d|j|j||||f}|S(s4 Return a version identifier string built from `version_info`, a `docutils.VersionInfo` namedtuple instance or compatible tuple. If `version_info` is not provided, by default return a version identifier string based on `docutils.__version_info__` (i.e. the current Docutils version). s.%sRws.devs %s.%s%s%s%s%sN( R3Rtmicrotrelease_level_abbreviationst releaseleveltserialtreleasetmajortminor(RRRR tdevtversion((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytversion_identifiers(         ((9RIt __docformat__RpRtos.pathRRR"RRRRRRtdocutils.nodesRt docutils.iotdocutils.utils.error_reportingRRRRRRMRNRORPRWRQRRRkRuRRR3RRRRRRRR2RRRRRRRRRRtobjectRRR(((s9/tmp/pip-build-kBFYxq/docutils/docutils/utils/__init__.pytsr          !  ,               D