Simple helper functions.
Force a string to be a unicode instance.
Parameters: | s – any value |
---|---|
Return type: | str |
If s is not already an unicode string, it is assumed it’s an utf-8 encoded string, a thus converted to unicode and returned. Otherwise s is returned as is:
>>> assert asunicode(None) is None
>>> assert not isinstance(asunicode(b'ascii'), bytes)
Normalize the case of a string, removing spurious spaces.
Parameters: |
|
---|---|
Return type: | unicode |
>>> assert normalize(None) is None
>>> print(normalize('lele gaifax'))
Lele Gaifax
>>> print(normalize('LELE'))
Lele
>>> print(normalize('LeLe', title=False))
LeLe
Given a sequence of items, concatenate them in a nice way.
Parameters: |
|
---|---|
Return type: | unicode |
If elts is empty returns an empty unicode string; if it contains a single element, returns the stringified element; otherwise returns a unicode string composed by all but the last elements stringified and joined by a comma, followed by the localized version of and followed by the last element stringified:
>>> print(njoin([1,2,3]))
1, 2 and 3
>>> print(njoin([1,2]))
1 and 2
>>> print(njoin([1]))
1
>>> assert njoin([]) == ''
>>> print(njoin([1,2], stringify=lambda x: str(x*10)))
10 and 20
Given the name of a primary key, return the mapped entity.
Parameters: | pkname – the name of a primary key |
---|---|
Return type: | a mapped class |
Given the name of a primary key, return the related table.
Parameters: | pkname – the name of a primary key |
---|---|
Return type: | a SQLAlchemy table |