zoukankan      html  css  js  c++  java
  • SpringPython之AOP

    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        ģ��1
    # Purpose:
    #
    # Author:      Administrator
    #
    # Created:     07-11-2012
    # Copyright:   (c) Administrator 2012
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    from springpython.context import ApplicationContext
    from springpython.config import PythonConfig
    
    from springpython.aop import *
    
    import time
    class PerformanceInterceptor(MethodInterceptor):
        def invoke(self, invocation):
            start = time.time()
            results = invocation.proceed()
            stop = time.time()
            print "Method took %2f seconds" % (stop - start)
            return results
    
    class WikiService:
        
        def AddWhileInt(self, a, b):
            result = a+b
            total = 10000000
            while(total):
                total-=1
                result+=1
            return result
        
        def AddWhileTrue(self, a, b):
            result = a+b
            total = 10000000
            while(total>0):
                total-=1
                result+=1
            return result
    
    class IocPythonContainer(PythonConfig):
        def __init__(self):
            super(IocPythonContainer, self).__init__()
        
        def PerformanceAdvisor(self):
            return RegexpMethodPointcutAdvisor(
                        advice = [PerformanceInterceptor()],
                        patterns = [".*.*"]
                                               )
        
        def WikiService(self):
            return ProxyFactoryObject(
                        target = WikiService(),
                        interceptors =[self.PerformanceAdvisor()]
                                      )
            
    def main():
        container = IocPythonContainer()
        service = container.WikiService()
        result = service.AddWhileInt(100, 20)
        print result
        result = service.AddWhileTrue(100, 20)
        print result
    
    if __name__ == '__main__':
        main()
            
  • 相关阅读:
    常见概念
    网站扒取
    图书管理系统易错点整理
    CSIC_716_2020104【Django入门---静态文件、request对象方法、ORM增删改查】
    CSIC_716_2020103【Django入门---HttpResponse、render、redirect】
    CSIC_716_2020102【前端框架Bootstrap】
    CSIC_716_2020101【???】
    CSIC_716_20191231【jQuery基础入门】
    CSIC_716_20191230【前端的BOM与DOM】
    ss
  • 原文地址:https://www.cnblogs.com/ankier/p/2759780.html
Copyright © 2011-2022 走看看