faster and simpler bytes implementation

pull/2/head
cybjit 2014-09-11 23:35:26 +02:00
parent ed13f7c47d
commit 31e6afc7cf
1 changed files with 4 additions and 11 deletions

View File

@ -8,17 +8,10 @@ import six # Python 2+3 compatibility
def bytes(s,i,j=None): def bytes(s,i,j=None):
"""implements s[i], s[i:], s[i:j] for Python2 and Python3""" """implements s[i], s[i:], s[i:j] for Python2 and Python3"""
if six.PY2: if i<0 : i=len(s)+i
if j is None: if j is None: j=i+1
return s[i] if j<0 : j=len(s)
if j<0: return s[i:j]
return s[i:]
return s[i:j]
else: # six.PY3
if i<0 : i=len(s)+i
if j is None: j=i+1
if j<0 : j=len(s)
return b''.join(six.int2byte(s[_]) for _ in range(i,j))
from .utils import choplist from .utils import choplist