def _make_route(self, match, func): if isinstance(match, string_types): matcher = HobokenRouteMatcher(match) elif isinstance(match, RegexType): # match is a regex, so we extract any named groups. keys = [None] * match.groups types = [False] * match.groups for name, index in iteritems(match.groupindex): types[index - 1] = True keys[index - 1] = name # Append the route with these keys. matcher = RegexMatcher(match, types, keys) elif hasattr(match, "match") and callable(getattr(match, "match")): # Don't know what type it is, but it has a callable "match" # attribute, so we use that. matcher = match else: # Unknown type! raise InvalidMatchTypeException("Unknown type: %r" % (match,)) return Route(matcher, func)
def _make_route(self, match, func): if isinstance(match, string_types): matcher = HobokenRouteMatcher(match) elif isinstance(match, RegexType): # match is a regex, so we extract any named groups. keys = [None] * match.groups types = [False] * match.groups for name, index in iteritems(match.groupindex): types[index - 1] = True keys[index - 1] = name # Append the route with these keys. matcher = RegexMatcher(match, types, keys) elif hasattr(match, "match") and callable(getattr(match, "match")): # Don't know what type it is, but it has a callable "match" # attribute, so we use that. matcher = match else: # Unknown type! raise InvalidMatchTypeException("Unknown type: %r" % (match, )) return Route(matcher, func)
def iter_close(iter): if hasattr(iter, 'close') and callable(iter.close): iter.close()