# 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 datetime_to_struct(datetime):
#     """Convert a datetime object to an UTC-based 9-tuple.
# 
#     The reverse of ``struct_to_datetime``.
#     """
#     if not datetime:
#         return datetime
#     return datetime.utctimetuple()
# 
# 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))
# 
# def to_unicode(s):
#     """Convert ``s`` to a unicode object if not None.
# 
#     This is helpful in scenarios where you want to assign to a nullable
#     Storm ``Unicode`` column (Storm enforces a unicode string type),
#     without checking the source for a ``None`` value manually.
#     """
# 
#     if s is None or isinstance(s, unicode):
#         return s
#     else:
#         return unicode(s)


from storm.locals import DateTime, Unicode
from feedplatform import addins
from feedplatform import db
from feedplatform.util import \
    datetime_to_struct, struct_to_datetime, to_unicode


    def _delete_self(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: removing self')
        # XXX: delete related objects
        db.store.remove(feed)

        # don't process this feed further
        return False

    def _delete_other(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: removing the other feeds')
        count = 0
        for f in dup_feeds:
            count += 1
            # XXX: we need a solution to delete related objects as well.
            # Storm doesn't seem to do it, and ON DELETE * is not
            # supported by every database backend.
            db.store.remove(f)
        self.log.debug('%d duplicate feeds removed' % count)
        feed.url = new_url

    def _ignore(self, feed, new_url, dup_feeds):
        # simple: don't do anything (except log), we keep the current url
        self.log.info('Redirect target already exists: ignore, keeping the old url')

    def _force(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: changing to new url anyway')
        feed.url = new_url



# 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 datetime_to_struct(datetime):
#     """Convert a datetime object to an UTC-based 9-tuple.
# 
#     The reverse of ``struct_to_datetime``.
#     """
#     if not datetime:
#         return datetime
#     return datetime.utctimetuple()
# 
# 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))
# 
# def to_unicode(s):
#     """Convert ``s`` to a unicode object if not None.
# 
#     This is helpful in scenarios where you want to assign to a nullable
#     Storm ``Unicode`` column (Storm enforces a unicode string type),
#     without checking the source for a ``None`` value manually.
#     """
# 
#     if s is None or isinstance(s, unicode):
#         return s
#     else:
#         return unicode(s)


# Path: feedplatform/lib/addins/feeds/http.py
from storm.locals import DateTime, Unicode
from feedplatform import addins
from feedplatform import db
from feedplatform.util import \
    datetime_to_struct, struct_to_datetime, to_unicode


    def _delete_self(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: removing self')
        # XXX: delete related objects
        db.store.remove(feed)

        # don't process this feed further
        return False

    def _delete_other(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: removing the other feeds')
        count = 0
        for f in dup_feeds:
            count += 1
            # XXX: we need a solution to delete related objects as well.
            # Storm doesn't seem to do it, and ON DELETE * is not
            # supported by every database backend.
            db.store.remove(f)
        self.log.debug('%d duplicate feeds removed' % count)
        feed.url = new_url

    def _ignore(self, feed, new_url, dup_feeds):
        # simple: don't do anything (except log), we keep the current url
        self.log.info('Redirect target already exists: ignore, keeping the old url')

    def _force(self, feed, new_url, dup_feeds):
        self.log.info('Redirect target already exists: changing to new url anyway')
        feed.url = new_url



class save_bandwith(addins.base):
