Example #1
0
    def action_file_upload(self):
        with DB.transaction():
            package_name = self.get_body_argument('name').lower()

            if not Package.select().where(
                    Package.lower_name == package_name).count():
                raise HTTPError(404)

            package = Package.get(lower_name=package_name)

            if package.owner != self.current_user and not self.current_user.is_admin:
                raise HTTPError(403)

            version = package.create_version(self.get_body_argument('version'))

            uploaded_file = self.request.files['content'][0]
            if not str(hashlib.md5(uploaded_file.body).hexdigest()) == str(
                    self.get_body_argument('md5_digest')):
                raise HTTPError(406)

            list_values = (u'classifiers', u'keywords')
            for key in self.METADATA_KEYS:
                val = self.get_body_argument(key, 'UNKNOWN')
                if key in list_values and not isinstance(val, (list, tuple)):
                    val = [val]

                setattr(version, key, val)

            version.save()

            try:
                pkg_file = version.create_file(uploaded_file.filename)
                pkg_file.fetched = True
                pkg_file.md5 = str(self.get_body_argument('md5_digest'))

                if pkg_file.exists():
                    raise HTTPError(409)

                with pkg_file.open("wb+") as f:
                    f.write(uploaded_file.body)

                pkg_file.save()
            except peewee.DataError:
                raise HTTPError(409)
Example #2
0
    def action_file_upload(self):
        with DB.transaction():
            package_name = self.get_body_argument('name').lower()

            if not Package.select().where(Package.lower_name == package_name).count():
                raise HTTPError(404)

            package = Package.get(lower_name=package_name)

            if package.owner != self.current_user and not self.current_user.is_admin:
                raise HTTPError(403)

            version = package.create_version(self.get_body_argument('version'))

            uploaded_file = self.request.files['content'][0]
            if not str(hashlib.md5(uploaded_file.body).hexdigest()) == str(self.get_body_argument('md5_digest')):
                raise HTTPError(406)

            list_values = (u'classifiers', u'keywords')
            for key in self.METADATA_KEYS:
                val = self.get_body_argument(key, 'UNKNOWN')
                if key in list_values and not isinstance(val, (list, tuple)):
                    val = [val]

                setattr(version, key, val)

            version.save()

            try:
                pkg_file = version.create_file(uploaded_file.filename)
                pkg_file.fetched = True
                pkg_file.md5 = str(self.get_body_argument('md5_digest'))

                if pkg_file.exists():
                    raise HTTPError(409)

                with pkg_file.open("wb+") as f:
                    f.write(uploaded_file.body)

                pkg_file.save()
            except peewee.DataError:
                raise HTTPError(409)
Example #3
0
    def tearDown(self):
        DB.close()
        self.__db_file.close()

        super(TestCase, self).tearDown()
Example #4
0
    def tearDown(self):
        DB.close()
        self.__db_file.close()

        super(TestCase, self).tearDown()