Compare commits
No commits in common. "ccd7001726af47dd878ee2119a8ba0da475810d1" and "9cd2345c8071e53315dd6b8c851cb602709ae6c5" have entirely different histories.
ccd7001726
...
9cd2345c80
1 changed files with 25 additions and 33 deletions
|
|
@ -11,7 +11,7 @@ from sass import CompileError
|
||||||
from sassutils.builder import Manifest
|
from sassutils.builder import Manifest
|
||||||
from importlib.metadata import version as _get_version
|
from importlib.metadata import version as _get_version
|
||||||
|
|
||||||
from .codecs import quote_css_string, want_bytes, want_bytes
|
from .codecs import quote_css_string
|
||||||
from .validators import must_be
|
from .validators import must_be
|
||||||
from .asgi import _MiddlewareFactory, ASGIApp, ASGIReceive, ASGIScope, ASGISend
|
from .asgi import _MiddlewareFactory, ASGIApp, ASGIReceive, ASGIScope, ASGISend
|
||||||
from . import __version__ as _suou_version
|
from . import __version__ as _suou_version
|
||||||
|
|
@ -83,42 +83,32 @@ class SassAsyncMiddleware(_MiddlewareFactory):
|
||||||
break
|
break
|
||||||
except CompileError as e:
|
except CompileError as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
resp_body = '\n'.join([
|
|
||||||
'/*',
|
|
||||||
str(e),
|
|
||||||
'***',
|
|
||||||
f'libsass {_libsass_version} + suou {_suou_version} {datetime.datetime.now().isoformat()}',
|
|
||||||
'*/',
|
|
||||||
'',
|
|
||||||
'body::before {',
|
|
||||||
f' content: {quote_css_string(str(e))};',
|
|
||||||
' color: maroon;',
|
|
||||||
' background-color: white;',
|
|
||||||
' white-space: pre-wrap;',
|
|
||||||
' display: block;',
|
|
||||||
' font-family: monospace;',
|
|
||||||
' user-select: text;'
|
|
||||||
'}'
|
|
||||||
]).encode('utf-8')
|
|
||||||
|
|
||||||
await send({
|
await send({
|
||||||
'type': 'http.response.start',
|
'type': 'http.response.start',
|
||||||
'status': self.error_status,
|
'status': self.error_status,
|
||||||
'headers': [
|
'headers': [
|
||||||
(b'Content-Type', b'text/css; charset=utf-8'),
|
(b'Content-Type', b'text/css; charset=utf-8'),
|
||||||
(b'Content-Length', want_bytes(f'{len(resp_body)}'))
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
await send({
|
await send({
|
||||||
'type': 'http.response.body',
|
'type': 'http.response.body',
|
||||||
'body': resp_body
|
'body': '\n'.join([
|
||||||
})
|
'/*',
|
||||||
await send({
|
str(e),
|
||||||
'type': 'http.response.start',
|
'***',
|
||||||
'status': self.error_status,
|
f'libsass {_libsass_version} + suou {_suou_version} {datetime.datetime.now().isoformat()}',
|
||||||
'headers': [
|
'*/',
|
||||||
(b'Content-Type', b'text/css; charset=utf-8'),
|
'',
|
||||||
]
|
'body::before {',
|
||||||
|
f' content: {quote_css_string(str(e))};',
|
||||||
|
' color: maroon;',
|
||||||
|
' background-color: white;',
|
||||||
|
' white-space: pre-wrap;',
|
||||||
|
' display: block;',
|
||||||
|
' font-family: monospace;',
|
||||||
|
' user-select: text;'
|
||||||
|
'}'
|
||||||
|
]).encode('utf-8')
|
||||||
})
|
})
|
||||||
|
|
||||||
async def _read_file(path):
|
async def _read_file(path):
|
||||||
|
|
@ -130,20 +120,22 @@ class SassAsyncMiddleware(_MiddlewareFactory):
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
resp_body = b''
|
||||||
async for chunk in _read_file(os.path.join(package_dir, result)):
|
async for chunk in _read_file(os.path.join(package_dir, result)):
|
||||||
await send({
|
resp_body += chunk
|
||||||
'type': 'http.response.body',
|
|
||||||
'body': chunk
|
|
||||||
})
|
|
||||||
|
|
||||||
await send({
|
await send({
|
||||||
'type': 'http.response.start',
|
'type': 'http.response.start',
|
||||||
'status': 200,
|
'status': 200,
|
||||||
'headers': [
|
'headers': [
|
||||||
(b'Content-Type', b'text/css; charset=utf-8'),
|
(b'Content-Type', b'text/css; charset=utf-8'),
|
||||||
(b'Content-Length', want_bytes(f'{len(resp_body)}'))
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await send({
|
||||||
|
'type': 'http.response.body',
|
||||||
|
'body': resp_body
|
||||||
|
})
|
||||||
|
|
||||||
await self.app(scope, receive, send)
|
await self.app(scope, receive, send)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue