home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
-
- try:
- import curses
- except ImportError:
- curses = None
-
- COLOR_BLACK = 0
- COLOR_RED = 1
- COLOR_GREEN = 2
- COLOR_YELLOW = 3
- COLOR_BLUE = 4
- COLOR_MAGENTA = 5
- COLOR_CYAN = 6
- COLOR_WHITE = 7
- A_BLINK = 1
- A_BOLD = 2
- A_DIM = 4
- A_REVERSE = 8
- A_STANDOUT = 16
- A_UNDERLINE = 32
-
- class Style(object):
- __slots__ = ('fg', 'bg', 'attrs')
- COLORNAMES = {
- 'black': COLOR_BLACK,
- 'red': COLOR_RED,
- 'green': COLOR_GREEN,
- 'yellow': COLOR_YELLOW,
- 'blue': COLOR_BLUE,
- 'magenta': COLOR_MAGENTA,
- 'cyan': COLOR_CYAN,
- 'white': COLOR_WHITE }
- ATTRNAMES = {
- 'blink': A_BLINK,
- 'bold': A_BOLD,
- 'dim': A_DIM,
- 'reverse': A_REVERSE,
- 'standout': A_STANDOUT,
- 'underline': A_UNDERLINE }
-
- def __init__(self, fg, bg, attrs = 0):
- self.fg = fg
- self.bg = bg
- self.attrs = attrs
-
-
- def __call__(self, *args):
- text = Text()
- for arg in args:
- if isinstance(arg, Text):
- text.extend(arg)
- continue
- text.append((self, arg))
-
- return text
-
-
- def __eq__(self, other):
- if self.fg == other.fg and self.bg == other.bg:
- pass
- return self.attrs == other.attrs
-
-
- def __neq__(self, other):
- if not self.fg != other.fg and self.bg != other.bg:
- pass
- return self.attrs != other.attrs
-
-
- def __repr__(self):
- color2name = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
- attrs2name = ('blink', 'bold', 'dim', 'reverse', 'standout', 'underline')
- if not [](_[1]):
- pass
- return color2name[self.fg] % (color2name[self.bg], '|'.join, [], 0)
-
-
- def fromstr(cls, value):
- fg = COLOR_WHITE
- bg = COLOR_BLACK
- attrs = 0
- parts = value.split(':')
- if len(parts) > 0:
- fg = cls.COLORNAMES[parts[0].lower()]
- if len(parts) > 1:
- bg = cls.COLORNAMES[parts[1].lower()]
- if len(parts) > 2:
- for strattr in parts[2].split('|'):
- attrs |= cls.ATTRNAMES[strattr.lower()]
-
-
-
-
- return cls(fg, bg, attrs)
-
- fromstr = classmethod(fromstr)
-
- def fromenv(cls, name, default):
- return cls.fromstr(os.environ.get(name, default))
-
- fromenv = classmethod(fromenv)
-
-
- def switchstyle(s1, s2):
- attrmask = A_BLINK | A_BOLD | A_UNDERLINE | A_REVERSE
- a1 = s1.attrs & attrmask
- a2 = s2.attrs & attrmask
- args = []
- if s1 != s2:
- if a1 & ~a2 or s2 == style_default:
- args.append('0')
- s1 = style_default
- a1 = 0
-
- if not (a1 & A_BOLD) and a2 & A_BOLD:
- args.append('1')
-
- if not (a1 & A_UNDERLINE) and a2 & A_UNDERLINE:
- args.append('4')
-
- if not (a1 & A_BLINK) and a2 & A_BLINK:
- args.append('5')
-
- if not (a1 & A_REVERSE) and a2 & A_REVERSE:
- args.append('7')
-
- if s1.fg != s2.fg:
- args.append('3%d' % s2.fg)
-
- if s1.bg != s2.bg:
- args.append('4%d' % s2.bg)
-
- if args:
- return '\x1b[%sm' % ';'.join(args)
-
- return ''
-
-
- class Text(list):
-
- def __init__(self, *args):
- list.__init__(self)
- self.append(*args)
-
-
- def __repr__(self):
- return '%s.%s(%s)' % (self.__class__.__module__, self.__class__.__name__, list.__repr__(self)[1:-1])
-
-
- def append(self, *args):
- for arg in args:
- if isinstance(arg, Text):
- self.extend(arg)
- continue
- if isinstance(arg, tuple):
- list.append(self, arg)
- continue
- if isinstance(arg, unicode):
- list.append(self, (style_default, arg))
- continue
- list.append(self, (style_default, str(arg)))
-
-
-
- def insert(self, index, *args):
- self[index:index] = Text(*args)
-
-
- def __add__(self, other):
- new = Text()
- new.append(self)
- new.append(other)
- return new
-
-
- def __iadd__(self, other):
- self.append(other)
- return self
-
-
- def format(self, styled = True):
- if styled:
- oldstyle = style_default
- for style, string in self:
- if not isinstance(style, (int, long)):
- switch = switchstyle(oldstyle, style)
- if switch:
- yield switch
-
- if string:
- yield string
-
- oldstyle = style
- continue
-
- switch = switchstyle(oldstyle, style_default)
- if switch:
- yield switch
-
- else:
- for style, string in self:
- if not isinstance(style, (int, long)):
- yield string
- continue
-
-
-
- def string(self, styled = True):
- return ''.join(self.format(styled))
-
-
- def __str__(self):
- return self.string(False)
-
-
- def write(self, stream, styled = True):
- for part in self.format(styled):
- stream.write(part)
-
-
-
-
- try:
- import ipipe
- except ImportError:
- pass
-
-
- def xrepr_astyle_text(self, mode = 'default'):
- yield (-1, True)
- for info in self:
- yield info
-
-
- ipipe.xrepr.when_type(Text)(xrepr_astyle_text)
-
- def streamstyle(stream, styled = None):
- if styled is None:
-
- try:
- styled = os.isatty(stream.fileno())
- except (KeyboardInterrupt, SystemExit):
- raise
- except Exception:
- styled = False
- except:
- None<EXCEPTION MATCH>(KeyboardInterrupt, SystemExit)
-
-
- None<EXCEPTION MATCH>(KeyboardInterrupt, SystemExit)
- return styled
-
-
- def write(stream, styled, *texts):
- text = Text(*texts)
- text.write(stream, streamstyle(stream, styled))
-
-
- def writeln(stream, styled, *texts):
- write(stream, styled, *texts)
- stream.write('\n')
-
-
- class Stream(object):
-
- def __init__(self, stream, styled = None):
- self.stream = stream
- self.styled = streamstyle(stream, styled)
-
-
- def write(self, *texts):
- write(self.stream, self.styled, *texts)
-
-
- def writeln(self, *texts):
- writeln(self.stream, self.styled, *texts)
-
-
- def __getattr__(self, name):
- return getattr(self.stream, name)
-
-
-
- class stdout(object):
-
- def write(self, *texts):
- write(sys.stdout, None, *texts)
-
-
- def writeln(self, *texts):
- writeln(sys.stdout, None, *texts)
-
-
- def __getattr__(self, name):
- return getattr(sys.stdout, name)
-
-
- stdout = stdout()
-
- class stderr(object):
-
- def write(self, *texts):
- write(sys.stderr, None, *texts)
-
-
- def writeln(self, *texts):
- writeln(sys.stderr, None, *texts)
-
-
- def __getattr__(self, name):
- return getattr(sys.stdout, name)
-
-
- stderr = stderr()
- if curses is not None:
- COLOR2CURSES = [
- COLOR_BLACK,
- COLOR_RED,
- COLOR_GREEN,
- COLOR_YELLOW,
- COLOR_BLUE,
- COLOR_MAGENTA,
- COLOR_CYAN,
- COLOR_WHITE]
- A2CURSES = {
- A_BLINK: curses.A_BLINK,
- A_BOLD: curses.A_BOLD,
- A_DIM: curses.A_DIM,
- A_REVERSE: curses.A_REVERSE,
- A_STANDOUT: curses.A_STANDOUT,
- A_UNDERLINE: curses.A_UNDERLINE }
-
- style_default = Style.fromstr('white:black')
- style_type_none = Style.fromstr('magenta:black')
- style_type_bool = Style.fromstr('magenta:black')
- style_type_number = Style.fromstr('yellow:black')
- style_type_datetime = Style.fromstr('magenta:black')
- style_type_type = Style.fromstr('cyan:black')
- style_url = Style.fromstr('green:black')
- style_dir = Style.fromstr('cyan:black')
- style_file = Style.fromstr('green:black')
- style_ellisis = Style.fromstr('red:black')
- style_error = Style.fromstr('red:black')
- style_nodata = Style.fromstr('red:black')
-