All we need to do to read styles from resources is to pass the
file-like object we get from open_template() on to frommapfile().
This takes the number of failing tests with PyOxidizer from 62 to 54.
| indygreg |
| hg-reviewers |
All we need to do to read styles from resources is to pass the
file-like object we get from open_template() on to frommapfile().
This takes the number of failing tests with PyOxidizer from 62 to 54.
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hgweb/hgweb_mod.py (11 lines) | |||
| M | mercurial/hgweb/hgwebdir_mod.py (7 lines) |
| Status | Author | Revision | |
|---|---|---|---|
| Abandoned | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| and pycompat.osaltsep in style | and pycompat.osaltsep in style | ||||
| ): | ): | ||||
| continue | continue | ||||
| locations = (os.path.join(style, b'map'), b'map-' + style, b'map') | locations = (os.path.join(style, b'map'), b'map-' + style, b'map') | ||||
| for location in locations: | for location in locations: | ||||
| mapfile, fp = templater.open_template(location, path) | mapfile, fp = templater.open_template(location, path) | ||||
| if mapfile: | if mapfile: | ||||
| return style, mapfile | return style, mapfile, fp | ||||
| raise RuntimeError(b"No hgweb templates found in %r" % path) | raise RuntimeError(b"No hgweb templates found in %r" % path) | ||||
| def makebreadcrumb(url, prefix=b''): | def makebreadcrumb(url, prefix=b''): | ||||
| '''Return a 'URL breadcrumb' list | '''Return a 'URL breadcrumb' list | ||||
| A 'URL breadcrumb' is a list of URL-name pairs, | A 'URL breadcrumb' is a list of URL-name pairs, | ||||
| or req.apppath.rstrip(b'/') + b'/static/' | or req.apppath.rstrip(b'/') + b'/static/' | ||||
| ) | ) | ||||
| if not staticurl.endswith(b'/'): | if not staticurl.endswith(b'/'): | ||||
| staticurl += b'/' | staticurl += b'/' | ||||
| # figure out which style to use | # figure out which style to use | ||||
| vars = {} | vars = {} | ||||
| styles, (style, mapfile) = getstyle(req, self.config, self.templatepath) | styles, (style, mapfile, fp) = getstyle( | ||||
| req, self.config, self.templatepath | |||||
| ) | |||||
| if style == styles[0]: | if style == styles[0]: | ||||
| vars[b'style'] = style | vars[b'style'] = style | ||||
| sessionvars = webutil.sessionvars(vars, b'?') | sessionvars = webutil.sessionvars(vars, b'?') | ||||
| if not self.reponame: | if not self.reponame: | ||||
| self.reponame = ( | self.reponame = ( | ||||
| self.config(b'web', b'name', b'') | self.config(b'web', b'name', b'') | ||||
| } | } | ||||
| templatekeyword = registrar.templatekeyword(defaults) | templatekeyword = registrar.templatekeyword(defaults) | ||||
| @templatekeyword(b'motd', requires=()) | @templatekeyword(b'motd', requires=()) | ||||
| def motd(context, mapping): | def motd(context, mapping): | ||||
| yield self.config(b'web', b'motd') | yield self.config(b'web', b'motd') | ||||
| tres = formatter.templateresources(self.repo.ui, self.repo) | tres = formatter.templateresources(self.repo.ui, self.repo) | ||||
| tmpl = templater.templater.frommapfile( | return templater.templater.frommapfile( | ||||
| mapfile, filters=filters, defaults=defaults, resources=tres | mapfile, fp=fp, filters=filters, defaults=defaults, resources=tres | ||||
| ) | ) | ||||
| return tmpl | |||||
| def sendtemplate(self, name, **kwargs): | def sendtemplate(self, name, **kwargs): | ||||
| """Helper function to send a response generated from a template.""" | """Helper function to send a response generated from a template.""" | ||||
| kwargs = pycompat.byteskwargs(kwargs) | kwargs = pycompat.byteskwargs(kwargs) | ||||
| self.res.setbodygen(self.tmpl.generate(name, kwargs)) | self.res.setbodygen(self.tmpl.generate(name, kwargs)) | ||||
| return self.res.sendresponse() | return self.res.sendresponse() | ||||
| return res.sendresponse() | return res.sendresponse() | ||||
| def templater(self, req, nonce): | def templater(self, req, nonce): | ||||
| def config(*args, **kwargs): | def config(*args, **kwargs): | ||||
| kwargs.setdefault('untrusted', True) | kwargs.setdefault('untrusted', True) | ||||
| return self.ui.config(*args, **kwargs) | return self.ui.config(*args, **kwargs) | ||||
| vars = {} | vars = {} | ||||
| styles, (style, mapfile) = hgweb_mod.getstyle( | styles, (style, mapfile, fp) = hgweb_mod.getstyle( | ||||
| req, config, self.templatepath | req, config, self.templatepath | ||||
| ) | ) | ||||
| if style == styles[0]: | if style == styles[0]: | ||||
| vars[b'style'] = style | vars[b'style'] = style | ||||
| sessionvars = webutil.sessionvars(vars, b'?') | sessionvars = webutil.sessionvars(vars, b'?') | ||||
| logourl = config(b'web', b'logourl') | logourl = config(b'web', b'logourl') | ||||
| logoimg = config(b'web', b'logoimg') | logoimg = config(b'web', b'logoimg') | ||||
| @templatekeyword(b'motd', requires=()) | @templatekeyword(b'motd', requires=()) | ||||
| def motd(context, mapping): | def motd(context, mapping): | ||||
| if self.motd is not None: | if self.motd is not None: | ||||
| yield self.motd | yield self.motd | ||||
| else: | else: | ||||
| yield config(b'web', b'motd') | yield config(b'web', b'motd') | ||||
| tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) | return templater.templater.frommapfile( | ||||
| return tmpl | mapfile, fp=fp, defaults=defaults | ||||
| ) | |||||