Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from aiohttp import client_exceptions
from gino.ext.aiohttp import Gino
from .operators import operators, operators_by_id, operator_names, operator_logos
from .render import render_station_arrivals, render_operator_index, render_route_alternatives, render_route_map, render_station_list
from .siri import SIRIClient
from .gtfs.utils import (get_stop_info, get_routes, get_route_route,
get_arrival_gtfs_info, translate_route_name,
count_routes, get_rail_stations, get_nearby_stops)
from .gtfs import model as gtfs_model
from .html import html_template, relative_linkify
from aiocache import SimpleMemoryCache
import os.path
import ansi2html
# monkey-patch ansi2html to get a more modern HTML document structure and a footer
ansi2html.converter._html_template = html_template
ansi2html.converter.linkify = relative_linkify
CACHE_TTL = 30
ANSI_RESET = "\033[0m\033[39m\033[49m"
def parse_accept_header(request):
""" Returns `json`, `html`, or `text` according to the accept header """
# This doesn't care for priorities, it'll take the first guess
accept = request.headers.getall('ACCEPT', [])
for item in accept:
for sub_item in item.lower().split(','):
if "text/html" in sub_item:
return 'html'
if "application/json" in sub_item:
return 'json'
if "*/*" in sub_item:
return 'text'
"""HTML template for curlbus + ansi2html """
from ansi2html.converter import linkify
import re
original_linkify = linkify
relative_url = re.compile(r"(│|\s|^)((?:\/\w+)+)")
def relative_linkify(line, latex_mode):
""" Override ansi2html linkify to add support for relative links """
modified = original_linkify(line, latex_mode)
return relative_url.sub(r'\1<a class="curlbusrelative" href="\2">\2</a>', modified)
html_template = """