import sha
from amplee.atompub.member.atom import EntryResource
	
import uuid



###########################################################
# The following two classes handle the
# application/atom+xml;type=entry media-type
###########################################################
class CommitEntryMember(EntryResource):
    def __init__(self, collection, **kwargs):
        print "fooo"
        self.uuid = uuid.uuid1()
        EntryResource.__init__(self, collection, **kwargs)

    def generate_atom_id(self, entry, slug=None):
        return u"urn:uuid:" + unicode(self.uuid)
    
    def generate_resource_id(self, entry, slug=None):
        if slug:
            return slug.replace(' ','_').decode('utf-8')
        title = entry.get_child('title', entry.xml_ns)
        if title:
            return title.xml_text.replace(' ','_')

        return str(int(time.time()))

class CommitEntryHandler(object):
    def __init__(self, member_type):
        # Instance of amplee.handler.MemberType
        self.member_type = member_type

    def on_update_feed(self, member):
        member.collection.feed_handler.set(member.collection.feed)
