<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import cgi
import re

from datetime import datetime

from wtforms import Form as WTForm, Field, validators, fields, widgets
from wtforms.fields import html5

from weckan import model, urls, conf

_ = lambda s: s

STORAGE_BUCKET = 'default'

RE_TAG = re.compile('^[\w \-.]*$', re.U)


def handle_upload(request, field, user=None):
    from ckan.controllers import storage

    if not isinstance(field.data, cgi.FieldStorage):
        return None

    filename = '{ts:%Y-%m-%dT%H-%M-%S}/{name}'.format(name=field.data.filename, ts=datetime.now())
    ofs = storage.get_ofs()
    ofs.put_stream(STORAGE_BUCKET, filename, field.data.file, {
        'filename-original': field.data.filename,
        'uploaded-by': user.name if user else '',
    })
    root = conf['home_url']
    if root.startswith('//'):
        root = root.replace('//', 'https://' if conf['https'] else 'http://', 1)
    path = urls.get_url(None, 'storage/f', filename)
    return ''.join([root, path])


class Form(WTForm):
    def __init__(self, *args, **kwargs):
        self.i18n = kwargs.pop('i18n', None)
        super(Form, self).__init__(*args, **kwargs)

    def _get_translations(self):
        return self.i18n


class FieldHelper(object):
    @property
    def id(self):<commit_msg>Slugify filenames<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import cgi
import re

from datetime import datetime
from os.path import splitext

from biryani1 import strings
from wtforms import Form as WTForm, Field, validators, fields, widgets
from wtforms.fields import html5

from weckan import model, urls, conf

_ = lambda s: s

STORAGE_BUCKET = 'default'

RE_TAG = re.compile('^[\w \-.]*$', re.U)


def handle_upload(request, field, user=None):
    from ckan.controllers import storage

    if not isinstance(field.data, cgi.FieldStorage):
        return None

    filename, ext = splitext(field.data.filename)
    filename = strings.slugify(filename)
    filename = ''.join([filename, ext])
    filename = '{ts:%Y-%m-%dT%H-%M-%S}/{name}'.format(name=filename, ts=datetime.now())
    ofs = storage.get_ofs()
    ofs.put_stream(STORAGE_BUCKET, filename, field.data.file, {
        'filename-original': field.data.filename,
        'uploaded-by': user.name if user else '',
    })
    root = conf['home_url']
    if root.startswith('//'):
        root = root.replace('//', 'https://' if conf['https'] else 'http://', 1)
    path = urls.get_url(None, 'storage/f', filename)
    return ''.join([root, path])


class Form(WTForm):
    def __init__(self, *args, **kwargs):
        self.i18n = kwargs.pop('i18n', None)
        super(Form, self).__init__(*args, **kwargs)

    def _get_translations(self):
        return self.i18n


class FieldHelper(object):
    @property
    def id(self):
{'fraction_non_alphanumeric': 0.1509433962264151, 'fraction_numerical': 0.006638714185883997, 'mean_word_length': 3.431888544891641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1496587', 'n_tokens_mistral': 985, 'n_tokens_neox': 958, 'n_words': 240}