#!/usr/bin/env python# -*- coding: utf-8 -*-import syssys.path.append("..")import commonclass Component: def __init__(self,data): self.url = data["url"] self.noteId = data["noteId"] self.userId = data["userId"] self.folderId = data["folderId"] def execute(self): passclass NoteComponent(Component): def __init__(self,data,component=None): self.component = component Component.__init__(self, data) def setComponent(self,component): self.component = componentclass HtmlCatcher(NoteComponent): def execute(self): if self.component != None: self.component.execute() print self.__class__.__name__class ImageCatcher(NoteComponent): def execute(self): if self.component != None: self.component.execute() print self.__class__.__name__ class shareNoteComponet(NoteComponent): def execute(self): if self.component != None: self.component.execute() print self.__class__.__name__ def process(message): component = None if message['TYPE'] & common.CATCH_PAGE: component = HtmlCatcher(message["DATA"]) if message['TYPE'] & common.CATCH_IMAGE: component1 = ImageCatcher(message["DATA"]) component1.setComponent(component) component = component1 if message['TYPE'] & common.SAVE_SHARED: component1 = shareNoteComponet(message["DATA"]) component1.setComponent(component) component = component1 component.execute() if __name__ == "__main__": message = { #"TYPE":common.CATCH_PAGE, #"TYPE":common.CATCH_IMAGE | common.SAVE_SHARED, "TYPE":common.CATCH_PAGE | common.SAVE_SHARED | common.CATCH_IMAGE, "DATA": { "url":"http://www.baidu.com", "noteId":100, "userId":100, "folderId":100, } } process(message)