Package Skype4Py :: Module utils
[frames] | no frames]

Module utils

source code

Utility functions and classes used internally by Skype4Py.
Classes
  EventHandlingBase
This class is used as a base by all classes implementing event handlers.
  Cached
Base class for all cached objects.
  CachedCollection
Functions
unicode
tounicode(s)
Converts a string to a unicode string.
source code
unicode
path2unicode(path)
Decodes a file/directory path from the current file system encoding to unicode.
source code
str
unicode2path(path)
Encodes a file/directory path from unicode to the current file system encoding.
source code
list of: str or unicode
chop(s, n=1, d=None)
Chops initial words from a string and returns a list of them and the rest of the string.
source code
dict
args2dict(s)
Converts a string or comma-separated 'ARG="a value"' or 'ARG=value2' strings into a dictionary.
source code
str or unicode
quote(s, always=False)
Adds double-quotes to string if it contains spaces.
source code
list of str or unicode
split(s, d=None)
Splits a string.
source code
same as type of truevalue or falsevalue
cndexp(condition, truevalue, falsevalue)
Simulates a conditional expression known from C or Python 2.5.
source code
Function Details

tounicode(s)

source code 
Converts a string to a unicode string. Accepts two types or arguments. An UTF-8 encoded byte string or a unicode string (in the latter case, no conversion is performed).
Parameters:
  • s (str or unicode) - String to convert to unicode.
Returns: unicode
A unicode string being the result of the conversion.

path2unicode(path)

source code 
Decodes a file/directory path from the current file system encoding to unicode.
Parameters:
  • path (str) - Encoded path.
Returns: unicode
Decoded path.

unicode2path(path)

source code 
Encodes a file/directory path from unicode to the current file system encoding.
Parameters:
  • path (unicode) - Decoded path.
Returns: str
Encoded path.

chop(s, n=1, d=None)

source code 
Chops initial words from a string and returns a list of them and the rest of the string. The returned list is guaranteed to be n+1 long. If too little words are found in the string, a ValueError exception is raised.
Parameters:
  • s (str or unicode) - String to chop from.
  • n (int) - Number of words to chop.
  • d (str or unicode) - Optional delimiter. Any white-char by default.
Returns: list of: str or unicode
A list of n first words from the string followed by the rest of the string ([w1, w2, ..., wn, rest_of_string]).

args2dict(s)

source code 
Converts a string or comma-separated 'ARG="a value"' or 'ARG=value2' strings into a dictionary.
Parameters:
  • s (str or unicode) - Input string.
Returns: dict
{'ARG': 'value'} dictionary.

quote(s, always=False)

source code 
Adds double-quotes to string if it contains spaces.
Parameters:
  • s (str or unicode) - String to add double-quotes to.
  • always (bool) - If True, adds quotes even if the input string contains no spaces.
Returns: str or unicode
If the given string contains spaces or <always> is True, returns the string enclosed in double-quotes. Otherwise returns the string unchanged.

split(s, d=None)

source code 
Splits a string.
Parameters:
  • s (str or unicode) - String to split.
  • d (str or unicode) - Optional delimiter. Any white-char by default.
Returns: list of str or unicode
A list of words or [] if the string was empty.

Note: This function works like s.split(d) except that it always returns an empty list instead of [''] for empty strings.

cndexp(condition, truevalue, falsevalue)

source code 
Simulates a conditional expression known from C or Python 2.5.
Parameters:
  • condition (any) - Tells what should be returned.
  • truevalue (any) - Value returned if condition evaluates to True.
  • falsevalue (any) - Value returned if condition evaluates to False.
Returns: same as type of truevalue or falsevalue
Either truevalue or falsevalue depending on condition.