UserPreferences

zqOtterDevLog


Otter 核心开发日志

-- Zoom.Quiet [2004-08-16 00:15:40]

  1. 开发难点
    1. Py脚本模板引擎
  2. 开发节点
    1. 040831 反复交流确认开发
    2. 040821 继承整理
    3. 040820 标签驱动
    4. 040819 Macro
    5. 040818 Templet
    6. 040817 XML
    7. 040816 XSD
    8. 040815 开始

开发难点

关注可能诞生新近项目的技术难点

Py脚本模板引擎

开发节点

简述各个时期的开发重心

040831 反复交流确认开发

040821 继承整理

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
>>> dir({})
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__'
, '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__
', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__r
epr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys', 'get', 'has_
key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefaul
t', 'update', 'values']
>>> type({}.update)
<type 'builtin_function_or_method'>
>>> {}.update.__doc__
'D.update(E) -> None.  Update D from E: for k in E.keys(): D[k] = E[k]'

040820 标签驱动

['define', 'connect'
        , [
                ['code', '###CommandName###', 'connect']
                , ['code', '###Field###', '6s16sI8s']
                , ['loop', '###loop###Fields###'
                        , ['system_id', 'auth_source', 'version', 'time_stamp']
                        ]
                , ['loop', '###loop###Field###'
                        , ['system_id', 'auth_source', 'version', 'time_stamp']
                        ]
        ]
]

040819 Macro

   - ###XPath### 值替换标签 
        - ###start###XPath### ; ###end###XPath### 块标签,返回进一步处理后的整块文本
        - ###loop###XPath### 行标签,通过传入数值列来在行的单位中进行值替换处理
        - ###macro### ; ###macroend### 其间是可以模板处理时执行的脚本!!
    """
runmacro
    spli[i] = eval(spli[i]%(arg))
  File "<string>", line 2
    if "pass"=="pass":
     ^
SyntaxError: invalid syntax
  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
###start###./Message/Commands/Command###
    def pack_###./Protocol/@ProtocolName###_###CommandName###(self, fields):
        """###CommandName###±¨ÎÄ´ò°ü"""

###macro###
if "pass"=="%s":
    print "return None"
else:
    print """    
        return struct.pack('###Field###',
                ###loop###Fields###
                )
"""
###macroend###

    def unpack_###./Protocol/@ProtocolName###_###CommandName###(self, packet):
        """###CommandName###±¨ÎĽâ°ü"""
###macro###
if "pass"=="%s":
    print "pass"
else:
    print """    
        ###loop###Field###
            struct.unpack('###Field###',packet)
"""
###macroend###

###end###./Message/Commands/Command###

040818 Templet

    设计的标签系统:
        - ###XPath### 值替换标签
        - ###start###XPath### ; ###end###XPath### 块标签,返回进一步处理后的整块文本
        - ###loop###XPath### 行标签,通过传入数值列来在行的单位中进行值替换处理
from ###./@ProtocolName###.message import bytemsg
import struct

class ###./Protocol/@ProtocolName###Message(bytemsg.ByteMessage):
    """###./Protocol/@ProtocolName### 消息基类"""
    def __init__(self):
        # 消息头
        self.head = bytemsg.ByteMessageHead(self)
        # 消息体
        self.body = bytemsg.ByteMessageBody(self)
        # 消息工具
        self.msgutilcls = ###./Protocol/@ProtocolName###MessageUtil
        # 协议名称
        self.protocolname = '###./Protocol/@ProtocolName###'
        # 当前的消息名称
        self.msgname = ''

    ###start###./Message/Commands/Command###
    def pack_###./Protocol/@ProtocolName###_###CommandName###(self, fields):
        """###CommandName###报文打包"""
        return struct.pack('###Field###',
                ###loop###Fields###
                )
    def unpack_###./Protocol/@ProtocolName###_###CommandName###(self, packet):
        """###CommandName###报文解包"""
        ###loop###Field###
            struct.unpack('###Field###',packet)    
    ###end###./Message/Commands/Command###
    
