Ejemplo n.º 1
0
 def test_linessplit(self):
     text = blue('the sum of the squares of the sideways')
     result = [blue('the')+blue(' ')+blue('sum'),
               blue('of')+blue(' ')+blue('the'),
               blue('squares'),
               blue('of')+blue(' ')+blue('the'),
               blue('sideway'),
               blue('s')
               ]
     self.assertEqual(linesplit(text, 7), result)
Ejemplo n.º 2
0
 def test_linessplit(self):
     text = blue('the sum of the squares of the sideways')
     result = [blue('the')+blue(' ')+blue('sum'),
               blue('of')+blue(' ')+blue('the'),
               blue('squares'),
               blue('of')+blue(' ')+blue('the'),
               blue('sideway'),
               blue('s')
               ]
     self.assertEqual(linesplit(text, 7), result)
Ejemplo n.º 3
0
 def test_linessplit(self):
     text = blue("the sum of the squares of the sideways")
     result = [
         blue("the") + blue(" ") + blue("sum"),
         blue("of") + blue(" ") + blue("the"),
         blue("squares"),
         blue("of") + blue(" ") + blue("the"),
         blue("sideway"),
         blue("s"),
     ]
     self.assertEqual(linesplit(text, 7), result)
Ejemplo n.º 4
0
def formatted_argspec(funcprops, arg_pos, columns, config):
    # Pretty directly taken from bpython.cli
    func = funcprops.func
    args = funcprops.argspec.args
    kwargs = funcprops.argspec.defaults
    _args = funcprops.argspec.varargs
    _kwargs = funcprops.argspec.varkwargs
    is_bound_method = funcprops.is_bound_method
    kwonly = funcprops.argspec.kwonly
    kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()

    arg_color = func_for_letter(config.color_scheme["name"])
    func_color = func_for_letter(config.color_scheme["name"].swapcase())
    punctuation_color = func_for_letter(config.color_scheme["punctuation"])
    token_color = func_for_letter(config.color_scheme["token"])
    bolds = {
        token_color: lambda x: bold(token_color(x)),
        arg_color: lambda x: bold(arg_color(x)),
    }

    s = func_color(func) + arg_color(": (")

    if is_bound_method and isinstance(arg_pos, int):
        # TODO what values could this have?
        arg_pos += 1

    for i, arg in enumerate(args):
        kw = None
        if kwargs and i >= len(args) - len(kwargs):
            kw = str(kwargs[i - (len(args) - len(kwargs))])
        color = token_color if arg_pos in (i, arg) else arg_color
        if i == arg_pos or arg == arg_pos:
            color = bolds[color]

        s += color(arg)

        if kw is not None:
            s += punctuation_color("=")
            s += token_color(kw)

        if i != len(args) - 1:
            s += punctuation_color(", ")

    if _args:
        if args:
            s += punctuation_color(", ")
        s += token_color(f"*{_args}")

    if kwonly:
        if not _args:
            if args:
                s += punctuation_color(", ")
            s += punctuation_color("*")
        marker = object()
        for arg in kwonly:
            s += punctuation_color(", ")
            color = token_color
            if arg_pos:
                color = bolds[color]
            s += color(arg)
            default = kwonly_defaults.get(arg, marker)
            if default is not marker:
                s += punctuation_color("=")
                s += token_color(repr(default))

    if _kwargs:
        if args or _args or kwonly:
            s += punctuation_color(", ")
        s += token_color(f"**{_kwargs}")
    s += punctuation_color(")")

    return linesplit(s, columns)
