Qc@skdZdZddlZddlZddlZddlZddlZddlZddlm Z m Z ddlm Z ddl Zddl mZmZde fdYZd e fd YZd d8d YZd e fdYZdefdYZdefdYZdefdYZdZdZdZde fdYZdZdZdZddZdZ dZ!dd Z"d!Z#d"Z$d#Z%d$Z&d%Z'e(d&Z)d'Z*d(Z+d)Z,id*d+6d*d,6d-d.6d-d/6d-d06d-d16Z-d2Z.d3Z/d4Z0d5Z1d6e2fd7YZ3dS(9s: Miscellaneous utilities for the documentation utilities. treStructuredTextiN(tApplicationErrort DataError(tnodes(t ErrorOutputt SafeStringt SystemMessagecBseZdZRS(cCs#tj||j||_dS(N(t Exceptiont__init__tastexttlevel(tselftsystem_messageR ((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs(t__name__t __module__R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRstSystemMessagePropagationcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRstReportercBseZdZdjZed\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((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRKs        cCshtjdtdd||_||_t|tsRt||j|j}n||_ ||_ dS(Nshdocutils.utils.Reporter.set_conditions deprecated; set attributes via configuration settings or directlyt stackleveli( twarningstwarntDeprecationWarningRRRRRRRR(R tcategoryRRRR((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytset_conditions~s     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((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytattach_observerscCs|jj|dS(N(Rtremove(R R&((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytdetach_observerscCs"x|jD]}||q WdS(N(R(R tmessageR&((s;/usr/lib/python2.7/site-packages/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||dR;((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytinfoscOs|j|j||S(s Level-2, "WARNING": an issue that should be addressed. If ignored, there may be unpredictable problems with the output. (R t WARNING_LEVEL(R R>R;((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytwarningscOs|j|j||S(sz Level-3, "ERROR": an error that should be addressed. If ignored, the output will contain errors. (R t ERROR_LEVEL(R R>R;((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyterrorscOs|j|j||S(s Level-4, "SEVERE": a severe error that must be addressed. If ignored, the output will contain severe errors. Typically level-4 system messages are turned into exceptions which halt processing. (R t SEVERE_LEVEL(R R>R;((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytseveresN(R Rt__doc__tsplitR6trangeR7R?RARCRER1tFalseRR$R'R)R+R RR@RBRDRF(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyR"s 3    /   tExtensionOptionErrorcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRKstBadOptionErrorcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRLstBadOptionDataErrorcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRMstDuplicateOptionErrorcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRNscCst|}t||}|S(sC Return a dictionary mapping extension option names to converted values. :Parameters: - `field_list`: A flat field list without field arguments, where each field body consists of a single paragraph only. - `options_spec`: Dictionary mapping known option names to a conversion function such as `int` or `float`. :Exceptions: - `KeyError` for unknown option names. - `ValueError` for invalid option values (raised by the conversion function). - `TypeError` for invalid option value types (raised by conversion function). - `DuplicateOptionError` for duplicate options. - `BadOptionError` for invalid fields. - `BadOptionDataError` for invalid option data (missing name, missing data, bad quotes, etc.). (textract_optionstassemble_option_dict(t field_listt options_spect option_listt option_dict((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytextract_extension_optionss cCs!g}x|D] }t|djjdkrDtdnt|djj}|d}t|dkrd}nt|dkst|dtj  st|ddkst|ddtj  rt d|n|ddj}|j ||fq W|S(s Return a list of option (name, value) pairs from field names & bodies. :Parameter: `field_list`: A flat field list, where each field name is a single word and each field body consists of a single paragraph only. :Exceptions: - `BadOptionError` for invalid fields. - `BadOptionDataError` for invalid option data (missing name, missing data, bad quotes, etc.). iis:extension option field name may not contain multiple wordssMextension option field body may contain a single paragraph only (option "%s")N( tlenR RHRLtstrtlowerR1RRt paragraphtTextRMR%(RQRStfieldtnametbodytdata((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRO s"  "   )1 cCsi}x|D]\}}||}|dkr>t|n||kr]td|ny||||(RSRRtoptionsR\tvaluet convertortdetail((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRP-s    'tNameValueErrorcBseZRS((R R(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRiNscCst|tr|Sy|jtjd}Wngtk rLtj|Stk ry|jdd}Wqtk r|jdd}qXnXtj|S(s Ensure `path` is Unicode. Return `nodes.reprunicode` object. Decode file/path string in a failsave manner if not already done. tstrictsutf-8Rtreplace( RtunicodetdecodetsystgetfilesystemencodingR5Rt reprunicodetUnicodeDecodeError(tpath((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyt decode_pathQs    cCsg}x|r|jd}|dkr9tdn|| j}|dks\| rktdn||dj}|std|n|ddkrR|j|dd}|dkrtd ||dfnt||dkr.||djr.td ||dfn|d|!}||dj}nH|jd }|dkr||}d }n|| }||dj}|j|j|fq W|S( s Return a list of (name, value) from a line of the form "name=value ...". :Exception: `NameValueError` for invalid input (missing name, missing data, bad quotes, etc.). t=is missing "="is!missing attribute name before "="ismissing value after "%s="s'"s%attribute "%s" missing end quote (%s)s8attribute "%s" end quote (%s) not followed by whitespaceR_t(tfindRitstriptlstripRVR%RX(R-tattlisttequalstattnametendquoteR^tspace((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytextract_name_valuefsB    *    c Cs@t||j|jd|jd|jd|jd|j}|S(s Return a new Reporter object. :Parameters: `source` : string The path to or description of the source text of the document. `settings` : optparse.Values object Runtime settings. RRRR(RRRtwarning_streamRterror_encodingterror_encoding_error_handler(t source_pathtsettingstreporter((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyt new_reporters   cCsxddlm}|dkr1|jj}nt|}t||}tj||d|}|j |d|S(s Return a new empty document object. :Parameters: `source_path` : string The path to or description of the source text of the document. `settings` : optparse.Values object Runtime settings. If none are provided, a default core set will be used. If you will use the document object with any Docutils components, you must provide their default settings as well. For example, if parsing, at least provide the parser settings, obtainable as follows:: settings = docutils.frontend.OptionParser( components=(docutils.parsers.rst.Parser,) ).get_default_values() i(tfrontendRN( tdocutilsRR1t OptionParsertget_default_valuesRsRRtdocumentt note_source(RRRRR((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyt new_documents  cCst|dkrt|dtjr|d}xO|D]D\}}|j|}|r9tj|j|||d>> find_combining_chars(u'A t̆ab̆lĕ') [3, 6, 9] ii(ii(RRWRnRt enumerateRR(RtiR((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytfind_combining_charsSscCsVtt|}xt|D]}d||>> column_indices(u'A t̆ab̆lĕ') [0, 1, 2, 4, 5, 7, 8] N(RIRVRR1(Rtstring_indicestindexR((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytcolumn_indices]sitWtFitNatHtNtAcCst|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( RRWRnRRVtsumteast_asian_widthsRteast_asian_widthR5R(RRtwidth((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyt column_widthts * cCs7g}x*|D]"}||kr |j|q q W|S(N(R%(tLtrtitem((s;/usr/lib/python2.7/site-packages/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(txrangeRVtunique_combinations(titemstnRtcc((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs  !"cCs|jjdd}tjdd|}g}g|jdD]}|jdd^qC}|jdg}xTtt|ddD]:}x1t||D] }|j dj ||qWqW||7}|S(sReturn a list of normalized combinations for a `BCP 47` language tag. Example: >>> normalize_language_tag('de_AT-1901') ['de-at-1901', 'de-at', 'de-1901', 'de'] t_t-s-([a-zA-Z0-9])-s-\1_ii( RXRktreRRHRRIRVRR%Rd(ttagttaglisttsubtagtsubtagstbase_tagRttags((s;/usr/lib/python2.7/site-packages/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((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs  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(RR1Rtiot FileOutputRJtfile(R Rtof((s;/usr/lib/python2.7/site-packages/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%RR1R8(R t filenamestfilename((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs  cCs|jjd|_dS(s( Close the output file. N(RtcloseR1(R ((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs cCsDy|jj}Wntk r)d}nXd|jj||jfS(Ns %s(%r, %s)(RR\R5R1RcR R(R R((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyt__repr__s   N( R RRGR1RRRRR(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pyRs   ((4RGt __docformat__RnRtos.pathRR RRRRRt docutils.iotdocutils.utils.error_reportingRRRRRRKRLRMRNRURORPRiRsR~RR1RRRRRRRR0RRJRRRRRRRRRtobjectR(((s;/usr/lib/python2.7/site-packages/docutils/utils/__init__.pytsb         !  ,