Coverage for tw2.core.util : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Utility functions, used internally. """
# py2 except ImportError: # py3 import _thread as thread
""" Convert a column name to a Human Readable name. 1) Strip _id from the end 2) Convert _ to spaces 3) Convert CamelCase to Camel Case 4) Upcase first character of Each Word """ name = name[:-3] re.findall(r'([A-Z][a-z0-9]+|[a-z0-9]+|[A-Z0-9]+)', name)])
"""Performs several regexp substitutions on a string with a single pass.
``dct`` is a dictionary keyed by a regular expression string and with a callable as value that will get called to produce a substituted value.
The callable takes the matched text as first argument and may take any number of positional and keyword arguments. These arguments are any extra args passed when calling the instance.
For performance, a single regular expression is built.
Example::
>>> string = "aaaabbbcc" >>> replacer = MultipleReplacer({ ... 'a+':lambda g, context: g + context['after_a'], ... 'b+':lambda g, context: g + context['after_b'], ... 'c+':lambda g, context: context['before_c'] + g, ... }) >>> replacer("aaaabbbcc", dict( ... after_a = "1", ... after_b = "2", ... before_c = "3" ... )) 'aaaa1bbb23cc' """
return "<%s at %d (%r)>" % (self.__class__.__name__, id(self), self._raw_regexp)
return webob.Response(request=req, status=status, content_type="text/html")
global _memoization_flush_callbacks
else:
else:
# relpath support for python-2.5 # Taken from https://github.com/nipy/nipype/issues/62 # Related to https://github.com/toscawidgets/tw2.core/issues/30 except ImportError: import os import os.path as op
def relpath(path, start=None): """Return a relative version of a path""" if start is None: start = os.curdir if not path: raise ValueError("no path specified") start_list = op.abspath(start).split(op.sep) path_list = op.abspath(path).split(op.sep)
if start_list[0].lower() != path_list[0].lower(): unc_path, rest = op.splitunc(path) unc_start, rest = op.splitunc(start) if bool(unc_path) ^ bool(unc_start): raise ValueError( "Cannot mix UNC and non-UNC paths (%s and%s)" % (path, start)) else: raise ValueError( "path is on drive %s, start on drive %s" % (path_list[0], start_list[0]))
# Work out how much of the filepath is shared by start and path. for i in range(min(len(start_list), len(path_list))): if start_list[i].lower() != path_list[i].lower(): break else: i += 1
rel_list = [op.pardir] * (len(start_list) - i) + path_list[i:] if not rel_list: return os.curdir return op.join(*rel_list) |