# Path: feedplatform/addins.py
# class base(object):
#     class __metaclass__(type):
#         def __new__(cls, name, bases, attrs):
#     def __new__(cls, *args, **kwargs):
#     def setup(self):
#     def log(self):
# def get_addins():
# def _make_addin(addin):
# def reinstall(addins=None):
#         def resolve_dependencies(addin, index):
# def install(*args, **kwargs):
# _ADDINS = None
#     _ADDINS = to_be_setup
# 
# Path: feedplatform/db.py
# class MultipleObjectsReturned(Exception):
# class DatabaseProxy(object):
# class ModelsProxy(types.ModuleType):
# def get_one(result):
# def cap_model_name(name):
#     def repl(m):
# def uncap_model_name(name):
#     def __init__(self, create_func):
#     def _connect(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __init__(self):
#     def __getattr__(self, name):
#     def __iter__(self):
#     def iternames(self):
#     def iteritems(self):
#     def _construct_models(self):
# def reconfigure():
# BASE_MODELS = {
#     'feed': {
#         'id': (Int, (), {'primary': True}),
#         'url': (Unicode, (), {}),
#         'items': (ReferenceSet, ('Feed.id', 'Item.feed_id',), {}),
#     },
#     'item': {
#         'id': (Int, (), {'primary': True}),
#         'feed_id': (Int, (), {}),
#         'feed': (Reference, ('feed_id', 'Feed.id',), {}),
#         'guid': (Unicode, (), {}),
#     },
# }
# 
# Path: feedplatform/util.py
# def struct_to_datetime(structt):
#     """Convert timestructs/9-tuples, as returned by feedparser, to
#     naive, UTC-based datetime objects.
# 
#     See also:
#         http://www.deadlybloodyserious.com/2007/09/feedparser-v-django/
#         http://www.intertwingly.net/blog/2007/09/02/Dealing-With-Dates
#     """
#     if not structt:
#         return structt
#     return datetime.datetime.utcfromtimestamp(calendar.timegm(structt))


from datetime import datetime
from storm.locals import Unicode, DateTime
from feedplatform import addins
from feedplatform import db
from feedplatform.util import struct_to_datetime


        # 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

# Path: feedplatform/addins.py
# class base(object):
#     class __metaclass__(type):
#         def __new__(cls, name, bases, attrs):
#     def __new__(cls, *args, **kwargs):
#     def setup(self):
#     def log(self):
# def get_addins():
# def _make_addin(addin):
# def reinstall(addins=None):
#         def resolve_dependencies(addin, index):
# def install(*args, **kwargs):
# _ADDINS = None
#     _ADDINS = to_be_setup
# 
# Path: feedplatform/db.py
# class MultipleObjectsReturned(Exception):
# class DatabaseProxy(object):
# class ModelsProxy(types.ModuleType):
# def get_one(result):
# def cap_model_name(name):
#     def repl(m):
# def uncap_model_name(name):
#     def __init__(self, create_func):
#     def _connect(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __init__(self):
#     def __getattr__(self, name):
#     def __iter__(self):
#     def iternames(self):
#     def iteritems(self):
#     def _construct_models(self):
# def reconfigure():
# BASE_MODELS = {
#     'feed': {
#         'id': (Int, (), {'primary': True}),
#         'url': (Unicode, (), {}),
#         'items': (ReferenceSet, ('Feed.id', 'Item.feed_id',), {}),
#     },
#     'item': {
#         'id': (Int, (), {'primary': True}),
#         'feed_id': (Int, (), {}),
#         'feed': (Reference, ('feed_id', 'Feed.id',), {}),
#         'guid': (Unicode, (), {}),
#     },
# }
# 
# Path: feedplatform/util.py
# def struct_to_datetime(structt):
#     """Convert timestructs/9-tuples, as returned by feedparser, to
#     naive, UTC-based datetime objects.
# 
#     See also:
#         http://www.deadlybloodyserious.com/2007/09/feedparser-v-django/
#         http://www.intertwingly.net/blog/2007/09/02/Dealing-With-Dates
#     """
#     if not structt:
#         return structt
#     return datetime.datetime.utcfromtimestamp(calendar.timegm(structt))


# Path: feedplatform/lib/addins/feeds/collect_feed_data.py
from datetime import datetime
from storm.locals import Unicode, DateTime
from feedplatform import addins
from feedplatform import db
from feedplatform.util import struct_to_datetime


        # 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))
