示例#1
0
    def update_page_context(self, pagename, templatename, ctx, event_arg):
        '''Extends builder context to make the function available at build time.'''

        DirectoryHTMLBuilder.update_page_context(self, pagename, templatename, \
                                                 ctx, event_arg)

        def md5(fname):
            '''Calculates MD5 for a file relative to source directory.'''

            pathname = self.srcdir + '/' + fname
            hash = hashlib_md5()
            with open(pathname, 'rb') as f:
                for chunk in iter(lambda: f.read(65536), b''):
                    hash.update(chunk)

            return hash.hexdigest()

        ctx['md5'] = md5
示例#2
0
    def update_page_context(self, pagename: str, templatename: str, ctx: Dict,
                            event_arg: Any) -> None:
        """Extends builder context to make the MD5 function available at
        build time.
        """
        def md5(fname: str) -> str:
            """Calculates MD5 for a file relative to source directory."""

            pathname = self.srcdir + '/' + fname
            hsh = hashlib_md5()

            with open(pathname, 'rb') as hashed_file:
                for chunk in iter(lambda: hashed_file.read(65536), b''):
                    hsh.update(chunk)

            return hsh.hexdigest()

        DirectoryHTMLBuilder.update_page_context(self, pagename, templatename,
                                                 ctx, event_arg)
        ctx['md5'] = md5