def serve(request, path, **kwargs): if not settings.DEBUG and not kwargs.get('insecure'): raise ImproperlyConfigured( "The gears view can only be used in debug mode or if the " "--insecure option of 'runserver' is used.") # It is only required check because we generate # version arg for each file if 'HTTP_IF_MODIFIED_SINCE' in request.META: response = HttpResponse() response['Expires'] = http_date(time.time() + MAX_AGE) response.status_code = 304 return response normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/') try: asset = build_asset(environment, normalized_path) except FileNotFound: return staticfiles_serve(request, path, **kwargs) last_modified = asset.mtime if request.GET.get('body'): asset = asset.processed_source mimetype, encoding = mimetypes.guess_type(normalized_path) mimetype = mimetype or 'application/octet-stream' response = HttpResponse(bytes(asset), mimetype=mimetype) if encoding: response['Content-Encoding'] = encoding response['Last-Modified'] = http_date(last_modified) return response
def serve(request, path, **kwargs): if not settings.DEBUG and not kwargs.get("insecure"): raise ImproperlyConfigured( "The gears view can only be used in debug mode or if the " "--insecure option of 'runserver' is used." ) # It is only required check because we generate # version arg for each file if "HTTP_IF_MODIFIED_SINCE" in request.META: response = HttpResponse() response["Expires"] = http_date(time.time() + MAX_AGE) response.status_code = 304 return response normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip("/") try: asset = build_asset(environment, normalized_path) except FileNotFound: return staticfiles_serve(request, path, **kwargs) last_modified = asset.mtime if request.GET.get("body"): asset = asset.processed_source mimetype, encoding = mimetypes.guess_type(normalized_path) mimetype = mimetype or "application/octet-stream" response = HttpResponse(bytes(asset), mimetype=mimetype) if encoding: response["Content-Encoding"] = encoding response["Last-Modified"] = http_date(last_modified) return response
def asset_view(self, filename): environment = current_app.extensions['gears']['environment'] static_view = current_app.extensions['gears']['static_view'] try: asset = build_asset(environment, filename) except FileNotFound: return static_view(filename) if request.args.get('body'): asset = asset.processed_source.encode('utf-8') mimetype, encoding = mimetypes.guess_type(filename) return send_file(BytesIO(bytes(asset)), mimetype=mimetype, conditional=True)
def asset_view(self, filename): environment = current_app.extensions['gears']['environment'] static_view = current_app.extensions['gears']['static_view'] try: asset = build_asset(environment, filename) except FileNotFound: return static_view(filename) if request.args.get('body'): asset = asset.processed_source.encode('utf-8') mimetype, encoding = mimetypes.guess_type(filename) source = bytes(asset) return send_file(StringIO(source), mimetype=mimetype, conditional=True)
def test_is_convertible_to_bytes(self): asset = self.get_static_asset('static_source') bytes(asset)
def test_is_convertible_to_bytes(self): asset = self.get_asset('unicode_support') bytes(asset)