Python: an implementation of the decoration Mode

Source: Internet
Author: User

# ! /Usr/bin/ENV Python # -*-Coding: UTF-8 -*- Import Syssys. Path. append ( " .. " ) Import Common Class Component: Def _ Init __ (Self, data): Self. url = Data [ " URL " ] Self. noteid = Data [ " Noteid " ] Self. userid = Data [ " Userid " ] Self. folderid = Data [ " Folderid " ] Def Execute (Self ): Pass Class Notecomponent (Component ): Def _ Init __ (Self, Data, Component = None): Self. Component = Component component. _ Init __ (Self, data) Def Setcomponent (self, component): Self. Component = Component Class Htmlcatcher (notecomponent ): Def Execute (Self ): If Self. Component! = None: self.component.exe cute () Print Self. _ Class __ . _ Name __ Class Imagecatcher (notecomponent ): Def Execute (Self ): If Self. Component! = None: self.component.exe cute () Print Self. _ Class __ . _ Name __ Class Sharenotecomponet (notecomponent ): Def Execute (Self ): If Self. Component! = None: self.component.exe cute () 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.exe cute () 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)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.