"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/http_prompt/output.py" (5 Mar 2021, 1113 Bytes) of package /linux/www/http-prompt-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "output.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.0.0_vs_2.1.0.

    1 import sys
    2 
    3 import click
    4 
    5 
    6 class Printer(object):
    7     """Wrap click.echo_via_pager() so it accepts binary data."""
    8 
    9     def write(self, data):
   10         if isinstance(data, bytes):
   11             data = data.decode('utf-8')
   12 
   13         # echo_via_pager() already appends a '\n' at the end of text,
   14         # so we use rstrip() to remove extra newlines (#89)
   15         click.echo_via_pager(data.rstrip())
   16 
   17     def flush(self):
   18         pass
   19 
   20     def close(self):
   21         pass
   22 
   23     def isatty(self):
   24         return True
   25 
   26     def fileno(self):
   27         return sys.stdout.fileno()
   28 
   29     def clear(self):
   30         click.clear()
   31 
   32 
   33 class TextWriter(object):
   34     """Wrap a file-like object, opened with 'wb' or 'ab', so it accepts text
   35     data.
   36     """
   37     def __init__(self, fp):
   38         self.fp = fp
   39 
   40     def write(self, data):
   41         if isinstance(data, str):
   42             data = data.encode('utf-8')
   43         self.fp.write(data)
   44 
   45     def flush(self):
   46         self.fp.flush()
   47 
   48     def close(self):
   49         self.fp.close()
   50 
   51     def isatty(self):
   52         return self.fp.isatty()
   53 
   54     def fileno(self):
   55         return self.fp.fileno()