Skip to content

Commit 9c03283

Browse files
committed
Fix SassMiddleware to work on eventlet.wsgi
1 parent bf07371 commit 9c03283

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ To be released.
88

99
- Follow up the libsass upstream: :upcommit:`3.0.1` ---
1010
See the `release note`__ of Libsass.
11+
- Fixed a bug that :class:`~sassutils.wsgi.SassMiddleware` never closes
12+
the socket on some WSGI servers e.g. ``eventlet.wsgi``.
1113

1214
__ https://github.com/sass/libsass/releases/tag/3.0.1
1315

sassutils/wsgi.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ def __call__(self, environ, start_response):
9090
self.quote_css_string(str(e)).encode('utf-8'),
9191
b'; color: maroon; background-color: white; }'
9292
]
93-
out = start_response('200 OK', [('Content-Type', 'text/css')])
94-
with open(os.path.join(package_dir, result), 'rb') as in_:
95-
while 1:
96-
chunk = in_.read(4096)
97-
if chunk:
98-
out(chunk)
99-
else:
100-
break
101-
return ()
93+
94+
def read_file(path):
95+
with open(path, 'rb') as in_:
96+
while 1:
97+
chunk = in_.read(4096)
98+
if chunk:
99+
yield chunk
100+
else:
101+
break
102+
start_response('200 OK', [('Content-Type', 'text/css')])
103+
return read_file(os.path.join(package_dir, result))
102104
return self.app(environ, start_response)
103105

104106
@staticmethod

0 commit comments

Comments
 (0)