m๒ iใธEc@sdZdZdkZy dkZWnnXdklZdklZdefd„ƒYZdefd„ƒYZ d efd „ƒYZ d e fd „ƒYZ d efd„ƒYZ de fd„ƒYZ defd„ƒYZde fd„ƒYZdefd„ƒYZdS(s„ I/O classes provide a uniform API for low-level input and output. Subclasses will exist for a variety of input/output mechanisms. treStructuredTextN(s UnicodeType(s TransformSpectInputcBsJtZdZdZeZeeedd„Zd„Zd„Zd„Z RS(s1 Abstract base class for input wrappers. tinputtstrictcCsH||_||_||_||_|p|i|_nd|_dS(N(tencodingtselft error_handlertsourcet source_pathtdefault_source_pathtNonetsuccessful_encoding(RRRRR((t*/data/zmath/zope/lib/python/docutils/io.pyt__init__!s    cCsd|i|i|ifS(Ns%s: source=%r, source_path=%r(Rt __class__RR(R((R t__repr__5scCs t‚dS(N(tNotImplementedError(R((R tread9scCs์|io4|iiƒdjot|tƒp td‚nt|tƒo|Sn|ig}|ip|idƒy|it i t i ƒƒWnnXy|it i ƒdƒWnnXy|it i ƒdƒWnnX|idƒnd }d}xl|D]d}|pqny2t|||iƒ}||_|iddƒSWqttfj o }qXqW|d j od |ii|f}ntd d ig}|D]}|o|t|ƒqดqด~ƒ|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-8islatin-1tu๏ปฟus (%s: %s)sBUnable to decode input data. Tried the following encodings: %s.%ss, N(RRtlowert isinstancetdatat UnicodeTypetAssertionErrort encodingstappendtlocalet nl_langinfotCODESETt getlocaletgetdefaultlocaleR terrort error_detailstencRRtdecodedR treplacet UnicodeErrort LookupErrorRt__name__tjoint_[1]trepr(RRR#R"R R!R)R((R tdecode<sH        ( R't __module__t__doc__tcomponent_typeR R R RRR+(((R Rs   tOutputcBsStZdZdZeZeeedd„Zd„Zd„Zd„Z d„Z RS(s2 Abstract base class for output wrappers. toutputRcCsF||_|pd|_||_||_|p|i|_ndS(NR(RRRt destinationtdestination_pathtdefault_destination_path(RR1R2RR((R R }s   cCsd|i|i|ifS(Ns'%s: destination=%r, destination_path=%r(RRR1R2(R((R RŽscCs t‚dS(s;`data` is a Unicode string, to be encoded by `self.encode`.N(R(RR((R twrite’scCsึ|io8|iiƒdjo"t|tƒp td‚|Snt|tƒp|Snyy|i|i|iƒSWn[t j oO|idjo5di g}|D]}||i |ƒqฆ~ƒSqา‚nXdS(NRsFthe encoding given is "unicode" but the output is not a Unicode stringtxmlcharrefreplaceR(RRRRRRRtencodeRt ValueErrorR(R)tchartxmlcharref_encode(RRR8R)((R R6–s 5cCs?y|i|idƒSWn!tj odt|ƒSnXdS(s@Emulate Python 2.3's 'xmlcharrefreplace' encoding error handler.Rs&#%i;N(R8R6RRR%tord(RR8((R R9ฎs ( R'R,R-R.R R3R RR4R6R9(((R R/ss    t FileInputcBs;tZdZeeedddd„Zd„Zd„ZRS(s5 Input for single, simple file-like objects. RicCsti|||||ƒ||_||_|djo˜|oxyt |ƒ|_Wqฬt j oR}|p‚nt id|ii|fIJt id|IJt idƒqฬXqะt i|_d|_n|p-y|ii|_Wqtj oqXndS(sV :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 (boolean); always false if `sys.stdin` is the source. - `handle_io_errors`: summarize I/O errors here, and exit? s%s: %ss6Unable to open source file for reading (%r). Exiting.iN(RR RRRRRt autoclosethandle_io_errorsR topentIOErrorR tsyststderrRR'texittstdintnametAttributeError(RRRRRR<R=R ((R R ผs*      cCs<z|iiƒ}Wd|io|iƒnX|i|ƒS(sU Read and decode a single file and return the data (Unicode string). N(RRRRR<tcloseR+(RR((R Rใs cCs|iiƒdS(N(RRRF(R((R RF๎s(R'R,R-R R RRF(((R R;ถs ' t FileOutputcBsDtZdZeeedddd„Zd„Zd„Zd„ZRS(s6 Output for single, simple file-like objects. RicCsฆti|||||ƒd|_||_||_ |djo-|o d|_qnt i |_d|_n|p-y|ii |_Wqขtj oqขXndS(sฝ :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. - `autoclose`: close automatically after write (boolean); always false if `sys.stdout` is the destination. iN(R/R RR1R2RRtopenedR<R=R R@tstdoutRDRE(RR1R2RRR<R=((R R ๘s         cCsyt|idƒ|_Wndtj oX}|ip‚ntid|i i |fIJtid|iIJti dƒnXd|_ dS(Ntws%s: %ss;Unable to open destination file for writing (%r). Exiting.i( R>RR2R1R?R R=R@RARR'RBRH(RR ((R R>s cCs[|i|ƒ}|ip|iƒnz|ii|ƒWd|io|i ƒnX|S(s8Encode `data`, write it to a single file, and return it.N( RR6RR0RHR>R1R4R<RF(RRR0((R R4#s  cCs|iiƒd|_dS(N(RR1RFR RH(R((R RF/s (R'R,R-R R R>R4RF(((R RG๒s  t StringInputcBstZdZdZd„ZRS(s Direct string input. scCs|i|iƒS(s$Decode and return the source string.N(RR+R(R((R R<s(R'R,R-R R(((R RK4s t StringOutputcBstZdZdZd„ZRS(s Direct string output. scCs|i|ƒ|_|iS(s=Encode `data`, store it in `self.destination`, and return it.N(RR6RR1(RR((R R4Is(R'R,R-R3R4(((R RLAs t NullInputcBstZdZdZd„ZRS(s) Degenerate input: read nothing. s null inputcCsdS(sReturn a null string.uN((R((R RWs(R'R,R-R R(((R RMOs t NullOutputcBstZdZdZd„ZRS(s+ Degenerate output: write nothing. s null outputcCsdS(s6Do nothing ([don't even] send data to the bit bucket).N((RR((R R4ds(R'R,R-R3R4(((R RN\s t DocTreeInputcBstZdZdZd„ZRS(sm Adapter for document tree input. The document tree must be passed in the ``source`` parameter. s doctree inputcCs|iS(sReturn the document tree.N(RR(R((R Rss(R'R,R-R R(((R ROis (R-t __docformat__R@RttypesRtdocutilst TransformSpecRR/R;RGRKRLRMRNRO(RRMR;RPRGR@RSRRKROR/RRLRN((R t? s"    \C<B