<commit_before># -*- coding: utf-8 -*-
"""
PyShop Simple View.

simple view are html views scrapped by pip in order to download
release files.
"""
import re
import logging
import os.path
from datetime import datetime

from sqlalchemy.sql.expression import func

from pyramid import httpexceptions as exc
from pyramid.settings import asbool
from pyramid.security import authenticated_userid

from pyshop.models import User, Package, Classifier, Release, ReleaseFile
from pyshop.helpers import pypi

from .base import View


log = logging.getLogger(__name__)


class List(View):

    def render(self):
        return {'packages': Package.all(self.session, order_by=Package.name)}


class UploadReleaseFile(View):

    def render(self):
        settings = self.request.registry.settings
        if not self.user:
            raise exc.HTTPForbidden()

        params = self.request.params

        if (asbool(settings['pyshop.upload.satanize'])
            and not re.match(settings['pyshop.upload.satanize.regex'],
                             params['version']
                             )):
            raise exc.HTTPForbidden()

        print type(params['name'])
        pkg = Package.by_name(self.session, params['name'])
        if pkg:
            auth = [user for user in pkg.owners + pkg.maintainers
                    if user == self.user]
            if not auth:
                raise exc.HTTPForbidden()
        else:
            pkg = Package(name=params['name'], local=True)
            pkg.owners.append(self.user)

        content = self.request.POST['content']
        input_file = content.file
        # rewrite the filename, do not use the posted one for security
        filename = u'%s-%s.%s' % (params['name'], params['version'],
                                  {u'sdist': u'tar.gz',
                                   u'bdist_egg': u'egg',
                                   u'bdist_msi': u'msi',
                                   u'bdist_dmg': u'zip',  # XXX or gztar ?<commit_msg>Remove print statement<commit_after># -*- coding: utf-8 -*-
"""
PyShop Simple View.

simple view are html views scrapped by pip in order to download
release files.
"""
import re
import logging
import os.path
from datetime import datetime

from sqlalchemy.sql.expression import func

from pyramid import httpexceptions as exc
from pyramid.settings import asbool
from pyramid.security import authenticated_userid

from pyshop.models import User, Package, Classifier, Release, ReleaseFile
from pyshop.helpers import pypi

from .base import View


log = logging.getLogger(__name__)


class List(View):

    def render(self):
        return {'packages': Package.all(self.session, order_by=Package.name)}


class UploadReleaseFile(View):

    def render(self):
        settings = self.request.registry.settings
        if not self.user:
            raise exc.HTTPForbidden()

        params = self.request.params

        if (asbool(settings['pyshop.upload.satanize'])
            and not re.match(settings['pyshop.upload.satanize.regex'],
                             params['version']
                             )):
            raise exc.HTTPForbidden()

        pkg = Package.by_name(self.session, params['name'])
        if pkg:
            auth = [user for user in pkg.owners + pkg.maintainers
                    if user == self.user]
            if not auth:
                raise exc.HTTPForbidden()
        else:
            pkg = Package(name=params['name'], local=True)
            pkg.owners.append(self.user)

        content = self.request.POST['content']
        input_file = content.file
        # rewrite the filename, do not use the posted one for security
        filename = u'%s-%s.%s' % (params['name'], params['version'],
                                  {u'sdist': u'tar.gz',
                                   u'bdist_egg': u'egg',
                                   u'bdist_msi': u'msi',
                                   u'bdist_dmg': u'zip',  # XXX or gztar ?
{'fraction_non_alphanumeric': 0.10165247871807712, 'fraction_numerical': 0.000500751126690035, 'mean_word_length': 2.0150943396226415, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114075', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1063, 'n_words': 304}