示例#1
0
    def prep_entriesappend(self, file, handler, fileentry):
        """Overridden to process .cap files and modify extensions.
        This is called by the
        parent's prepare to append an entry to the list.  Here, we check
        to see if there's a .cap file right before adding it."""

        global extstrip
        if extstrip == None:
            extstrip = self.config.get("handlers.UMN.UMNDirHandler",
                                       "extstrip")
        if extstrip != 'none' and \
               isinstance(handler, FileHandler):
            if extstrip == 'full' or \
               (extstrip == 'nonencoded' and not fileentry.getencoding()):
                # If it's a file, has a MIME type, and we know about it..
                fileentry.setname(
                    pygopherd.fileext.extstrip(
                        file,
                        fileentry.getencodedmimetype()
                        or fileentry.getmimetype()))

        capfilename = self.selectorbase + '/.cap/' + file

        try:
            capinfo = self.processLinkFile(capfilename,
                                           fileentry.getselector())
            if len(capinfo) >= 1:  # We handle one and only one entry.
                if capinfo[0].gettype() == 'X' or capinfo[0].gettype() == '-':
                    return  # Type X -- don't append.
                else:
                    self.mergeentries(fileentry, capinfo[0])
        except IOError:  # Ignore no capfile situation
            pass
        DirHandler.prep_entriesappend(self, file, handler, fileentry)
示例#2
0
文件: UMN.py 项目: Almad/pygopherd
    def prep_entriesappend(self, file, handler, fileentry):
        """Overridden to process .cap files and modify extensions.
        This is called by the
        parent's prepare to append an entry to the list.  Here, we check
        to see if there's a .cap file right before adding it."""

        global extstrip
        if extstrip == None:
            extstrip = self.config.get("handlers.UMN.UMNDirHandler",
                                       "extstrip")
        if extstrip != 'none' and \
               isinstance(handler, FileHandler):
            if extstrip == 'full' or \
               (extstrip == 'nonencoded' and not fileentry.getencoding()):
                # If it's a file, has a MIME type, and we know about it..
                fileentry.setname(
                    pygopherd.fileext.extstrip(file,
                                               fileentry.getencodedmimetype() or
                                               fileentry.getmimetype()))
        
        capfilename = self.selectorbase + '/.cap/' + file
        
        try:
            capinfo = self.processLinkFile(capfilename,
                                           fileentry.getselector())
            if len(capinfo) >= 1:       # We handle one and only one entry.
                if capinfo[0].gettype() == 'X' or capinfo[0].gettype() == '-':
                    return              # Type X -- don't append.
                else:
                    self.mergeentries(fileentry, capinfo[0])
        except IOError:                 # Ignore no capfile situation
            pass
        DirHandler.prep_entriesappend(self, file, handler, fileentry)
示例#3
0
    def prepare(self):
        """Override parent to do a few more things and override sort order."""
        # Initialize.
        self.linkentries = []

        # Let the parent do the directory walking for us.  Will call
        # prep_initfiles_canaddfile and prep_entriesappend.
        if DirHandler.prepare(self):
            # Returns 1 if it didn't load from the cache.
            # Merge and sort.
            self.MergeLinkFiles()
示例#4
0
文件: UMN.py 项目: Almad/pygopherd
    def prepare(self):
        """Override parent to do a few more things and override sort order."""
        # Initialize.
        self.linkentries = []

        # Let the parent do the directory walking for us.  Will call
        # prep_initfiles_canaddfile and prep_entriesappend.
        if DirHandler.prepare(self):
            # Returns 1 if it didn't load from the cache.
            # Merge and sort.
            self.MergeLinkFiles()
            self.fileentries.sort(self.entrycmp)
示例#5
0
文件: UMN.py 项目: Almad/pygopherd
 def prep_initfiles_canaddfile(self, ignorepatt, pattern, file):
     """Override the parent to process dotfiles and keep them out
     of the list."""
     if DirHandler.prep_initfiles_canaddfile(self, ignorepatt, pattern,
                                              file):
         # If the parent says it's OK, then let's see if it's
         # a link file.  If yes, process it and return false.
         if file[0] == '.':
             if not self.vfs.isdir(self.selectorbase + '/' + file):
                 self.linkentries.extend(self.processLinkFile(self.selectorbase + '/' + file))
                 return 0
             else:
                 return 0            # A "dot dir" -- ignore.
         return 1                    # Not a dot file -- return true
     else:
         return 0                    # Parent returned 0, do the same.
示例#6
0
 def prep_initfiles_canaddfile(self, ignorepatt, pattern, file):
     """Override the parent to process dotfiles and keep them out
     of the list."""
     if DirHandler.prep_initfiles_canaddfile(self, ignorepatt, pattern,
                                              file):
         # If the parent says it's OK, then let's see if it's
         # a link file.  If yes, process it and return false.
         if file[0] == '.':
             if not self.vfs.isdir(self.selectorbase + '/' + file):
                 self.linkentries.extend(self.processLinkFile(self.selectorbase + '/' + file))
                 return 0
             else:
                 return 0            # A "dot dir" -- ignore.
         return 1                    # Not a dot file -- return true
     else:
         return 0                    # Parent returned 0, do the same.
示例#7
0
    def test_dir_handler(self):
        handler = DirHandler(self.selector, "", self.protocol, self.config,
                             self.stat_result, self.vfs)

        self.assertTrue(handler.canhandlerequest())
        self.assertTrue(handler.isdir())

        handler.prepare()
        self.assertFalse(handler.fromcache)

        entry = handler.getentry()
        self.assertEqual(entry.mimetype, "application/gopher-menu")
        self.assertEqual(entry.type, "1")

        entries = handler.getdirlist()
        self.assertTrue(entries)

        # Create a second handler to test that it will load from the cached
        # file that the first handler should have created
        handler = DirHandler(self.selector, "", self.protocol, self.config,
                             self.stat_result, self.vfs)

        handler.prepare()
        self.assertTrue(handler.fromcache)

        cached_entries = handler.getdirlist()
        for a, b in zip(entries, cached_entries):
            self.assertEqual(a.selector, b.selector)