.pyenv/versions/3.6.8/lib/python3.6/wsgiref/handlers.py:179: ResourceWarning: unclosed file <_io.BufferedReader name=
class OwnerMenuPlugin(object):
"""A plugin for adding options for owners of a project."""
api = 2
re_menu_html = regex.compile(b'<!-- Editor Menu -->')
def replace(self, template, body):
in_header = True
for item in body:
if in_header:
if b'</head>' in item:
in_header = False
item = self.re_menu_html.sub(template, item)
yield item
raise StopIteration
def apply(self, callback, context):
def wrapper(*args, **kwargs):
response = callback(*args, **kwargs)
if 'path' in kwargs and '.html' in kwargs['path']:
# Only process html files served
# First get the template
template = jinja2_template('menu.html').encode('utf-8') # string
# process the links in the body, producing a generator
response.body = self.replace(template=template,
body=response.body)
return response
return wrapper
Hi JD,
1) You have to call `close()` on the body iterator if it is defined, as per WSGI spec.
2) Yes, it will be horrible slow. A simple str.replace instead of
a regular expression would be better, but still... why!?
3) It depends. If you do not control the body, which would be the
only reason of writing this plugin in the first place, than it may
contain all kinds of nasty scripts that are then executed in the
context of your own website.
Why are you doing that in the first place?
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bottlepy/610f2f4a-42d9-44fb-b217-071fe61d2892%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to bott...@googlegroups.com.