<commit_before>#!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""Main file"""

import os
import bottle
from io import BytesIO
import qrcode

from handlers.settings import LOGGER, PROJECT_PATH, PRODUCTION, MEDIA, PREFIX
from handlers.t34base import T34GenExt, MongoEx, StripPathMiddleware
from handlers.t34methods import T34Url
from functools import lru_cache

@bottle.get('/')
@lru_cache(2)
def index():
    """index page"""
    LOGGER.debug('index')
    return bottle.template('index')

@bottle.post('/')
def result():
    """create/update an item for icoming URL address"""
    value = bottle.request.forms.longurl
    if not value.strip():
        bottle.redirect("/")
    try:
        obj = T34Url()
        returned_link = obj.create(value)
        if not returned_link:
            LOGGER.warning("can not add link: {0}".format(value))
            raise T34GenExt()
        result_link = PREFIX + returned_link
        if obj.newest:
            obj.complement({
                "api": False,
                "method": bottle.request.method,
                "raddr": bottle.request.remote_addr,
                "rroute": bottle.request.remote_route
            })
    except (T34GenExt, MongoEx) as err:
        LOGGER.warning(err)
        raise bottle.HTTPError(500)
    return bottle.template('result', var=result_link, dirty=returned_link)

@bottle.get('/<link:re:[0-9a-zA-Z]+>')<commit_msg>minor changes<commit_after>#!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""Main file"""

import os
import bottle
import qrcode

from handlers.settings import LOGGER, PROJECT_PATH, PRODUCTION, MEDIA, PREFIX
from handlers.t34base import T34GenExt, MongoEx, StripPathMiddleware #, debug_profiler
from handlers.t34methods import T34Url

from io import BytesIO
from functools import lru_cache

@bottle.get('/')
@lru_cache(2)
def index():
    """index page"""
    # LOGGER.debug('index')
    return bottle.template('index')

@bottle.post('/')
def result():
    """create/update an item for icoming URL address"""
    value = bottle.request.forms.longurl
    if not value.strip():
        bottle.redirect("/")
    try:
        obj = T34Url()
        returned_link = obj.create(value)
        if not returned_link:
            LOGGER.warning("can not add link: {0}".format(value))
            raise T34GenExt()
        result_link = PREFIX + returned_link
        if obj.newest:
            obj.complement({
                "api": False,
                "method": bottle.request.method,
                "raddr": bottle.request.remote_addr,
                "rroute": bottle.request.remote_route
            })
    except (T34GenExt, MongoEx) as err:
        LOGGER.warning(err)
        raise bottle.HTTPError(500)
    return bottle.template('result', var=result_link, dirty=returned_link)

@bottle.get('/<link:re:[0-9a-zA-Z]+>')
{'fraction_non_alphanumeric': 0.12876906704505145, 'fraction_numerical': 0.016317843206810925, 'mean_word_length': 2.76, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4753843', 'n_tokens_mistral': 927, 'n_tokens_neox': 894, 'n_words': 211}