# Path: feedplatform/lib/addins/feeds/collect_feed_data.py
# class base_data_collector(addins.base):
#     """Baseclass for data collector addins.
# 
#     Subclasses should provide at least the ``model_name`` and
#     ``standard_fields`` attributes, and may implement ``_get_value``
#     for additional processing.
# 
#     ``standard_fields`` should be a dict in the form (name => field),
#     with ``field`` being a database field instance or creation tuple,
#     and name being both the model column name and the key name to use
#     when reading the value from the feed parser source dict. If you
#     want the model field name to differ from the source field, you may
#     specifiy a dict for ``field``:
# 
#         'href': {'target': 'image_href', 'field': (Unicode, (), {})}
# 
#     See also ``collect_feed_data`` and other subclasses for information
#     about how these collectors can be called and used from the end-user
#     perspective - much of that functionality is implemented here in the
#     base class.
#     """
# 
#     abstract = True
# 
#     USE_DEFAULT = object()
# 
#     # provide in subclass
#     model_name = None
#     standard_fields = None
#     date_fields = None
# 
#     # Provide special fields that every subclass supports.
#     class __metaclass__(type(addins.base)):
#         def __new__(cls, name, bases, attrs):
#             result = type(addins.base).__new__(cls, name, bases, attrs)
#             if result.standard_fields is not None:
#                 standard_fields = result.standard_fields
#                 result.standard_fields = {'__now': (DateTime, (), {})}
#                 result.standard_fields.update(standard_fields)
#             return result
# 
#     def __init__(self, *args, **kwargs):
#         error_msg = 'unknown standard field "%s"'
#         self.fields = {}
#         for name in args:
#             try:
#                 f = self.standard_fields[name]
#             except KeyError:
#                 raise ValueError(error_msg % name)
#             self.fields[name] = f
# 
#         for key, value in kwargs.items():
#             if isinstance(value, basestring):
#                 # handle std fields being stored using a different name
#                 f = self.standard_fields.get(key)
#                 if not f:
#                     raise ValueError(error_msg % key)
#                 self.fields[key] = {'target': value, 'field': f}
#             else:
#                 self.fields[key] = value
# 
#         # Fields may be specified as dicts or tuples: normalize
#         # everything to use the dict format, so we can work with a
#         # common datastructure from now on.
#         for name, value in self.fields.iteritems():
#             if not isinstance(value, dict):
#                 self.fields[name] = {'field': value, 'target': name}
# 
#     def get_fields(self):
#         return {self.model_name: dict([(k['target'], k['field'])
#                     for n, k in self.fields.iteritems()])}
# 
#     def _process(self, obj, source_dict, *args, **kwargs):
#         """Call this in your respective subclass hook callback.
# 
#         ``args`` and ``kwargs`` will be passed along to ``_get_value``.
#         """
#         for source_name, d in self.fields.iteritems():
#             target_name = d['target']
# 
#             # First, let child classes handle the field, if they want.
#             # Otherwise, fall back to default; Do not handle default
#             # inside base _get_value, so that subclasses don't need to
#             # bother with super().
#             new_value = self._get_value(source_dict, source_name,
#                                         target_name, *args, **kwargs)
#             if new_value is self.USE_DEFAULT:
#                 # dates need to be converted to datetime
#                 if self.date_fields and source_name in self.date_fields:
#                     source_name = "%s_parsed" % source_name
#                     new_value = struct_to_datetime(source_dict.get(source_name))
#                 else:
#                     # Make sure to default to an empty string rather,
#                     # than NULL, since not all schemas may allow NULL.
#                     new_value = source_dict.get(source_name, u'')
# 
#             setattr(obj, target_name, new_value)
# 
#     def _get_value(self, source_dict, source_name, target_name, *args, **kwargs):
#         """Overwrite this if some of your collector's fields need
#         additional processing.
# 
#         Should return the final value, or ``self.USE_DEFAULT`` to let
#         default processing continue.
#         """
#         # handle base "special" fields
#         if source_name == '__now':
#             return datetime.utcnow()
#         return self.USE_DEFAULT


from storm.locals import Unicode, DateTime
from feedplatform.lib.addins.feeds.collect_feed_data \
    import base_data_collector

"""Addins that store item metadata in the database for offline access.
"""




__all__ = (
    'collect_item_data',
)



