<commit_before>from pyramid.view import view_config
from pyramid.response import Response
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotAcceptable
import logging
import qrcode
import StringIO
import re

log = logging.getLogger(__name__)


class Qr(object):

    def __init__(self, request):
        self.request = request
        self.regex = re.compile(
                '^http[s]{0,1}://.*[g-o|geoportal|geoportail]{1}.lu.*$')

    @view_config(route_name='qr')
    def getqrcode(self):
        url = self.request.params.get('url', '')
        if len(url) == 0:
            return HTTPBadRequest()
        if not self.regex.match(url):
            return HTTPNotAcceptable(
                    "not a valid url for this QR code generator")
        qr = qrcode.QRCode(
                 version=1,
                 error_correction=qrcode.constants.ERROR_CORRECT_L,
                 box_size=3,
                 border=0
        )
        qr.add_data(url)
        qr.make(fit=True)
        im = qr.make_image()
        output = StringIO.StringIO()
        im.save(output)
        headers = {"Content-Type": 'image/png'}
        return Response(output.getvalue(), headers=headers)<commit_msg>overindentation<commit_after>from pyramid.view import view_config
from pyramid.response import Response
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotAcceptable
import logging
import qrcode
import StringIO
import re

log = logging.getLogger(__name__)


class Qr(object):

    def __init__(self, request):
        self.request = request
        self.regex = re.compile(
            '^http[s]{0,1}://.*[g-o|geoportal|geoportail]{1}.lu.*$')

    @view_config(route_name='qr')
    def getqrcode(self):
        url = self.request.params.get('url', '')
        if len(url) == 0:
            return HTTPBadRequest()
        if not self.regex.match(url):
            return HTTPNotAcceptable(
                "not a valid url for this QR code generator")
        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=3,
            border=0
        )
        qr.add_data(url)
        qr.make(fit=True)
        im = qr.make_image()
        output = StringIO.StringIO()
        im.save(output)
        headers = {"Content-Type": 'image/png'}
        return Response(output.getvalue(), headers=headers)
{'fraction_non_alphanumeric': 0.1118587047939445, 'fraction_numerical': 0.005887300252312868, 'mean_word_length': 2.3179916317991633, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3591934', 'n_tokens_mistral': 744, 'n_tokens_neox': 701, 'n_words': 151}