# Path: doodle/core/models/base_model.py
# class PropertiedModel(SimpleModel):
#     __metaclass__ = PropertiedClass
# 
#     def __init__(self, **kwargs):
#         super(PropertiedModel, self).__init__()
#         self._attributes = {}  # stores real values
# 
#         for attr_name in self._properties.iterkeys():
#             attr_value = kwargs.get(attr_name)
#             setattr(self, attr_name, attr_value)
# 
#     def to_dict(self):
#         return self._attributes.copy()
# 
#     def __eq__(self, other):
#         if type(self) is type(other) and self._attributes == other._attributes:
#             return True
#         return False
# 
# Path: doodle/core/property.py
# class BooleanProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             return bool(value)
# 
# class DateTimeProperty(Property):
#     def __init__(self, auto_now=False, **kwargs):
#         super(DateTimeProperty, self).__init__(**kwargs)
#         self.auto_now = auto_now
# 
#     def validate(self, value):
#         if value is not None:
#             if isinstance(value, datetime):
#                 return datetime_to_timestamp(value)
#             try:
#                 value = int(value)
#             except ValueError:
#                 raise ValueError('Property %s must be a timestamp' % self.name)
#             if value < 0:
#                 raise ValueError('Property %s must be non-negative' % self.name)
#             return value
#         if self.auto_now:
#             return int(time.time())
# 
# class FloatProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             try:
#                 return float(value)
#             except ValueError:
#                 raise ValueError('Property %s must be a float' % self.name)
# 
# class IntegerProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             try:
#                 return int(value)
#             except ValueError:
#                 raise ValueError('Property %s must be an int or long, not a %s'
#                                  % (self.name, value.__class__.__name__))
# 
# class ListProperty(Property):
#     def validate(self, value):
#         if value is None:
#             return []
#         if not hasattr(value, '__iter__'):
#             raise ValueError('Property %s must be iterable' % self.name)
#         if not value:
#             return []
#         if isinstance(value, list):
#             return value
#         return list(value)
# 
#     def is_empty(self, value):
#         return not value
# 
# class Property(object):
#     def __init__(self, name=None):
#         self.name = name
# 
#     def __get__(self, model_instance, model_class):
#         if model_instance is None:
#             return self
#         return model_instance._attributes.get(self.name)
# 
#     def __set__(self, model_instance, value):
#         value = self.validate(value)
#         model_instance._attributes[self.name] = value
# 
#     def validate(self, value):
#         return value
# 
#     def is_empty(self, value):
#         return value is None
# 
# class StringProperty(Property):
#     def validate(self, value):
#         if value is None:
#             return ''
#         if not isinstance(value, basestring):
#             value = str(value)
#         return value
# 
#     def is_empty(self, value):
#         return not value


import calendar
import unittest
from datetime import datetime
from doodle.core.models.base_model import PropertiedModel
from doodle.core.property import BooleanProperty, DateTimeProperty, FloatProperty, IntegerProperty, ListProperty, Property, StringProperty
# -*- coding: utf-8 -*-




class Model1(PropertiedModel):
    pass


class Model2(PropertiedModel):
    KEY = 'm2'

    a = Property()


class Model3(Model2):
    b = Property()


class Model4(Model1):
    a = StringProperty()
    b = IntegerProperty()
    c = BooleanProperty()
    d = FloatProperty()
    e = DateTimeProperty()

# Path: doodle/core/models/base_model.py
# class PropertiedModel(SimpleModel):
#     __metaclass__ = PropertiedClass
# 
#     def __init__(self, **kwargs):
#         super(PropertiedModel, self).__init__()
#         self._attributes = {}  # stores real values
# 
#         for attr_name in self._properties.iterkeys():
#             attr_value = kwargs.get(attr_name)
#             setattr(self, attr_name, attr_value)
# 
#     def to_dict(self):
#         return self._attributes.copy()
# 
#     def __eq__(self, other):
#         if type(self) is type(other) and self._attributes == other._attributes:
#             return True
#         return False
# 
# Path: doodle/core/property.py
# class BooleanProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             return bool(value)
# 
# class DateTimeProperty(Property):
#     def __init__(self, auto_now=False, **kwargs):
#         super(DateTimeProperty, self).__init__(**kwargs)
#         self.auto_now = auto_now
# 
#     def validate(self, value):
#         if value is not None:
#             if isinstance(value, datetime):
#                 return datetime_to_timestamp(value)
#             try:
#                 value = int(value)
#             except ValueError:
#                 raise ValueError('Property %s must be a timestamp' % self.name)
#             if value < 0:
#                 raise ValueError('Property %s must be non-negative' % self.name)
#             return value
#         if self.auto_now:
#             return int(time.time())
# 
# class FloatProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             try:
#                 return float(value)
#             except ValueError:
#                 raise ValueError('Property %s must be a float' % self.name)
# 
# class IntegerProperty(Property):
#     def validate(self, value):
#         if value is not None:
#             try:
#                 return int(value)
#             except ValueError:
#                 raise ValueError('Property %s must be an int or long, not a %s'
#                                  % (self.name, value.__class__.__name__))
# 
# class ListProperty(Property):
#     def validate(self, value):
#         if value is None:
#             return []
#         if not hasattr(value, '__iter__'):
#             raise ValueError('Property %s must be iterable' % self.name)
#         if not value:
#             return []
#         if isinstance(value, list):
#             return value
#         return list(value)
# 
#     def is_empty(self, value):
#         return not value
# 
# class Property(object):
#     def __init__(self, name=None):
#         self.name = name
# 
#     def __get__(self, model_instance, model_class):
#         if model_instance is None:
#             return self
#         return model_instance._attributes.get(self.name)
# 
#     def __set__(self, model_instance, value):
#         value = self.validate(value)
#         model_instance._attributes[self.name] = value
# 
#     def validate(self, value):
#         return value
# 
#     def is_empty(self, value):
#         return value is None
# 
# class StringProperty(Property):
#     def validate(self, value):
#         if value is None:
#             return ''
#         if not isinstance(value, basestring):
#             value = str(value)
#         return value
# 
#     def is_empty(self, value):
#         return not value


# Path: doodle/tests/core/test_property.py
import calendar
import unittest
from datetime import datetime
from doodle.core.models.base_model import PropertiedModel
from doodle.core.property import BooleanProperty, DateTimeProperty, FloatProperty, IntegerProperty, ListProperty, Property, StringProperty

# -*- coding: utf-8 -*-




class Model1(PropertiedModel):
    pass


class Model2(PropertiedModel):
    KEY = 'm2'

    a = Property()


class Model3(Model2):
    b = Property()


class Model4(Model1):
    a = StringProperty()
    b = IntegerProperty()
    c = BooleanProperty()
    d = FloatProperty()
    e = DateTimeProperty()

    f = DateTimeProperty(auto_now=True)