記錄Tornado-4.0.2源碼的閱讀,學習,分析html
1 from __future__ import absolute_import, division, print_function, with_statement
future_statement 即:from __futuren import XXX. 參見 XiaoKL學Python(C)__future__python
1 import datetime 2 import numbers 3 import re 4 import sys 5 import os 6 import textwrap
1 from tornado.escape import _unicode 2 from tornado.log import define_logging_options 3 from tornado import stack_context 4 from tornado.util import basestring_type, exec_in
該類負責解析命令行的Option, 每一個option被抽象爲類_Option的對象。web
表明命令行上的每一個option,該類爲內部類。正則表達式
定義了一個全局的OptionParser對象。options.py提供的接口都是在該對象上進行操做的。ide
末尾調用瞭如下接口來將log相關的option添加到options.py模塊中。tornado
1 define_logging_options(options)
[Todo]post
1 def define(name, default=None, type=None, help=None, metavar=None, 2 multiple=False, group=None, callback=None)
1 def parse_config_file(path, final=True)
import sys單元測試
https://docs.python.org/2/library/sys.html?highlight=sys#module-sys學習
sys._getframe([depth])測試
"Return a frame object from the call stack. If optional integer depth is given, return the frame
object that many calls below the top of the stack. If that is deeper than the call stack, ValueError
is raised. The default fordepth is zero, returning the frame at the top of the call stack."
在options.py中的使用,在OptionParser類的define方法的實現中:
1 frame = sys._getframe(0)
https://docs.python.org/2/library/inspect.html
"The inspect module provides several useful functions to help get information about live
objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. "
該模塊中包含 frame 類型(即: sys._getframe() 返回值的類型 )的說明。
mock 模塊
Python中的單元測試。
1 def value(self): 2 return self.default if self._value is _Option.UNSET else self._value
1 _TIMEDELTA_ABBREV_DICT = dict( 2 (abbrev, full) for full, abbrevs in _TIMEDELTA_ABBREVS 3 for abbrev in abbrevs)
1 _FLOAT_PATTERN = r'[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?'
1. http://www.tornadoweb.org/en/stable/options.html