# ###./Protocol/@ProtocolName### Message定义
###./Protocol/@ProtocolName###MessageUtil.commandinfo = {
    ###loop###commandinfo###
    }

# 通过名称查出消息ID的结构定义
###./Protocol/@ProtocolName###MessageUtil.nametoid = {}
for k in ###./Protocol/@ProtocolName###MessageUtil.commandinfo.keys():
    ###./Protocol/@ProtocolName###MessageUtil.nametoid[###./Protocol/@ProtocolName###MessageUtil.commandinfo[k]] = k


types -- Names for all built-in types

This module defines names for all object types that are used by the standard Python interpreter, but not for the types defined by various extension modules. It is safe to use "from types import *" -- the module does not export any names besides the ones listed here. New names exported by future versions of this module will all end in "Type".

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 

Typical use is for functions that do different things depending on their argument types, like the following:

from types import *
def delete(list, item):
    if type(item) is IntType:
       del list[item]
    else:
       list.remove(item)

The module defines the following names:

NoneType
The type of None.


...

LambdaType
An alternate name for FunctionType.


...

StringTypes

040817 XML

['###./@Version###', '0.1']

['###./@ProtocolName###', 'uss']

['###./@PersistentConnection###', 'false']

['###./@OtBaseDir###', 'OtterBaseTemplet']

['###./Message/@MessageName###', 'usspmsg']

['###./Message/@OtBaseDir###', 'message']

['###./Message/@OtBaseFile###', 'bytemsg.py']

['###./Message/Commands/Command###', [['generic_noop', '0x00000000L'], ['generic_noop_resp', '0xff000000L'], ['connect', '0x00000001L', [['system_id', '6', 's'], ['auth_source', '16', 's'], ['version', None, 'I'], ['time_stamp', '8', 's']]], ['connect_resp', '0xff000001L', [['status', None, 'I'], ['version', None, 'I']]], ['terminate', '0x00000002L'], ['terminate_resp', '0xff000002L'], ['mail_counter', '0x00000005L'], ['mail_counter_resp', '0xff000005L']], ('CommandName', 'CommandID'), ('FieldName', 'FieldSize', 'FieldType')]

['###./Protocol/@ProtocolName###', 'ussp']

['###./Protocol/@ListenPort###', '7890']

['###./Protocol/@OtBaseDir###', 'protocols']

['###./Protocol/@OtBaseFile###', 'byteprotocol.py']

['###./Protocol/ClientProtocol/Command###', [['generic_noop_resp', '0xff000000L'], ['connect_resp', '0xff000001L'], ['terminate', '0x00000002L'], ['terminate_resp', '0xff000002L'], ['mail_counter_resp', '0xff000005L']], ('CommandName', 'CommandID')]

['###./Protocol/ServerProtocol/Command###', [['generic_noop', '0x00000000L'], ['connect', '0x00000001L'], ['terminate', '0x00000002L'], ['terminate_resp', '0xff000002L'], ['mail_counter', '0x00000005L']], ('CommandName', 'CommandID')]

040816 XSD

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
# -*- coding: utf-8 -*-
# file OtterTools.py
#
"""Otter Tools main script

@version: 0.1a
@author: U{Zoom.Quiet<mailto:[email protected]>}
@see: http://wiki.woodpecker.org.cn/moin.cgi/Otter_2fOtterTool
"""
import sys,string
from elementtree import ElementTree
if __name__ == '__main__':      # this way the module can be
    """
    应用 Elements and Element Trees 来通过XPath 迅速理解XML
    """
    file = open("uss.xml", "r")
    weblog = ElementTree.parse('uss.xml').getroot()
    commands = weblog.findall('.//Command')
    for node in commands:
        print node.attrib["CommandID"]

040815 开始