ó ½z]c@s}dZdZddlZddlZddlZddlZddlmZddlm Z m Z m Z de fd„ƒYZ de fd „ƒYZd „Zd efd „ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(s I/O classes provide a uniform API for low-level input and output. Subclasses exist for a variety of input/output mechanisms. treStructuredTextiÿÿÿÿN(t TransformSpec(tlocale_encodingt ErrorStringt ErrorOutputt InputErrorcBseZRS((t__name__t __module__(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRst OutputErrorcBseZRS((RR(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRscCsEy#tj|jƒtj|ƒkSWntttfk r@dSXdS(sNTest, whether the encoding of `stream` matches `encoding`. Returns :None: if `encoding` or `stream.encoding` are not a valid encoding argument (e.g. ``None``) or `stream.encoding is missing. :True: if the encoding argument resolves to the same value as `encoding`, :False: if the encodings differ. N(tcodecstlookuptencodingt LookupErrortAttributeErrort TypeErrortNone(tstreamR ((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pytcheck_encodings #tInputcBsŒeZdZdZd Zd d d dd„Zd„Zd„Zd„Z e j dƒZ e jdfe jd fe jd ffZd „ZRS( s1 Abstract base class for input wrappers. tinputtstrictcCsF||_||_||_||_|s9|j|_nd|_dS(N(R t error_handlertsourcet source_pathtdefault_source_pathRtsuccessful_encoding(tselfRRR R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyt__init__1s     cCsd|j|j|jfS(Ns%s: source=%r, source_path=%r(t __class__RR(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyt__repr__EscCs t‚dS(N(tNotImplementedError(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pytreadIscCsT|jr<|jjƒdkr<t|tƒs<tdƒ‚nt|tƒrO|S|jrg|jg}nF|j|ƒ}|rˆ|g}n%ddg}tr­|jdtƒnxb|D]Z}y2t|||jƒ}||_ |j ddƒSWq´t t fk r }|}q´Xq´Wt dd j g|D]}t|ƒ^q%ƒt|ƒfƒ‚d S( s Decode a string, `data`, heuristically. Raise UnicodeError if unsuccessful. The client application should call ``locale.setlocale`` at the beginning of processing:: locale.setlocale(locale.LC_ALL, '') tunicodes=input encoding is "unicode" but input is not a unicode objectsutf-8slatin-1iuusEUnable to decode input data. Tried the following encodings: %s. (%s)s, N(R tlowert isinstanceR tAssertionErrortdetermine_encoding_from_dataRtinsertRRtreplacet UnicodeErrorR tjointreprR(Rtdatat encodingst data_encodingtenctdecodedterrterror((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pytdecodeLs0       %scoding[:=]\s*([-\w.]+)sutf-8s utf-16-bes utf-16-lecCszx*|jD]\}}|j|ƒr |Sq WxF|jƒd D]4}|jj|ƒ}|r>|jdƒjdƒSq>WdS(s— Try to determine the encoding of `data` by looking *in* `data`. Check for a byte order mark (BOM) or an encoding declaration. iitasciiN(tbyte_order_markst startswitht splitlinest coding_slugtsearchtgroupR1R(RR*t start_bytesR tlinetmatch((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR$†sN(RRt__doc__tcomponent_typeRRRRRR1tretcompileR6R tBOM_UTF8t BOM_UTF16_BEt BOM_UTF16_LER3R$(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR's     0  tOutputcBsJeZdZdZdZddddd„Zd„Zd„Zd„Z RS(s2 Abstract base class for output wrappers. toutputRcCsC||_|pd|_||_||_|s?|j|_ndS(NR(R Rt destinationtdestination_pathtdefault_destination_path(RRERFR R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR¡s    cCsd|j|j|jfS(Ns'%s: destination=%r, destination_path=%r(RRERF(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR²scCs t‚dS(s;`data` is a Unicode string, to be encoded by `self.encode`.N(R(RR*((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pytwrite¶scCsj|jr=|jjƒdkr=t|tƒs9tdƒ‚|St|tƒsP|S|j|j|jƒSdS(NR sFthe encoding given is "unicode" but the output is not a Unicode string(R R!R"R R#tencodeR(RR*((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRIºs N( RRR<R=RRGRRRHRI(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRC—s  t FileInputcBsYeZdZd d d deejd kr0dndd„Zd„Zd„Z d „Z RS( s5 Input for single, simple file-like objects. RiitrtrUc Ks‹tj|||||ƒ||_tƒ|_x=|D]5}|dkrZtjjdƒq5td|ƒ‚q5W|d kr |rütj d kr¬i|j d6|j d6}ni}yt ||||_Wqtk rø} t| j| j|ƒ‚qXqWtj|_nLtj d krWt|j|j ƒtkrWtd|j |jj fƒ‚n|s‡y|jj|_Wq‡tk rƒq‡Xnd S( sÅ :Parameters: - `source`: either a file-like object (which is read directly), or `None` (which implies `sys.stdin` if no `source_path` given). - `source_path`: a path to a file, which is opened and then read. - `encoding`: the expected text encoding of the input file. - `error_handler`: the encoding error handler to use. - `autoclose`: close automatically after read (except when `sys.stdin` is the source). - `mode`: how the file is to be opened (see standard function `open`). The default 'rU' provides universal newline support for text files on Python < 3.4. thandle_io_errorss…deprecation warning: io.FileInput() argument `handle_io_errors` is ignored since Docutils 0.10 (2012-12-16) and will soon be removed.s2__init__() got an unexpected keyword argument '%s'iiR terrorssOEncoding clash: encoding given is "%s" but source is opened with encoding "%s".N(ii(ii(RRt autocloseRt_stderrtsyststderrRHRRt version_infoR RtopenRtIOErrorRterrnotstrerrortstdinRtFalseR'tnameRR ( RRRR RROtmodetkwargstkeyR0((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRÌs8       cCszÜyb|jtjkrUtjdkrU|jjjƒ}dj|jƒƒd}n|jjƒ}Wnstt fk rÚ}|j rÔ|j rÔt |j dƒ}|jƒ}|j ƒdj|jƒƒd}qÛ‚nXWd|jrõ|j ƒnX|j|ƒS(sU Read and decode a single file and return the data (Unicode string). iis trbN(ii(RRQRXRStbufferRR(R5R'R R RRTtcloseROR1(RR*R/tb_source((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRs !    cCs|jƒjtƒS(sK Return lines of a single file as list of Unicode strings. (RR5tTrue(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyt readlines!scCs&|jtjk r"|jjƒndS(N(RRQRXR`(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR`'sN(ii( RRR<RRbRQRSRRRcR`(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRJÇs!7  t FileOutputcBsMeZdZdZddddeddd„Zd„Zd„Zd„Z RS(s6 Output for single, simple file-like objects. twRcCsútj|||||ƒt|_||_|dk rC||_ntƒ|_|dkr||rmt |_qÆt j |_ nJ|rÆt |j dƒrÆ||j jkrÆ|jd|j j|fIJn|söy|j j|_Wqötk ròqöXndS(sA :Parameters: - `destination`: either a file-like object (which is written directly) or `None` (which implies `sys.stdout` if no `destination_path` given). - `destination_path`: a path to a file, which is opened and then written. - `encoding`: the text encoding of the output file. - `error_handler`: the encoding error handler to use. - `autoclose`: close automatically after write (except when `sys.stdout` or `sys.stderr` is the destination). - `handle_io_errors`: ignored, deprecated, will be removed. - `mode`: how the file is to be opened (see standard function `open`). The default is 'w', providing universal newline support for text files. R[s?Warning: Destination mode "%s" differs from specified mode "%s"N(RCRRbtopenedRORR[RRPRYRQtstdoutREthasattrRZRFR (RRERFR RRORMR[((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR8s(          cCsžtjdkr;d|jkr;i|jd6|jd6}ni}yt|j|j||_Wn.tk r}t |j |j |jƒ‚nXt |_ dS(NiitbR RN(ii(RQRSR[R RRTRFRERURRVRWRbRf(RR\R0((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRTcs cCs¾|js|jƒnd|jkr4tjd ksOt|j|jƒtkr |j |ƒ}tjd kr t j dkr |j dt t j dƒƒ}q nzy|jj|ƒWnåtk rg}tjd krŸt|t ƒrŸy|jjj|ƒWqdtk r`t|j|jƒtkrWtd|jp;d|jj|jfƒ‚qa|‚qdXqŸn8ttfk rž}td|jt|ƒfƒ‚nXWd |jr¹|jƒnX|S( sÐEncode `data`, write it to a single file, and return it. With Python 3 or binary output mode, `data` is returned unchanged, except when specified encoding and output encoding differ. Riiis R2s;Encoding of %s (%s) differs from specified encoding (%s)REs:Unable to encode output data. output-encoding is: %s. (%s)N(ii(ii(ii(RfRTR[RQRSRRER RYRItostlinesepR&tbytesRHRR"R_R t ValueErrorRFR'R RROR`(RR*teR/((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRHqs8  $   ! cCs8|jtjtjfkr4|jjƒt|_ndS(N(RERQRgRRR`RYRf(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR`˜s N( RRR<R[RRbRRTRHR`(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRd,s )  'tBinaryFileOutputcBseZdZdZRS(sL A version of docutils.io.FileOutput which writes to a binary file. twb(RRR<R[(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRožst StringInputcBseZdZdZd„ZRS(s Direct string input. scCs|j|jƒS(s$Decode and return the source string.(R1R(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyR¯s(RRR<RR(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRq§st StringOutputcBseZdZdZd„ZRS(s Direct string output. scCs|j|ƒ|_|jS(s=Encode `data`, store it in `self.destination`, and return it.(RIRE(RR*((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRH¼s(RRR<RGRH(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRr´st NullInputcBseZdZdZd„ZRS(s) Degenerate input: read nothing. s null inputcCsdS(sReturn a null string.u((R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRÊs(RRR<RR(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRsÂst NullOutputcBseZdZdZd„ZRS(s+ Degenerate output: write nothing. s null outputcCsdS(s6Do nothing ([don't even] send data to the bit bucket).N((RR*((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRH×s(RRR<RGRH(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRtÏst DocTreeInputcBseZdZdZd„ZRS(sm Adapter for document tree input. The document tree must be passed in the ``source`` parameter. s doctree inputcCs|jS(sReturn the document tree.(R(R((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRæs(RRR<RR(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyRuÜs(R<t __docformat__RQRjR>R tdocutilsRtdocutils.utils.error_reportingRRRRURRRRRCRJRdRoRqRrRsRtRu(((s-/tmp/pip-build-kBFYxq/docutils/docutils/io.pyts(     p0er