# Path: norm/interface.py
# class IOperator(Interface):
#     """
#     I provide functions for doing operations.  My methods are suitable for
#     use as the function in L{IRunner.runInteraction}.
#     """
# 
# 
#     def insert(cursor, obj):
#         """
#         Insert the ORM object into the database, update the object's attributes
#         and return the object.
#         """
# 
# 
#     def query(cursor, query):
#         """
#         XXX
#         """
# 
# 
#     def refresh(cursor, obj):
#         """
#         XXX
#         """
# 
# 
#     def update(cursor, obj):
#         """
#         XXX
#         """
# 
# 
#     def delete(cursor, obj):
#         """
#         XXX
#         """
# 
# Path: norm/orm/props.py
# class Int(Property):
#     
# 
#     def _validate(self, prop, obj, value):
#         if value is None:
#             return value
#         if type(value) not in (int, long):
#             raise TypeError('%r must be an integer, not %r' % (prop, value))
#         return value
# 
# class String(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), str):
#             raise TypeError('%r must be a str, not %r' % (prop, value))
#         return value
# 
# class Unicode(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), unicode):
#             raise TypeError('%r must be a unicode, not %r' % (prop, value))
#         return value
# 
# class Date(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), date):
#             raise TypeError('%r must be a date, not %r' % (prop, value))
#         return value
# 
# class DateTime(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), datetime):
#             raise TypeError('%r must be a datetime, not %r' % (prop, value))
#         return value
# 
# class Bool(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if value is None:
#             return None
#         if type(value) not in (bool, int):
#             raise TypeError('%r must be a boolean, not %r' % (prop, value))
#         return bool(value)
# 
# Path: norm/orm/expr.py
# class Query(object):
#     """
#     I am a query for a set of objects.  Pass me to L{IOperator.query}.
#     """
# 
# 
#     def __init__(self, select, *constraints, **kwargs):
#         """
#         @param select: Class(es) to return in the result.  This may either be
#             a single class or a list/tuple of classes.
#         @param constraints: A L{Comparison} or other compileable expression.
# 
#         @param kwargs:
#             joins
#         """
#         if type(select) not in (list, tuple):
#             select = (select,)
#         self.select = select
#         if constraints:
#             self.constraints = And(*constraints)
#         else:
#             self.constraints = None
#         self.joins = kwargs.pop('joins', None) or []
#         self._classes = []
#         self._props = []
#         self._process()
# 
# 
#     def _process(self):
#         self._classes = []
#         self._props = []
#         for item in self.select:
#             info = classInfo(item)
#             keys = sorted(info.attributes.values())
#             self._props.extend(keys)
#             self._classes.append(item)
# 
# 
#     def properties(self):
#         """
#         Get a tuple of the Properties that will be returned by the query.
#         """
#         return tuple(self._props)
# 
# 
#     def classes(self):
#         """
#         Return a list of classes involved in the query.
#         """
#         return self._classes
# 
# 
#     def find(self, select, constraints=None, joins=None):
#         """
#         Search for another kind of object with additional constraints.
#         """
#         all_constraints = [x for x in [self.constraints, constraints] if x]
#         joins = joins or []
#         return Query(select, *all_constraints, joins=self.joins + joins)
# 
# class Eq(Comparison):
#     op = '='
# 
# class And(LogicalBinaryOp):
#     join = ' AND '
# 
# class LeftJoin(Join):
# 
#     oper = 'LEFT JOIN'
# 
# Path: norm/orm/error.py
# class NotFound(Error):
#     pass
# 
# Path: norm/porcelain.py
# def ormHandle(pool):
#     operator = None
#     if pool.db_scheme == 'sqlite':
#         from norm.sqlite import SqliteOperator
#         operator = SqliteOperator()
#     elif pool.db_scheme == 'postgres':
#         from norm.postgres import PostgresOperator
#         operator = PostgresOperator()
#     return ORMHandle(pool, operator)


from twisted.internet import defer
from zope.interface.verify import verifyObject
from datetime import datetime, date
from norm.interface import IOperator
from norm.orm.props import Int, String, Unicode, Date, DateTime, Bool
from norm.orm.expr import Query, Eq, And, LeftJoin
from norm.orm.error import NotFound
from norm import ormHandle


class Defaults(object):
    __sql_table__ = 'with_defaults'
    id = Int(primary=True)
    name = String()
    uni = Unicode()
    date = Date()
    dtime = DateTime()
    mybool = Bool()


class Parent(object):
    __sql_table__ = 'parent'
    id = Int(primary=True)
    name = Unicode()


class Child(object):
    __sql_table__ = 'child'
    id = Int(primary=True)
    name = Unicode()
    parent_id = Int()

    def __init__(self, name=None):
        self.name = name


class FavoriteBook(object):
    __sql_table__ = 'favorite_book'