Ejemplo n.º 5
0
def formatted_argspec(funcprops, arg_pos, columns, config):
    # Pretty directly taken from bpython.cli
    func = funcprops.func
    args = funcprops.argspec.args
    kwargs = funcprops.argspec.defaults
    _args = funcprops.argspec.varargs
    _kwargs = funcprops.argspec.varkwargs
    is_bound_method = funcprops.is_bound_method
    if py3:
        kwonly = funcprops.argspec.kwonly
        kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()

    arg_color = func_for_letter(config.color_scheme['name'])
    func_color = func_for_letter(config.color_scheme['name'].swapcase())
    punctuation_color = func_for_letter(config.color_scheme['punctuation'])
    token_color = func_for_letter(config.color_scheme['token'])
    bolds = {
        token_color: lambda x: bold(token_color(x)),
        arg_color: lambda x: bold(arg_color(x))
    }

    s = func_color(func) + arg_color(': (')

    if is_bound_method and isinstance(arg_pos, int):
        # TODO what values could this have?
        arg_pos += 1

    for i, arg in enumerate(args):
        kw = None
        if kwargs and i >= len(args) - len(kwargs):
            kw = str(kwargs[i - (len(args) - len(kwargs))])
        color = token_color if arg_pos in (i, arg) else arg_color
        if i == arg_pos or arg == arg_pos:
            color = bolds[color]

        if not py3:
            s += color(inspect.strseq(arg, unicode))
        else:
            s += color(arg)

        if kw is not None:
            s += punctuation_color('=')
            if not py3:
                kw = kw.decode('ascii', 'replace')
            s += token_color(kw)

        if i != len(args) - 1:
            s += punctuation_color(', ')

    if _args:
        if args:
            s += punctuation_color(', ')
        s += token_color('*%s' % (_args, ))

    if py3 and kwonly:
        if not _args:
            if args:
                s += punctuation_color(', ')
            s += punctuation_color('*')
        marker = object()
        for arg in kwonly:
            s += punctuation_color(', ')
            color = token_color
            if arg_pos:
                color = bolds[color]
            s += color(arg)
            default = kwonly_defaults.get(arg, marker)
            if default is not marker:
                s += punctuation_color('=')
                s += token_color(repr(default))

    if _kwargs:
        if args or _args or (py3 and kwonly):
            s += punctuation_color(', ')
        s += token_color('**%s' % (_kwargs, ))
    s += punctuation_color(')')

    return linesplit(s, columns)
Ejemplo n.º 6
0
 def render(self):
     return linesplit(
         green(''.join(
             s.decode('latin-1')
             for s in self.received)), 80) if self.received else ['']
Ejemplo n.º 7
0
def formatted_argspec(funcprops, arg_pos, columns, config):
    # Pretty directly taken from bpython.cli
    func = funcprops.func
    args = funcprops.argspec.args
    kwargs = funcprops.argspec.defaults
    _args = funcprops.argspec.varargs
    _kwargs = funcprops.argspec.varkwargs
    is_bound_method = funcprops.is_bound_method
    if py3:
        kwonly = funcprops.argspec.kwonly
        kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()

    arg_color = func_for_letter(config.color_scheme['name'])
    func_color = func_for_letter(config.color_scheme['name'].swapcase())
    punctuation_color = func_for_letter(config.color_scheme['punctuation'])
    token_color = func_for_letter(config.color_scheme['token'])
    bolds = {token_color: lambda x: bold(token_color(x)),
             arg_color: lambda x: bold(arg_color(x))}

    s = func_color(func) + arg_color(': (')

    if is_bound_method and isinstance(arg_pos, int):
        # TODO what values could this have?
        arg_pos += 1

    for i, arg in enumerate(args):
        kw = None
        if kwargs and i >= len(args) - len(kwargs):
            kw = str(kwargs[i - (len(args) - len(kwargs))])
        color = token_color if arg_pos in (i, arg) else arg_color
        if i == arg_pos or arg == arg_pos:
            color = bolds[color]

        if not py3:
            s += color(inspect.strseq(arg, unicode))
        else:
            s += color(arg)

        if kw is not None:
            s += punctuation_color('=')
            if not py3:
                kw = kw.decode('ascii', 'replace')
            s += token_color(kw)

        if i != len(args) - 1:
            s += punctuation_color(', ')

    if _args:
        if args:
            s += punctuation_color(', ')
        s += token_color('*%s' % (_args,))

    if py3 and kwonly:
        if not _args:
            if args:
                s += punctuation_color(', ')
            s += punctuation_color('*')
        marker = object()
        for arg in kwonly:
            s += punctuation_color(', ')
            color = token_color
            if arg_pos:
                color = bolds[color]
            s += color(arg)
            default = kwonly_defaults.get(arg, marker)
            if default is not marker:
                s += punctuation_color('=')
                s += token_color(repr(default))

    if _kwargs:
        if args or _args or (py3 and kwonly):
            s += punctuation_color(', ')
        s += token_color('**%s' % (_kwargs,))
    s += punctuation_color(')')

    return linesplit(s, columns)
Ejemplo n.º 8
0
 def render(self):
     return linesplit(green(''.join(s.decode('latin-1') for s in self.received)), 80) if self.received else ['']
Ejemplo n.º 9
0
 def render(self):
     # linesplit is paart of curtsies.formatstring
     return linesplit(
         green(''.join(
             s.decode('latin-1')
             for s in self.received)), 80) if self.received else ['']
