3535
3636import re
3737import codecs
38+ import sys
3839import logging
3940import util
4041from preprocessors import build_preprocessors
@@ -320,8 +321,8 @@ def convertFile(self, input=None, output=None, encoding=None):
320321
321322 Keyword arguments:
322323
323- * input: File object or path of file as string .
324- * output: Name of output file . Writes to stdout if `None`.
324+ * input: File object or path. Reads from stdin if `None` .
325+ * output: File object or path . Writes to stdout if `None`.
325326 * encoding: Encoding of input and output files. Defaults to utf-8.
326327
327328 """
@@ -332,6 +333,7 @@ def convertFile(self, input=None, output=None, encoding=None):
332333 if isinstance (input , basestring ):
333334 input_file = codecs .open (input , mode = "r" , encoding = encoding )
334335 else :
336+ input = input or sys .stdin
335337 input_file = codecs .getreader (encoding )(input )
336338 text = input_file .read ()
337339 input_file .close ()
@@ -341,13 +343,14 @@ def convertFile(self, input=None, output=None, encoding=None):
341343 html = self .convert (text )
342344
343345 # Write to file or stdout
344- if isinstance (output , ( str , unicode ) ):
346+ if isinstance (output , basestring ):
345347 output_file = codecs .open (output , "w" ,
346348 encoding = encoding ,
347349 errors = "xmlcharrefreplace" )
348350 output_file .write (html )
349351 output_file .close ()
350352 else :
353+ output = output or sys .stdout
351354 output .write (html .encode (encoding , "xmlcharrefreplace" ))
352355
353356 return self
0 commit comments