mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Various code improvements contributed by dilyanpalauzov.
These were originally based on 19.9.0 code and were rebased with conflicts resolved. Fixed #1690. Co-Authored-By: dilyanpalauzov <git-dpa@aegee.org> Signed-off-by: Brett Randall <javabrett@gmail.com>
This commit is contained in:
parent
dc7b5d5c48
commit
b014fa78ee
@ -457,9 +457,7 @@ class URL(object):
|
|||||||
return False
|
return False
|
||||||
narrow = encoder.NarrowText(loc, None)
|
narrow = encoder.NarrowText(loc, None)
|
||||||
(scheme, netloc, path, query, frag) = urlparse.urlsplit(narrow)
|
(scheme, netloc, path, query, frag) = urlparse.urlsplit(narrow)
|
||||||
if (not scheme) or (not netloc):
|
return scheme and netloc
|
||||||
return False
|
|
||||||
return True
|
|
||||||
#end def IsAbsolute
|
#end def IsAbsolute
|
||||||
IsAbsolute = staticmethod(IsAbsolute)
|
IsAbsolute = staticmethod(IsAbsolute)
|
||||||
|
|
||||||
@ -543,26 +541,16 @@ class URL(object):
|
|||||||
|
|
||||||
# Test the lastmod
|
# Test the lastmod
|
||||||
if self.lastmod:
|
if self.lastmod:
|
||||||
match = False
|
|
||||||
self.lastmod = self.lastmod.upper()
|
self.lastmod = self.lastmod.upper()
|
||||||
for pattern in LASTMOD_PATTERNS:
|
if not any(pattern.match(self.lastmod) for pattern in LASTMOD_PATTERNS):
|
||||||
match = pattern.match(self.lastmod)
|
|
||||||
if match:
|
|
||||||
break
|
|
||||||
if not match:
|
|
||||||
output.Warn('Lastmod "%s" does not appear to be in ISO8601 format on '
|
output.Warn('Lastmod "%s" does not appear to be in ISO8601 format on '
|
||||||
'URL: %s' % (self.lastmod, self.loc))
|
'URL: %s' % (self.lastmod, self.loc))
|
||||||
self.lastmod = None
|
self.lastmod = None
|
||||||
|
|
||||||
# Test the changefreq
|
# Test the changefreq
|
||||||
if self.changefreq:
|
if self.changefreq:
|
||||||
match = False
|
|
||||||
self.changefreq = self.changefreq.lower()
|
self.changefreq = self.changefreq.lower()
|
||||||
for pattern in CHANGEFREQ_PATTERNS:
|
if all(self.changefreq != pattern for pattern in CHANGEFREQ_PATTERNS):
|
||||||
if self.changefreq == pattern:
|
|
||||||
match = True
|
|
||||||
break
|
|
||||||
if not match:
|
|
||||||
output.Warn('Changefreq "%s" is not a valid change frequency on URL '
|
output.Warn('Changefreq "%s" is not a valid change frequency on URL '
|
||||||
': %s' % (self.changefreq, self.loc))
|
': %s' % (self.changefreq, self.loc))
|
||||||
self.changefreq = None
|
self.changefreq = None
|
||||||
@ -1490,7 +1478,7 @@ class InputSitemap(xml.sax.handler.ContentHandler):
|
|||||||
|
|
||||||
# Switch contexts
|
# Switch contexts
|
||||||
if (self._current < 0) or (self._contexts[self._current].AcceptTag(tag)):
|
if (self._current < 0) or (self._contexts[self._current].AcceptTag(tag)):
|
||||||
self._current = self._current + 1
|
self._current += 1
|
||||||
assert self._current < len(self._contexts)
|
assert self._current < len(self._contexts)
|
||||||
self._contexts[self._current].Open()
|
self._contexts[self._current].Open()
|
||||||
else:
|
else:
|
||||||
@ -1663,7 +1651,7 @@ class PerURLStatistics:
|
|||||||
|
|
||||||
def Log(self):
|
def Log(self):
|
||||||
""" Dump out stats to the output. """
|
""" Dump out stats to the output. """
|
||||||
if len(self._extensions):
|
if self._extensions:
|
||||||
output.Log('Count of file extensions on URLs:', 1)
|
output.Log('Count of file extensions on URLs:', 1)
|
||||||
set = self._extensions.keys()
|
set = self._extensions.keys()
|
||||||
set.sort()
|
set.sort()
|
||||||
@ -1758,7 +1746,7 @@ class Sitemap(xml.sax.handler.ContentHandler):
|
|||||||
input.ProduceURLs(self.ConsumeURL)
|
input.ProduceURLs(self.ConsumeURL)
|
||||||
|
|
||||||
# Do last flushes
|
# Do last flushes
|
||||||
if len(self._set):
|
if self._set:
|
||||||
self.FlushSet()
|
self.FlushSet()
|
||||||
if not self._sitemaps:
|
if not self._sitemaps:
|
||||||
output.Warn('No URLs were recorded, writing an empty sitemap.')
|
output.Warn('No URLs were recorded, writing an empty sitemap.')
|
||||||
|
|||||||
@ -491,20 +491,19 @@ class Arbiter(object):
|
|||||||
"""
|
"""
|
||||||
if not self.timeout:
|
if not self.timeout:
|
||||||
return
|
return
|
||||||
workers = list(self.WORKERS.items())
|
for pid, worker in self.WORKERS.items():
|
||||||
for (pid, worker) in workers:
|
|
||||||
try:
|
try:
|
||||||
if time.time() - worker.tmp.last_update() <= self.timeout:
|
if time.time() - worker.tmp.last_update() <= self.timeout:
|
||||||
continue
|
continue
|
||||||
except (OSError, ValueError):
|
except (OSError, ValueError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not worker.aborted:
|
if worker.aborted:
|
||||||
|
self.kill_worker(pid, signal.SIGKILL)
|
||||||
|
else:
|
||||||
self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
|
self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
|
||||||
worker.aborted = True
|
worker.aborted = True
|
||||||
self.kill_worker(pid, signal.SIGABRT)
|
self.kill_worker(pid, signal.SIGABRT)
|
||||||
else:
|
|
||||||
self.kill_worker(pid, signal.SIGKILL)
|
|
||||||
|
|
||||||
def reap_workers(self):
|
def reap_workers(self):
|
||||||
"""\
|
"""\
|
||||||
|
|||||||
@ -415,10 +415,7 @@ class Logger(object):
|
|||||||
|
|
||||||
def _set_syslog_handler(self, log, cfg, fmt, name):
|
def _set_syslog_handler(self, log, cfg, fmt, name):
|
||||||
# setup format
|
# setup format
|
||||||
if not cfg.syslog_prefix:
|
prefix = cfg.syslog_prefix or cfg.proc_name.replace(":", ".")
|
||||||
prefix = cfg.proc_name.replace(":", ".")
|
|
||||||
else:
|
|
||||||
prefix = cfg.syslog_prefix
|
|
||||||
|
|
||||||
prefix = "gunicorn.%s.%s" % (prefix, name)
|
prefix = "gunicorn.%s.%s" % (prefix, name)
|
||||||
|
|
||||||
|
|||||||
@ -124,7 +124,7 @@ class request(object):
|
|||||||
def szread(self, func, sizes):
|
def szread(self, func, sizes):
|
||||||
sz = sizes()
|
sz = sizes()
|
||||||
data = func(sz)
|
data = func(sz)
|
||||||
if sz >= 0 and len(data) > sz:
|
if 0 <= sz < len(data):
|
||||||
raise AssertionError("Read more than %d bytes: %s" % (sz, data))
|
raise AssertionError("Read more than %d bytes: %s" % (sz, data))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user