Return Bytes from Split
Allows split to return a list of bytes, given a byte input string.
This commit is contained in:
parent
ab48481bd8
commit
a00ce0134b
|
@ -316,7 +316,11 @@ def split(s, comments=False, posix=True):
|
|||
lex.whitespace_split = True
|
||||
if not comments:
|
||||
lex.commenters = ''
|
||||
return list(lex)
|
||||
|
||||
if isinstance(s, bytes):
|
||||
return [i.encode("ascii") for i in lex]
|
||||
else:
|
||||
return list(lex)
|
||||
|
||||
|
||||
def join(split_command):
|
||||
|
|
|
@ -171,9 +171,9 @@ class ShlexTest(unittest.TestCase):
|
|||
"""Test data splitting with posix parser"""
|
||||
self.splitTest(self.posix_data, comments=True)
|
||||
|
||||
def splitBytesTest(self):
|
||||
def testSplitBytes(self):
|
||||
"""Test byte objects splitting"""
|
||||
self.assertEqual(shlex.split(b"split words"), [b"hello", b"world"])
|
||||
self.assertEqual(shlex.split(b"split words"), [b"split", b"words"])
|
||||
|
||||
def testCompat(self):
|
||||
"""Test compatibility interface"""
|
||||
|
|
Loading…
Reference in New Issue