strings.py
Others:
Converts a string to nice string: currentLogText -> Current Log Text.
Usage:
>>> getNiceName("getMeANiceName")
u'Get Me A Nice Name'
>>> getNiceName("__getMeANiceName")
u'__Get Me A Nice Name'
Parameters: | name (unicode) – Current string to be nicified. |
---|---|
Returns: | Nicified string. |
Return type: | unicode |
Converts a version string to it’s rank.
Usage:
>>> getVersionRank("4.2.8")
4002008000000
>>> getVersionRank("4.0")
4000000000000
>>> getVersionRank("4.2.8").__class__
<type 'int'>
Parameters: | version (unicode) – Current version to calculate rank. |
---|---|
Returns: | Rank. |
Return type: | int |
Gets the basename of a path without its extension.
Usage:
>>> getSplitextBasename("/Users/JohnDoe/Documents/Test.txt")
u'Test'
Parameters: | path (unicode) – Path to extract the basename without extension. |
---|---|
Returns: | Splitext basename. |
Return type: | unicode |
Gets common ancestor of given iterables.
Usage:
>>> getCommonAncestor(("1", "2", "3"), ("1", "2", "0"), ("1", "2", "3", "4"))
(u'1', u'2')
>>> getCommonAncestor("azerty", "azetty", "azello")
u'aze'
Parameters: | *args ([iterable]) – Iterables to retrieve common ancestor from. |
---|---|
Returns: | Common ancestor. |
Return type: | iterable |
Gets common paths ancestor of given paths.
Usage:
>>> getCommonPathsAncestor("/Users/JohnDoe/Documents", "/Users/JohnDoe/Documents/Test.txt")
u'/Users/JohnDoe/Documents'
Parameters: | *args ([unicode]) – Paths to retrieve common ancestor from. |
---|---|
Returns: | Common path ancestor. |
Return type: | unicode |
Extracts the words from given string.
Usage:
>>> getWords("Users are: John Doe, Jane Doe, Z6PO.")
[u'Users', u'are', u'John', u'Doe', u'Jane', u'Doe', u'Z6PO']
Parameters: | data (unicode) – Data to extract words from. |
---|---|
Returns: | Words. |
Return type: | list |
Filters the words using the given filters.
Usage:
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersIn=("John", "Doe"))
[u'John', u'Doe', u'Doe']
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersIn=("\w*r",))
[u'Users', u'are']
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersOut=("\w*o",))
[u'Users', u'are', u'Jane', u'Z6PO']
Parameters: |
|
---|---|
Returns: | Filtered words. |
Return type: | list |
Replaces the data occurrences in the string.
Usage:
>>> replace("Users are: John Doe, Jane Doe, Z6PO.", {"John" : "Luke", "Jane" : "Anakin", "Doe" : "Skywalker",
"Z6PO" : "R2D2"})
u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
Parameters: | |
---|---|
Returns: | Manipulated string. |
Return type: | unicode |
Removes the pattern occurrences in the string and strip the result.
Usage:
>>> removeStrip("John Doe", "John")
u'Doe'
Parameters: | |
---|---|
Returns: | Manipulated string. |
Return type: | unicode |
Converts backward slashes to forward slashes.
Usage:
>>> toForwardSlashes("To\Forward\Slashes")
u'To/Forward/Slashes'
Parameters: | data (unicode) – Data to convert. |
---|---|
Returns: | Converted path. |
Return type: | unicode |
Converts forward slashes to backward slashes.
Usage:
>>> toBackwardSlashes("/Users/JohnDoe/Documents")
u'\Users\JohnDoe\Documents'
Parameters: | data (unicode) – Data to convert. |
---|---|
Returns: | Converted path. |
Return type: | unicode |
Converts Windows path to Posix path while stripping drives letters and network server slashes.
Usage:
>>> toPosixPath("c:\Users\JohnDoe\Documents")
u'/Users/JohnDoe/Documents'
Parameters: | path (unicode) – Windows path. |
---|---|
Returns: | Path converted to Posix path. |
Return type: | unicode |
Normalizes a path, escaping slashes if needed on Windows.
Usage:
>>> getNormalizedPath("C:\Users/johnDoe\Documents")
u'C:\Users\JohnDoe\Documents'
Parameters: | path (unicode) – Path to normalize. |
---|---|
Returns: | Normalized path. |
Return type: | unicode |
Returns a random sequence.
Usage:
>>> getRandomSequence()
u'N_mYO7g5'
Parameters: | length (int) – Length of the sequence. |
---|---|
Returns: | Random sequence. |
Return type: | unicode |
Check if given data string is an email.
Usage:
>>> isEmail("[email protected]")
True
>>> isEmail("john.doe:domain.com")
False
Parameters: | data (unicode) – Data to check. |
---|---|
Returns: | Is email. |
Return type: | bool |