# Path: playa/ext/zodb.py
# class ZODB(IterableUserDict):
# class Factory(object):
# class Model(Persistent):
#     def __init__(self, app=None):
#     def init(self, cb):
#     def db(self):
#     def connection(self):
#     def connection(self, new):
#     def root(self):
#     def data(self):
#     def init_app(self, app):
#         def open_db():
#         def close_db(response):
#     def transaction(self, db=None):
#     def __call__(self):
#     def __init__(self, callable, *args, **kwargs):
#     def __call__(self):
#     def __init__(self, **kwargs):
#     def __repr__(self):
# UUID4 = Factory(uuid4)


from BTrees.OOBTree import OOBTree
from playa.ext.zodb import Model, Timestamp, Boolean, \
                           UUID4, List
import bcrypt
import uuid
class User(Model):
    username = None
    password = None
    date_created = Timestamp
    
    def __unicode__(self):
        return self.username

    def check_password(self, password):
        salt, hash = self.password.split('$', 1)

        return bcrypt.hashpw(password, salt) == hash

    def set_password(self, password):
        salt = bcrypt.gensalt()

        self.password = bcrypt.hashpw(password, salt)

class Playlists(OOBTree):
    def new(self, name, owner=None):
        id = uuid.uuid4().hex
        playlist = Playlist(id=id, name=name, owner=owner)
        self[id] = playlist
        return playlist

class Playlist(Model):
    id = UUID4
    name = None
    owner = User
    collaborative = Boolean

# Path: playa/ext/zodb.py
# class ZODB(IterableUserDict):
# class Factory(object):
# class Model(Persistent):
#     def __init__(self, app=None):
#     def init(self, cb):
#     def db(self):
#     def connection(self):
#     def connection(self, new):
#     def root(self):
#     def data(self):
#     def init_app(self, app):
#         def open_db():
#         def close_db(response):
#     def transaction(self, db=None):
#     def __call__(self):
#     def __init__(self, callable, *args, **kwargs):
#     def __call__(self):
#     def __init__(self, **kwargs):
#     def __repr__(self):
# UUID4 = Factory(uuid4)


# Path: playa/models.py
from BTrees.OOBTree import OOBTree
from playa.ext.zodb import Model, Timestamp, Boolean, \
                           UUID4, List
import bcrypt
import uuid

class User(Model):
    username = None
    password = None
    date_created = Timestamp
    
    def __unicode__(self):
        return self.username

    def check_password(self, password):
        salt, hash = self.password.split('$', 1)

        return bcrypt.hashpw(password, salt) == hash

    def set_password(self, password):
        salt = bcrypt.gensalt()

        self.password = bcrypt.hashpw(password, salt)

class Playlists(OOBTree):
    def new(self, name, owner=None):
        id = uuid.uuid4().hex
        playlist = Playlist(id=id, name=name, owner=owner)
        self[id] = playlist
        return playlist

class Playlist(Model):
    id = UUID4
    name = None
    owner = User
    collaborative = Boolean

    date_created = Timestamp