root/branch/UMPA/umpa/packets.py @ 3082

Revision 3082, 1.7 kB (checked in by getxsick, 5 years ago)

Added set_fields() method for Protocol and few utils functions

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (C) 2008 Adriano Monteiro Marques.
5#
6# Author: Bartosz SKOWRON <getxsick at gmail dot com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22class Packet:
23    '''You have to use this class to build a completely packets.
24    An instance of the class should contains protocols which
25    you want to send.'''
26
27    def __init__(self, *protos):
28        '''You can include some protocols objects in construtor
29        or use include() method later.
30        '''
31        self.protos = []
32        self._add_new_protocols(protos)
33
34    def __str__(self):
35        '''Prints in human-readable style a content of the packet.'''
36        print "Not implemented yet."
37
38    def print_protocols(self):
39        '''Prints all included protocols into the packet.'''
40        for p in self.protos:
41            print p
42
43    def include(self, *protos):
44        '''You can add protocols into your packet.
45        '''
46        self._add_new_protocols(protos)
47
48    def _add_new_protocols(*protos):
49        for p in protos:
50            self.protos.append(p)
Note: See TracBrowser for help on using the browser.