# Path: papaye/factories/root.py
# def user_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['user']
# 
# def repository_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['repository']
# 
# APP_ROOT_NAME = '{}_root'.format(APP_NAME)
# 
# Path: papaye/schemas.py
# class Metadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = colander.SchemaNode(Description(), default=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)


import datetime
import hashlib
import io
import json
import logging
import magic
import pkg_resources
import requests
from BTrees.OOBTree import OOBTree
from ZODB.blob import Blob
from beaker.cache import cache_region
from persistent import Persistent
from pkg_resources import parse_version
from pyramid.security import Allow, ALL_PERMISSIONS, Everyone
from pyramid.threadlocal import get_current_registry
from pyramid_zodbconn import db_from_uri
from repoze.evolution import ZODBEvolutionManager
from requests.exceptions import ConnectionError
from pytz import utc
from papaye.factories.root import user_root_factory, repository_root_factory, APP_ROOT_NAME
from papaye.schemas import Metadata
        self.set_content(content)
        self.upload_date = datetime.datetime.now(tz=utc)

    def get_content_type(self, content):
        buf = io.BytesIO(content)
        with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
            self.content_type = m.id_buffer(buf.read())

    def set_content(self, content):
        self.content = Blob(content)
        self.content_type = self.get_content_type(content)
        self.size = len(content)


class User(Persistent):

    def __init__(self, username, password, **kwargs):
        self.username = username
        self.password = self.hash_password(password)
        self.groups = kwargs.get('groups', [])

    def hash_password(self, password):
        return hashlib.sha512(password.encode('utf-8')).hexdigest()

    def password_verify(self, clear_password):
        return self.hash_password(clear_password) == self.password

    @classmethod
    def by_username(cls, username, request):
        """Return user instance by username"""

# Path: papaye/factories/root.py
# def user_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['user']
# 
# def repository_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['repository']
# 
# APP_ROOT_NAME = '{}_root'.format(APP_NAME)
# 
# Path: papaye/schemas.py
# class Metadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = colander.SchemaNode(Description(), default=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)


# Path: papaye/evolve/models/snapshot1.py
import datetime
import hashlib
import io
import json
import logging
import magic
import pkg_resources
import requests
from BTrees.OOBTree import OOBTree
from ZODB.blob import Blob
from beaker.cache import cache_region
from persistent import Persistent
from pkg_resources import parse_version
from pyramid.security import Allow, ALL_PERMISSIONS, Everyone
from pyramid.threadlocal import get_current_registry
from pyramid_zodbconn import db_from_uri
from repoze.evolution import ZODBEvolutionManager
from requests.exceptions import ConnectionError
from pytz import utc
from papaye.factories.root import user_root_factory, repository_root_factory, APP_ROOT_NAME
from papaye.schemas import Metadata

        self.set_content(content)
        self.upload_date = datetime.datetime.now(tz=utc)

    def get_content_type(self, content):
        buf = io.BytesIO(content)
        with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
            self.content_type = m.id_buffer(buf.read())

    def set_content(self, content):
        self.content = Blob(content)
        self.content_type = self.get_content_type(content)
        self.size = len(content)


class User(Persistent):

    def __init__(self, username, password, **kwargs):
        self.username = username
        self.password = self.hash_password(password)
        self.groups = kwargs.get('groups', [])

    def hash_password(self, password):
        return hashlib.sha512(password.encode('utf-8')).hexdigest()

    def password_verify(self, clear_password):
        return self.hash_password(clear_password) == self.password

    @classmethod
    def by_username(cls, username, request):
        """Return user instance by username"""

        root = user_root_factory(request)