Skip to content

Commit

Permalink
Adjust docstring and drop no longer used wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Dick committed Sep 28, 2023
1 parent 961893d commit 0d062f2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
15 changes: 2 additions & 13 deletions perfact/zodbsync/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,16 @@ def __init__(self, data=None, **kw):


def to_string(value, enc='utf-8'):
'''This method delivers bytes in python2 and unicode in python3.'''
"""Convert input into a string"""
if isinstance(value, str):
return value
if isinstance(value, bytes):
return value.decode(enc)
return str(value)


def to_ustring(value, enc='utf-8'):
'''Convert any string (bytes or unicode) into unicode.
'''
if isinstance(value, str):
return value
if isinstance(value, bytes):
return value.decode(enc, 'ignore')

return to_ustring(str(value))


def to_bytes(value, enc='utf-8'):
'''This method delivers bytes (encoded strings).'''
"""Convert input to bytes (encoded strings)"""
if isinstance(value, memoryview):
return value.tobytes()
if isinstance(value, bytes):
Expand Down
4 changes: 1 addition & 3 deletions perfact/zodbsync/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ def test_converters():
"""
Several tests for to_* methods
"""
for value in ['test', b'test', u'test']:
for value in ['test', b'test']:
assert helpers.to_bytes(value) == b'test'
assert helpers.to_string(value) == 'test'
assert helpers.to_ustring(value) == u'test'
assert helpers.to_string([1]) == '[1]'
assert helpers.to_ustring([1]) == u'[1]'
assert helpers.to_bytes([1]) == b'[1]'
assert helpers.to_bytes(memoryview(b'test')) == b'test'

Expand Down

0 comments on commit 0d062f2

Please sign in to comment.