mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Add some methods to PowerlineRenderResult
This is an attempt to fix PDB prompt on PyPy. Does not work.
This commit is contained in:
parent
ef02ab70fb
commit
deacb9ab02
@ -16,6 +16,8 @@ if sys.version_info < (3,):
|
|||||||
class PowerlineRenderBytesResult(bytes):
|
class PowerlineRenderBytesResult(bytes):
|
||||||
def __new__(cls, s, encoding=None):
|
def __new__(cls, s, encoding=None):
|
||||||
encoding = encoding or s.encoding
|
encoding = encoding or s.encoding
|
||||||
|
if isinstance(s, PowerlineRenderResult):
|
||||||
|
return s.encode(encoding)
|
||||||
self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s)
|
self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s)
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
return self
|
return self
|
||||||
@ -57,12 +59,12 @@ if sys.version_info < (3,):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def add(encoding, *args):
|
def add(encoding, *args):
|
||||||
if any((isinstance(arg, unicode) for arg in args)):
|
if any((isinstance(arg, unicode) for arg in args)):
|
||||||
return ''.join((
|
return PowerlineRenderResult(''.join((
|
||||||
arg
|
arg
|
||||||
if isinstance(arg, unicode)
|
if isinstance(arg, unicode)
|
||||||
else arg.decode(encoding)
|
else arg.decode(encoding)
|
||||||
for arg in args
|
for arg in args
|
||||||
))
|
)), encoding)
|
||||||
else:
|
else:
|
||||||
return PowerlineRenderBytesResult(b''.join(args), encoding=encoding)
|
return PowerlineRenderBytesResult(b''.join(args), encoding=encoding)
|
||||||
|
|
||||||
@ -91,6 +93,30 @@ if sys.version_info < (3,):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return PowerlineRenderBytesResult(self)
|
return PowerlineRenderBytesResult(self)
|
||||||
|
|
||||||
|
def __getitem__(self, *args):
|
||||||
|
return PowerlineRenderResult(unicode.__getitem__(self, *args))
|
||||||
|
|
||||||
|
def __getslice__(self, *args):
|
||||||
|
return PowerlineRenderResult(unicode.__getslice__(self, *args))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add(encoding, *args):
|
||||||
|
return PowerlineRenderResult(''.join((
|
||||||
|
arg
|
||||||
|
if isinstance(arg, unicode)
|
||||||
|
else arg.decode(encoding)
|
||||||
|
for arg in args
|
||||||
|
)), encoding)
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
return self.add(self.encoding, self, other)
|
||||||
|
|
||||||
|
def __radd__(self, other):
|
||||||
|
return self.add(self.encoding, other, self)
|
||||||
|
|
||||||
|
def encode(self, *args, **kwargs):
|
||||||
|
return PowerlineRenderBytesResult(unicode.encode(self, *args, **kwargs), args[0])
|
||||||
else:
|
else:
|
||||||
PowerlineRenderResult = str
|
PowerlineRenderResult = str
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user