#coding=utf-8
from Template import T

main=T("""# -*- coding: utf-8 -*-
# 版权 2004 啄木鸟基金会
# 保留一切权利。
# 
# 重新分发或者使用源代码格式和二进制格式，无论是否修改，必须在符合
# 以下许可条件的情况下进行：
# 1. 重新分发的源代码必须保留上述版权信息、本许可条件列表以及下列
#    否认声明。
# 2. 重新分发的二进制格式程序必须再次产生上述版权信息，本许可条件列
#    表以及在本分发中的文档或者其他材料中提供的否认声明。
#
# 本软件是由作者和参与者“照此”提供，并且任何显式或隐式的保证，只
# 包含在内但不被其限制，否认任何商业性和特殊目的适切性的隐式担保
# 之效力。本软件的作者或参与者不对由于本软件造成的任何直接地、
# 间接地、连带地、特殊地、惩戒性地，或者由此而产生地损害（还包括
# 以下的不被其限制的内容在内：替代品或服务地取得；使用过程、数据、
# 或由此产生的收益之损失；或商业行为的中断）发生在即使被告知可能
# 出现上述损害后，仍设法摆脱使用本软件的过程中，无论其起因和任何
# 责任地推测，其是否属于合同范畴、限定的义务、或者民事侵权行为
#（包括疏忽及其他）都否认其责任。
# 
# 
#
# Copyright (c) 2004 The Woodpecker Foundation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Header: /woodpecker/otter/ottertools/OtterBaseTemplet/lib/messages/pcon-pmsg.py,v 1.5 2004/08/19 07:45:28 zhaoxin Exp $

\"\"\"二进制流长连接通讯协议处理

@author: Otter ToolKit

@see: 二进制流通讯长连接规范
\"\"\"
from ###Lprotoname###.message import ###MsgBase###
import struct

class ###Uprotoname###PMessage(###MsgBase###.ByteMessage):
    \"\"\"二进制流连接消息基类\"\"\"
    def __init__(self):
        # 消息头
        self.head = ###MsgBase###.ByteMessageHead(self)
        # 消息体
        self.body = ###MsgBase###.ByteMessageBody(self)
        # 消息工具
        self.msgutilcls = ###Uprotoname###PMessageUtil
        # 协议名称
        self.protocolname = '###Lprotoname###p'
        # 当前的消息名称
        self.msgname = ''

###Commands###

class ###Uprotoname###PMessageUtil(###MsgBase###.ByteMessageUtil):
    \"\"\"二进制长连接消息处理工具类\"\"\"
    def __init__(self):
        pass

# 消息定义
###Uprotoname###PMessageUtil.commandinfo = {
###Commandsinfo###
    }

# 通过名称查出消息ID的结构定义
###Uprotoname###PMessageUtil.nametoid = {}
for k in ###Uprotoname###PMessageUtil.commandinfo.keys():
    ###Uprotoname###PMessageUtil.nametoid[###Uprotoname###PMessageUtil.commandinfo[k]] = k

""")

Commands = T("""    def pack_###Lprotoname###p_###commandname###(self, fields):
###packcontent###

    def unpack_###Lprotoname###p_###commandname###(self, fields):
###unpackcontent###

""")

Lprotoname = T("###lpname###")
Uprotoname = T("###upname###")
packcontent = T('')
unpackcontent = T('')
Commandsinfo=T("    ###flag### : '###name###',\n")