def handle_css(self): try: f = open(os.path.join(self.config.static_path, "css", "main.css")) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="text/css")
def handle_css(self): try: f = open(os.path.join(self.config.static_path, "css", "main.css")) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="text/css")
def handle_index(self): """Serve up the one static index page.""" try: f = open(os.path.join(self.config.static_path, "index.html")) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype='text/html')
def handle_index(self): """Serve up the one static index page.""" try: f = open(os.path.join(self.config.static_path, "index.html")) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype='text/html')
def handle_svg_img(self, name): img_dir = os.path.join(self.config.static_path, "img") if name not in os.listdir(img_dir): raise NotFound try: f = open(os.path.join(img_dir, name)) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="image/svg+xml")
def handle_js(self, name): js_dir = os.path.join(self.config.static_path, "js") if name not in os.listdir(js_dir): raise NotFound try: f = open(os.path.join(js_dir, name)) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="application/javascript")
def handle_svg_img(self, name): img_dir = os.path.join(self.config.static_path, "img") if name not in os.listdir(img_dir): raise NotFound try: f = open(os.path.join(img_dir, name)) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="image/svg+xml")
def handle_js(self, name): js_dir = os.path.join(self.config.static_path, "js") if name not in os.listdir(js_dir): raise NotFound try: f = open(os.path.join(js_dir, name)) except IOError: get_sentry().captureException() return Response(status=500, response="Internal Server Error") txt = f.read() f.close() return Response(response=txt, mimetype="application/javascript")
def __call__(self, request): try: with closing(self.engine.connect()) as conn: response = CoverArtRedirect(self.config, conn).handle(request) response.headers.add('Access-Control-Allow-Origin', '*') return response except werkzeug.exceptions.HTTPException as e: get_sentry().captureException() return e except: # FIXME: Exception clause is too broad get_sentry().captureException() logging.error("Caught exception\n" + traceback.format_exc()) return werkzeug.wrappers.Response( status=500, response=["Whoops. Our bad.\n"], )
def __call__(self, request): try: with closing(self.engine.connect()) as conn: response = CoverArtRedirect(self.config, conn).handle(request) except werkzeug.exceptions.HTTPException as e: get_sentry().captureException() response = e.get_response() except: # FIXME: Exception clause is too broad get_sentry().captureException() logging.error("Caught exception\n" + traceback.format_exc()) response = werkzeug.wrappers.Response( status=500, response=["Whoops. Our bad.\n"], ) response.headers.add('Access-Control-Allow-Origin', '*') return response
def handle_options(self, request, entity): """Repond to OPTIONS requests with a status code of 200 and the allowed request methods. """ if request.environ["SERVER_PROTOCOL"] != "HTTP/1.1": # OPTIONS does not exist in HTTP/1.0 raise NotImplemented() if entity: if not entity == '*': self.validate_entity(entity) elif pop_path_info(request.environ) is not None: # There's more than a single asterisk in the request uri raise BadRequest() else: return Response(status=200, headers=[("Allow", "GET, HEAD, OPTIONS")]) req_mbid = shift_path_info(request.environ) self.validate_mbid(req_mbid) image_id = shift_path_info(request.environ) if image_id and image_id is not None: image_id = splitext(image_id)[0] _split = image_id.split('-') if len(_split) > 0: id_text = _split[0] try: int(id_text) except ValueError: if id_text not in ('front', 'back'): raise BadRequest() else: get_sentry().captureException() if len(_split) > 1: size = _split[1] if size not in ('250', '500'): raise BadRequest() return Response(status=200, headers=[("Allow", "GET, HEAD, OPTIONS")])
def handle_options(self, request, entity): """Repond to OPTIONS requests with a status code of 200 and the allowed request methods. """ if request.environ["SERVER_PROTOCOL"] != "HTTP/1.1": # OPTIONS does not exist in HTTP/1.0 raise NotImplemented() if entity: if not entity == '*': self.validate_entity(entity) elif pop_path_info(request.environ) is not None: # There's more than a single asterisk in the request uri raise BadRequest() else: return Response(status=200, headers=[("Allow", "GET, HEAD, OPTIONS")]) req_mbid = shift_path_info(request.environ) self.validate_mbid(req_mbid) image_id = shift_path_info(request.environ) if image_id and image_id is not None: image_id = splitext(image_id)[0] _split = image_id.split('-') if len(_split) > 0: id_text = _split[0] try: int(id_text) except ValueError: if id_text not in ('front', 'back'): raise BadRequest() else: get_sentry().captureException() if len(_split) > 1: size = _split[1] if size not in ('250', '500', '1200'): raise BadRequest() return Response(status=200, headers=[("Allow", "GET, HEAD, OPTIONS")])