Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strutils.assemble #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions boltons/strutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

__all__ = ['camel2under', 'under2camel', 'slugify', 'split_punct_ws',
'unit_len', 'ordinalize', 'cardinalize', 'pluralize', 'singularize',
'asciify', 'is_ascii', 'is_uuid', 'html2text', 'strip_ansi',
'bytes2human', 'find_hashtags', 'a10n', 'gunzip_bytes',
'iter_splitlines', 'indent', 'escape_shell_args',
'asciify', 'implode', 'is_ascii', 'is_uuid', 'html2text',
'strip_ansi', 'bytes2human', 'find_hashtags', 'a10n',
'gunzip_bytes', 'iter_splitlines', 'indent', 'escape_shell_args',
'args2cmd', 'args2sh', 'parse_int_list', 'format_int_list']


Expand Down Expand Up @@ -427,6 +427,19 @@ def asciify(text, ignore=False):
return ret


def assemble(delimiter, *args):
"""Perform a join on args casted to strings.

Args:
delimiter (str or unicode): The string to use as delimiter between args
args: The

>>> assemble('-', 1, 'b') == '1-b'
True
"""
return delimiter.join(map(str, args))


def is_ascii(text):
"""Check if a unicode or bytestring, *text*, is composed of ascii
characters only. Raises :exc:`ValueError` if argument is not text.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_strutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def test_indent():
assert strutils.indent(to_indent, ' ') == ref


def test_assemble():
assert strutils.assemble('-', 1, 'b') == '1-b'


def test_is_uuid():
assert strutils.is_uuid(uuid.uuid4()) == True
assert strutils.is_uuid(uuid.uuid4(), version=1) == False
Expand Down