Logo Search packages:      
Sourcecode: zim version File versions  Download package

def zim::notebook::Notebook::resolve_path (   self,
  name,
  source = None,
  index = None 
)

Returns a proper path name for page names given in links
or from user input. The optional argument 'source' is the
path for the refering page, if any, or the path of the "current"
page in the user interface.

The 'index' argument allows specifying an index object, if
none is given the default index for this notebook is used.

If no source path is given or if the page name starts with
a ':' the name is considered an absolute name and only case is
resolved. If the page does not exist the last part(s) of the
name will remain in the case as given.

If a source path is given and the page name starts with '+'
it will be resolved as a direct child of the source.

Else we first look for a match of the first part of the name in the
source path. If that fails we do a search for the first part of
the name through all namespaces in the source path, starting with
pages below the namespace of the source. If no existing page was
found in this search we default to a new page below this namespace.

So if we for example look for "baz" with as source ":foo:bar:dus"
the following pages will be checked in a case insensitive way:

      :foo:bar:baz
      :foo:baz
      :baz

And if none exist we default to ":foo:bar:baz"

However if for example we are looking for "bar:bud" with as source
":foo:bar:baz:dus", we only try to resolve the case for ":foo:bar:bud"
and default to the given case if it does not yet exist.

This method will raise a PageNameError if the name resolves
to an empty string. Since all trailing ":" characters are removed
there is no way for the name to address the root path in this method -
and typically user input should not need to able to address this path.

Definition at line 503 of file notebook.py.

00503                                                            :
            '''Returns a proper path name for page names given in links
            or from user input. The optional argument 'source' is the
            path for the refering page, if any, or the path of the "current"
            page in the user interface.

            The 'index' argument allows specifying an index object, if
            none is given the default index for this notebook is used.

            If no source path is given or if the page name starts with
            a ':' the name is considered an absolute name and only case is
            resolved. If the page does not exist the last part(s) of the
            name will remain in the case as given.

            If a source path is given and the page name starts with '+'
            it will be resolved as a direct child of the source.

            Else we first look for a match of the first part of the name in the
            source path. If that fails we do a search for the first part of
            the name through all namespaces in the source path, starting with
            pages below the namespace of the source. If no existing page was
            found in this search we default to a new page below this namespace.

            So if we for example look for "baz" with as source ":foo:bar:dus"
            the following pages will be checked in a case insensitive way:

                  :foo:bar:baz
                  :foo:baz
                  :baz

            And if none exist we default to ":foo:bar:baz"

            However if for example we are looking for "bar:bud" with as source
            ":foo:bar:baz:dus", we only try to resolve the case for ":foo:bar:bud"
            and default to the given case if it does not yet exist.

            This method will raise a PageNameError if the name resolves
            to an empty string. Since all trailing ":" characters are removed
            there is no way for the name to address the root path in this method -
            and typically user input should not need to able to address this path.
            '''
            assert name, 'BUG: name is empty string'
            startswith = name[0]
            if startswith == '.':
                  startswith = '+' # backward compat
            if startswith == '+':
                  name = name[1:]
            name = self.cleanup_pathname(name)

            if index is None:
                  index = self.index

            if startswith == ':' or source == None:
                  return index.resolve_case(name) or Path(name)
            elif startswith == '+':
                  if not source:
                        raise PageNameError, '+'+name
                  return index.resolve_case(source.name+':'+name)  \
                                    or Path(source.name+':'+name)
                  # FIXME use parent as argument
            else:
                  # first check if we see an explicit match in the path
                  assert isinstance(source, Path)
                  anchor = name.split(':')[0].lower()
                  path = source.namespace.lower().split(':')
                  if anchor in path:
                        # ok, so we can shortcut to an absolute path
                        path.reverse() # why is there no rindex or rfind ?
                        i = path.index(anchor) + 1
                        path = path[i:]
                        path.reverse()
                        path.append( name.lstrip(':') )
                        name = ':'.join(path)
                        return index.resolve_case(name) or Path(name)
                        # FIXME use parentt as argument
                        # FIXME use short cut when the result is the parent
                  else:
                        # no luck, do a search through the whole path - including root
                        source = index.lookup_path(source) or source
                        for parent in source.parents():
                              candidate = index.resolve_case(name, namespace=parent)
                              if not candidate is None:
                                    return candidate
                        else:
                              # name not found, keep case as is
                              return source.parent + name

      def relative_link(self, source, href):


Generated by  Doxygen 1.6.0   Back to index