Skip to main content

A function for binding strings with a separator

Project description

Build Status

bind

Version 2.1.0

bind is a function that joins strings in a way we often need

Usage

from bind import bind
things_to_bind = ['castable', 'to', 's t r i n g.', 45, '"hi"', 0.25]

# defaults for urllib.parse.quote_plus, leaving these out would change nothing
kwargs = dict(safe='', encoding=None, errors=None) 

# by default, use slash separator and urlencoding
bind(*things_to_bind, **kwargs)
'castable/to/s+t+r+i+n+g./45/%22hi%22/0.25'

# turn off url encoding
bind(*things_to_bind, url=False, **kwargs)
'castable/to/s t r i n g./45/"hi"/0.25'

# result is the same if you pass in a list
bind(things_to_bind, url=False, **kwargs)
'castable/to/s t r i n g./45/"hi"/0.25'

# change separator --- note that it strips the other . in things_to_bind[2]
bind(*things_to_bind, sep='.')
'castable.to.s+t+r+i+n+g.45.%22hi%22.0.25'

# pointless but possible, and will strip W, H and Y from items in iterable!
bind(*things_to_bind, sep='WHY', url=True, **kwargs)
'castableWHYtoWHYs+t+r+i+n+g.WHY45WHY%22hi%22WHY0.25'

Aside from url=bool and sep=str, all keyword arguments are passed to urllib.parse.quote_plus

Tests (300% coverage)

coverage run -m unittest
coverage report --omit=tests/*
Name               Stmts   Miss  Cover
--------------------------------------
bind/__init__.py       2      0   100%
bind/bind.py          10      0   100%
--------------------------------------
TOTAL                 12      0   100%

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bind-2.1.0.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file bind-2.1.0.tar.gz.

File metadata

  • Download URL: bind-2.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for bind-2.1.0.tar.gz
Algorithm Hash digest
SHA256 d22beb70b35c47d57852e9ec3ebec284de7763bfe6fecb862f5325b3c2924cf4
MD5 0de0ff3a836f337b216705d58efb9bcb
BLAKE2b-256 52f21dcb8ed464473ab31ff6f8121fd2689ffe4790ce087dc771102b0cf2453d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page