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

def zim::index::Index::resolve_case (   self,
  name,
  namespace = None 
)

Construct an IndexPath or Path by doing a case insensitive lookups
for pages matching these name. If the full sub-page is found an
IndexPath is returned. If at least the first part of the name is found
an a Path is returned with the part that was found in the correct case
and the remaining parts in the original case. If no match is found at
all None is returned. If a parent namespace is given, the page name is
resolved as a (indirect) sub-page of that path while assuming the case
of the parent path is correct.

Definition at line 903 of file index.py.

00903                                                   :
            '''Construct an IndexPath or Path by doing a case insensitive lookups
            for pages matching these name. If the full sub-page is found an
            IndexPath is returned. If at least the first part of the name is found
            an a Path is returned with the part that was found in the correct case
            and the remaining parts in the original case. If no match is found at
            all None is returned. If a parent namespace is given, the page name is
            resolved as a (indirect) sub-page of that path while assuming the case
            of the parent path is correct.
            '''
            if namespace and not namespace.isroot:
                  parent = self.lookup_path(namespace)
                  if parent is None:
                        return None # parent does not even exist
                  else:
                        parentid = parent.id
                        indexpath = list(parent._indexpath)
            else:
                  parent = Path(':')
                  parentid = ROOT_ID
                  indexpath = [ROOT_ID]

            names = name.split(':')
            found = []
            cursor = self.db.cursor()
            for name in names:
                  cursor.execute(
                        'select * from pages where lower(basename)==lower(?) and parent==?',
                        (name, parentid) )
                  rows = {}
                  for row in cursor.fetchall():
                        rows[row['basename']] = row

                  if not rows:
                        # path is not indexed
                        if found: # but at least we found some match
                              found.extend(names[len(found):]) # pad remaining names
                              if not parent.isroot: found.insert(0, parent.name)
                              return Path(':'.join(found))
                              # FIXME should we include an indexpath here ?
                        else:
                              return None
                  elif name in rows: # exact match
                        row = rows[name]
                  else: # take first insensitive match based on sorting
                        n = rows.keys()
                        n.sort()
                        row = rows[n[0]]

                  indexpath.append(row['id'])
                  parentid = row['id']
                  found.append(row['basename'])

            if not parent.isroot: found.insert(0, parent.name)
            return IndexPath(':'.join(found), indexpath, row)

      def list_pages(self, path):


Generated by  Doxygen 1.6.0   Back to index