# Path: feedplatform/lib/addins/feeds/collect_feed_data.py
# class base_data_collector(addins.base):
#     """Baseclass for data collector addins.
# 
#     Subclasses should provide at least the ``model_name`` and
#     ``standard_fields`` attributes, and may implement ``_get_value``
#     for additional processing.
# 
#     ``standard_fields`` should be a dict in the form (name => field),
#     with ``field`` being a database field instance or creation tuple,
#     and name being both the model column name and the key name to use
#     when reading the value from the feed parser source dict. If you
#     want the model field name to differ from the source field, you may
#     specifiy a dict for ``field``:
# 
#         'href': {'target': 'image_href', 'field': (Unicode, (), {})}
# 
#     See also ``collect_feed_data`` and other subclasses for information
#     about how these collectors can be called and used from the end-user
#     perspective - much of that functionality is implemented here in the
#     base class.
#     """
# 
#     abstract = True
# 
#     USE_DEFAULT = object()
# 
#     # provide in subclass
#     model_name = None
#     standard_fields = None
#     date_fields = None
# 
#     # Provide special fields that every subclass supports.
#     class __metaclass__(type(addins.base)):
#         def __new__(cls, name, bases, attrs):
#             result = type(addins.base).__new__(cls, name, bases, attrs)
#             if result.standard_fields is not None:
#                 standard_fields = result.standard_fields
#                 result.standard_fields = {'__now': (DateTime, (), {})}
#                 result.standard_fields.update(standard_fields)
#             return result
# 
#     def __init__(self, *args, **kwargs):
#         error_msg = 'unknown standard field "%s"'
#         self.fields = {}
#         for name in args:
#             try:
#                 f = self.standard_fields[name]
#             except KeyError:
#                 raise ValueError(error_msg % name)
#             self.fields[name] = f
# 
#         for key, value in kwargs.items():
#             if isinstance(value, basestring):
#                 # handle std fields being stored using a different name
#                 f = self.standard_fields.get(key)
#                 if not f:
#                     raise ValueError(error_msg % key)
#                 self.fields[key] = {'target': value, 'field': f}
#             else:
#                 self.fields[key] = value
# 
#         # Fields may be specified as dicts or tuples: normalize
#         # everything to use the dict format, so we can work with a
#         # common datastructure from now on.
#         for name, value in self.fields.iteritems():
#             if not isinstance(value, dict):
#                 self.fields[name] = {'field': value, 'target': name}
# 
#     def get_fields(self):
#         return {self.model_name: dict([(k['target'], k['field'])
#                     for n, k in self.fields.iteritems()])}
# 
#     def _process(self, obj, source_dict, *args, **kwargs):
#         """Call this in your respective subclass hook callback.
# 
#         ``args`` and ``kwargs`` will be passed along to ``_get_value``.
#         """
#         for source_name, d in self.fields.iteritems():
#             target_name = d['target']
# 
#             # First, let child classes handle the field, if they want.
#             # Otherwise, fall back to default; Do not handle default
#             # inside base _get_value, so that subclasses don't need to
#             # bother with super().
#             new_value = self._get_value(source_dict, source_name,
#                                         target_name, *args, **kwargs)
#             if new_value is self.USE_DEFAULT:
#                 # dates need to be converted to datetime
#                 if self.date_fields and source_name in self.date_fields:
#                     source_name = "%s_parsed" % source_name
#                     new_value = struct_to_datetime(source_dict.get(source_name))
#                 else:
#                     # Make sure to default to an empty string rather,
#                     # than NULL, since not all schemas may allow NULL.
#                     new_value = source_dict.get(source_name, u'')
# 
#             setattr(obj, target_name, new_value)
# 
#     def _get_value(self, source_dict, source_name, target_name, *args, **kwargs):
#         """Overwrite this if some of your collector's fields need
#         additional processing.
# 
#         Should return the final value, or ``self.USE_DEFAULT`` to let
#         default processing continue.
#         """
#         # handle base "special" fields
#         if source_name == '__now':
#             return datetime.utcnow()
#         return self.USE_DEFAULT


# Path: feedplatform/lib/addins/items/collect_item_data.py
from storm.locals import Unicode, DateTime
from feedplatform.lib.addins.feeds.collect_feed_data \
    import base_data_collector

"""Addins that store item metadata in the database for offline access.
"""




__all__ = (
    'collect_item_data',
)



class collect_item_data(base_data_collector):