Ejemplo n.º 10
0
def formatted_argspec(argspec, columns, config):
    # Pretty directly taken from bpython.cli
    is_bound_method = argspec[2]
    func = argspec[0]
    args = argspec[1][0]
    kwargs = argspec[1][3]
    _args = argspec[1][1]  #*args
    _kwargs = argspec[1][2]  #**kwargs
    is_bound_method = argspec[2]
    in_arg = argspec[3]
    if py3:
        kwonly = argspec[1][4]
        kwonly_defaults = argspec[1][5] or dict()

    arg_color = func_for_letter(config.color_scheme['name'])
    func_color = func_for_letter(config.color_scheme['name'].swapcase())
    punctuation_color = func_for_letter(config.color_scheme['punctuation'])
    token_color = func_for_letter(config.color_scheme['token'])
    bolds = {
        token_color: lambda x: bold(token_color(x)),
        arg_color: lambda x: bold(arg_color(x))
    }

    s = func_color(func) + arg_color(': (')

    if is_bound_method and isinstance(in_arg,
                                      int):  #TODO what values could this have?
        in_arg += 1

    for i, arg in enumerate(args):
        kw = None
        if kwargs and i >= len(args) - len(kwargs):
            kw = str(kwargs[i - (len(args) - len(kwargs))])
        color = token_color if in_arg in (i, arg) else arg_color
        if i == in_arg or arg == in_arg:
            color = bolds[color]

        if not py3:
            s += color(inspect.strseq(arg, str))
        else:
            s += color(arg)

        if kw is not None:
            s += punctuation_color('=')
            s += token_color(kw)

        if i != len(args) - 1:
            s += punctuation_color(', ')

    if _args:
        if args:
            s += punctuation_color(', ')
        s += token_color('*%s' % (_args, ))

    if py3 and kwonly:
        if not _args:
            if args:
                s += punctuation_color(', ')
            s += punctuation_color('*')
        marker = object()
        for arg in kwonly:
            s += punctuation_color(', ')
            color = token_color
            if in_arg:
                color = bolds[color]
            s += color(arg)
            default = kwonly_defaults.get(arg, marker)
            if default is not marker:
                s += punctuation_color('=')
                s += token_color(repr(default))

    if _kwargs:
        if args or _args or (py3 and kwonly):
            s += punctuation_color(', ')
        s += token_color('**%s' % (_kwargs, ))
    s += punctuation_color(')')

    return linesplit(s, columns)
def formatted_argspec(argspec, columns, config):
    # Pretty directly taken from bpython.cli
    is_bound_method = argspec[2]
    func = argspec[0]
    args = argspec[1][0]
    kwargs = argspec[1][3]
    _args = argspec[1][1]  # *args
    _kwargs = argspec[1][2]  # **kwargs
    is_bound_method = argspec[2]
    in_arg = argspec[3]
    if py3:
        kwonly = argspec[1][4]
        kwonly_defaults = argspec[1][5] or dict()

    arg_color = func_for_letter(config.color_scheme['name'])
    func_color = func_for_letter(config.color_scheme['name'].swapcase())
    punctuation_color = func_for_letter(config.color_scheme['punctuation'])
    token_color = func_for_letter(config.color_scheme['token'])
    bolds = {token_color: lambda x: bold(token_color(x)),
             arg_color: lambda x: bold(arg_color(x))}

    s = func_color(func) + arg_color(': (')

    if is_bound_method and isinstance(in_arg, int):
        # TODO what values could this have?
        in_arg += 1

    for i, arg in enumerate(args):
        kw = None
        if kwargs and i >= len(args) - len(kwargs):
            kw = str(kwargs[i - (len(args) - len(kwargs))])
        color = token_color if in_arg in (i, arg) else arg_color
        if i == in_arg or arg == in_arg:
            color = bolds[color]

        if not py3:
            s += color(inspect.strseq(arg, str))
        else:
            s += color(arg)

        if kw is not None:
            s += punctuation_color('=')
            s += token_color(kw)

        if i != len(args) - 1:
            s += punctuation_color(', ')

    if _args:
        if args:
            s += punctuation_color(', ')
        s += token_color('*%s' % (_args,))

    if py3 and kwonly:
        if not _args:
            if args:
                s += punctuation_color(', ')
            s += punctuation_color('*')
        marker = object()
        for arg in kwonly:
            s += punctuation_color(', ')
            color = token_color
            if in_arg:
                color = bolds[color]
            s += color(arg)
            default = kwonly_defaults.get(arg, marker)
            if default is not marker:
                s += punctuation_color('=')
                s += token_color(repr(default))

    if _kwargs:
        if args or _args or (py3 and kwonly):
            s += punctuation_color(', ')
        s += token_color('**%s' % (_kwargs,))
    s += punctuation_color(')')

    return linesplit(s, columns)