diff -r 4d7bf6bdcd8f -r 8f23804302d0 app/soc/logic/key_name.py --- a/app/soc/logic/key_name.py Wed Oct 01 20:48:58 2008 +0000 +++ b/app/soc/logic/key_name.py Wed Oct 01 20:52:39 2008 +0000 @@ -23,27 +23,7 @@ ] -# start with ASCII digit or lowercase -# (additional ASCII digit or lowercase -# -OR- -# underscore and ASCII digit or lowercase) -# zero or more of OR group -LINKNAME_PATTERN_CORE = r'[0-9a-z](?:[0-9a-z]|_[0-9a-z])*' - -LINKNAME_PATTERN = r'^%s$' % LINKNAME_PATTERN_CORE -LINKNAME_ARG_PATTERN = r'(?P%s)' % LINKNAME_PATTERN_CORE - - -# partial path is multiple linkname chunks, -# each separated by a trailing / -# (at least 1) -# followed by a single linkname with no trailing / -WORK_PATH_LINKNAME_ARGS_PATTERN = ( - r'(?P%(linkname)s(?:/%(linkname)s)*)/' - '(?P%(linkname)s)' % { - 'linkname': LINKNAME_PATTERN_CORE}) - -WORK_PATH_LINKNAME_PATTERN = r'^%s$' % WORK_PATH_LINKNAME_ARGS_PATTERN +from soc.logic import path_linkname class Error(Exception): @@ -56,45 +36,6 @@ return '%s.%s' % (cls.__module__, cls.__name__) -def combinePath(path_parts): - """Returns path components combined into a single string. - - Args: - path_parts: a single path string, or a list of path part strings, - or a nested list of path part strings (where the zeroeth element in - the list is itself a list); for example: - 'a/complete/path/in/one/string' - ['some', 'path', 'parts'] - [['path', 'parts', 'and', 'a'], 'link name'] - - Returns: - None if path_parts is False (None, empty string, etc.) or if - any list elements are False (an empty list, empty string, etc.); - otherwise, the combined string with the necessary separators. - """ - if not path_parts: - # completely empty input, so return early - return None - - if not isinstance(path_parts, (list, tuple)): - # a single path string, so just return it as-is (nothing to do) - return path_parts - - flattened_parts = [] - - for part in path_parts: - if not part: - # encountered a "False" element, which invalidates everything else - return None - - if isinstance(part, (list, tuple)): - flattened_parts.extend(part) - else: - flattened_parts.append(part) - - return '/'.join(flattened_parts) - - def nameDocument(partial_path, link_name=None): """Returns a Document key name constructed from a path and link name. @@ -114,7 +55,7 @@ if link_name: path.append(link_name) - path = combinePath(path) + path = path_linkname.combinePath(path) if not path: raise Error('"path" must be non-False: "%s"' % path) @@ -170,7 +111,7 @@ Error if sponsor_ln, program_ln, and link_Name combine to produce a "False" path (None, empty string, etc.) """ - path = combinePath([[sponsor_ln, program_ln], link_name]) + path = path_linkname.combinePath([[sponsor_ln, program_ln], link_name]) if not path: raise Error('"path" must be non-False: "%s"' % path) @@ -190,7 +131,7 @@ Error if sponsor_ln, program_ln, and link_Name combine to produce a "False" path (None, empty string, etc.) """ - path = combinePath([[sponsor_ln, program_ln], link_name]) + path = path_linkname.combinePath([[sponsor_ln, program_ln], link_name]) if not path: raise Error('"path" must be non-False: "%s"' % path)