# Path: norm/interface.py
# class IOperator(Interface):
#     """
#     I provide functions for doing operations.  My methods are suitable for
#     use as the function in L{IRunner.runInteraction}.
#     """
# 
# 
#     def insert(cursor, obj):
#         """
#         Insert the ORM object into the database, update the object's attributes
#         and return the object.
#         """
# 
# 
#     def query(cursor, query):
#         """
#         XXX
#         """
# 
# 
#     def refresh(cursor, obj):
#         """
#         XXX
#         """
# 
# 
#     def update(cursor, obj):
#         """
#         XXX
#         """
# 
# 
#     def delete(cursor, obj):
#         """
#         XXX
#         """
# 
# Path: norm/orm/props.py
# class Int(Property):
#     
# 
#     def _validate(self, prop, obj, value):
#         if value is None:
#             return value
#         if type(value) not in (int, long):
#             raise TypeError('%r must be an integer, not %r' % (prop, value))
#         return value
# 
# class String(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), str):
#             raise TypeError('%r must be a str, not %r' % (prop, value))
#         return value
# 
# class Unicode(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), unicode):
#             raise TypeError('%r must be a unicode, not %r' % (prop, value))
#         return value
# 
# class Date(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), date):
#             raise TypeError('%r must be a date, not %r' % (prop, value))
#         return value
# 
# class DateTime(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if type(value) not in (type(None), datetime):
#             raise TypeError('%r must be a datetime, not %r' % (prop, value))
#         return value
# 
# class Bool(Property):
# 
# 
#     def _validate(self, prop, obj, value):
#         if value is None:
#             return None
#         if type(value) not in (bool, int):
#             raise TypeError('%r must be a boolean, not %r' % (prop, value))
#         return bool(value)
# 
# Path: norm/orm/expr.py
# class Query(object):
#     """
#     I am a query for a set of objects.  Pass me to L{IOperator.query}.
#     """
# 
# 
#     def __init__(self, select, *constraints, **kwargs):
#         """
#         @param select: Class(es) to return in the result.  This may either be
#             a single class or a list/tuple of classes.
#         @param constraints: A L{Comparison} or other compileable expression.
# 
#         @param kwargs:
#             joins
#         """
#         if type(select) not in (list, tuple):
#             select = (select,)
#         self.select = select
#         if constraints:
#             self.constraints = And(*constraints)
#         else:
#             self.constraints = None
#         self.joins = kwargs.pop('joins', None) or []
#         self._classes = []
#         self._props = []
#         self._process()
# 
# 
#     def _process(self):
#         self._classes = []
#         self._props = []
#         for item in self.select:
#             info = classInfo(item)
#             keys = sorted(info.attributes.values())
#             self._props.extend(keys)
#             self._classes.append(item)
# 
# 
#     def properties(self):
#         """
#         Get a tuple of the Properties that will be returned by the query.
#         """
#         return tuple(self._props)
# 
# 
#     def classes(self):
#         """
#         Return a list of classes involved in the query.
#         """
#         return self._classes
# 
# 
#     def find(self, select, constraints=None, joins=None):
#         """
#         Search for another kind of object with additional constraints.
#         """
#         all_constraints = [x for x in [self.constraints, constraints] if x]
#         joins = joins or []
#         return Query(select, *all_constraints, joins=self.joins + joins)
# 
# class Eq(Comparison):
#     op = '='
# 
# class And(LogicalBinaryOp):
#     join = ' AND '
# 
# class LeftJoin(Join):
# 
#     oper = 'LEFT JOIN'
# 
# Path: norm/orm/error.py
# class NotFound(Error):
#     pass
# 
# Path: norm/porcelain.py
# def ormHandle(pool):
#     operator = None
#     if pool.db_scheme == 'sqlite':
#         from norm.sqlite import SqliteOperator
#         operator = SqliteOperator()
#     elif pool.db_scheme == 'postgres':
#         from norm.postgres import PostgresOperator
#         operator = PostgresOperator()
#     return ORMHandle(pool, operator)


# Path: norm/orm/test/mixin.py
from twisted.internet import defer
from zope.interface.verify import verifyObject
from datetime import datetime, date
from norm.interface import IOperator
from norm.orm.props import Int, String, Unicode, Date, DateTime, Bool
from norm.orm.expr import Query, Eq, And, LeftJoin
from norm.orm.error import NotFound
from norm import ormHandle



class Defaults(object):
    __sql_table__ = 'with_defaults'
    id = Int(primary=True)
    name = String()
    uni = Unicode()
    date = Date()
    dtime = DateTime()
    mybool = Bool()


class Parent(object):
    __sql_table__ = 'parent'
    id = Int(primary=True)
    name = Unicode()


class Child(object):
    __sql_table__ = 'child'
    id = Int(primary=True)
    name = Unicode()
    parent_id = Int()

    def __init__(self, name=None):
        self.name = name


class FavoriteBook(object):
    __sql_table__ = 'favorite_book'

    child_id = Int(primary=True)