<commit_before>#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#

from functools import wraps
from io import BytesIO
import re
import unicodecsv as csv

from flask import session, abort, request, make_response, g
from flask_login import current_user, login_required
from werkzeug.datastructures import Headers
from werkzeug.wrappers import Response

import oclubs
from oclubs.exceptions import NoRow
from oclubs.enums import UserType


@login_required
def upload_picture(club):
    '''Handle upload object'''
    file = request.files['picture']
    oclubs.objs.Upload.handle(current_user, club, file)


def download_csv(filename, header, info):
    '''Create csv file for given info and download it'''
    # header as list, info as list of list
    def generate():
        yield ','.join(header) + '\n'
        for row in info:
            yield ','.join(row) + '\n'
    headers = Headers()
    headers.set('Content-Disposition', 'attachment', filename=filename)
    return Response(generate(), mimetype='text/csv', headers=headers)
    # f = BytesIO()
    # w = csv.writer(f, encoding='utf-16')
    # _ = w.writerow(header)
    # _ = f.seek(0)


def get_callsign(objtype, kw=None):
    def decorator(func):
        @wraps(func)
        def decorated_function(*args, **kwargs):
            try:
                item = int(re.match(r'^\d+', kwargs[kw]).group(0))<commit_msg>shared: get_callsign have kw required<commit_after>#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#

from functools import wraps
from io import BytesIO
import re
import unicodecsv as csv

from flask import session, abort, request, make_response, g
from flask_login import current_user, login_required
from werkzeug.datastructures import Headers
from werkzeug.wrappers import Response

import oclubs
from oclubs.exceptions import NoRow
from oclubs.enums import UserType


@login_required
def upload_picture(club):
    '''Handle upload object'''
    file = request.files['picture']
    oclubs.objs.Upload.handle(current_user, club, file)


def download_csv(filename, header, info):
    '''Create csv file for given info and download it'''
    # header as list, info as list of list
    def generate():
        yield ','.join(header) + '\n'
        for row in info:
            yield ','.join(row) + '\n'
    headers = Headers()
    headers.set('Content-Disposition', 'attachment', filename=filename)
    return Response(generate(), mimetype='text/csv', headers=headers)
    # f = BytesIO()
    # w = csv.writer(f, encoding='utf-16')
    # _ = w.writerow(header)
    # _ = f.seek(0)


def get_callsign(objtype, kw):
    def decorator(func):
        @wraps(func)
        def decorated_function(*args, **kwargs):
            try:
                item = int(re.match(r'^\d+', kwargs[kw]).group(0))
{'fraction_non_alphanumeric': 0.12450235251538183, 'fraction_numerical': 0.003619254433586681, 'mean_word_length': 3.436597110754414, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2047041', 'n_tokens_mistral': 885, 'n_tokens_neox': 862, 'n_words': 249}