Exemple #1
0
 def _parse_path_str(self, path_str):
     # /foo -> stuff under /foo with default depth and include_origin
     # [depth=2]/foo -> stuff under /foo with depth 2 and default i_o
     # [include_origin=false]/foo -> stuff under /foo without include_origin
     # [depth=2,include_origin=false]/foo -> combination of all options
     if path_str.startswith('[') and ']' in path_str:
         optionstr, path = PATH_WITH_OPTIONS.match(
             path_str).groups()
         optiondict = self._parse_optionstr(optionstr)
         depth = optiondict.get('depth', None)
         include_origin =  optiondict.get('include_origin', None)
         if depth is None:
             depth = self.depth
         else:
             depth = int(depth)
         if include_origin is None:
             include_origin = self.include_origin
         else:
             include_origin = asbool(include_origin)
     else:
         path = path_str
         depth = self.depth
         include_origin = self.include_origin
         
     if not path.startswith('/'):
         raise ValueError('Path must start with a slash')
     
     tmp = [x for x in url_unquote_text(path).split(_SLASH) if x]
     path_tuple = (_BLANK,) + tuple(tmp)
     return path_tuple, depth, include_origin
Exemple #2
0
    def _parse_path_str(self, path_str):
        # /foo -> stuff under /foo with default depth and include_origin
        # [depth=2]/foo -> stuff under /foo with depth 2 and default i_o
        # [include_origin=false]/foo -> stuff under /foo without include_origin
        # [depth=2,include_origin=false]/foo -> combination of all options
        if path_str.startswith('[') and ']' in path_str:
            optionstr, path = PATH_WITH_OPTIONS.match(path_str).groups()
            optiondict = self._parse_optionstr(optionstr)
            depth = optiondict.get('depth', None)
            include_origin = optiondict.get('include_origin', None)
            if depth is None:
                depth = self.depth
            else:
                depth = int(depth)
            if include_origin is None:
                include_origin = self.include_origin
            else:
                include_origin = asbool(include_origin)
        else:
            path = path_str
            depth = self.depth
            include_origin = self.include_origin

        if not path.startswith('/'):
            raise ValueError('Path must start with a slash')

        tmp = filter(None, url_unquote_text(path).split(u'/'))
        path_tuple = (u'', ) + tuple(tmp)
        return path_tuple, depth, include_origin
Exemple #3
0
 def _parse_path(self, obj_or_path):
     path_tuple = obj_or_path
     if hasattr(obj_or_path, '__parent__'):
         path_tuple = resource_path_tuple(obj_or_path)
     elif isinstance(obj_or_path, basestring):
         tmp = filter(None, url_unquote_text(obj_or_path).split(u'/'))
         path_tuple = (u'',) + tuple(tmp)
     elif not isinstance(obj_or_path, tuple):
         raise ValueError(
             'Must be object, path string, or tuple, not %s' % (
                 obj_or_path,))
     return path_tuple