source: package_tags/python-pydhcplib/0.3.2-3/pydhcplib/type_strlist.py @ 2778

Last change on this file since 2778 was 1191, checked in by broder, 16 years ago

Strip the sipb-xen prefix from packages we didn't write

File size: 1.8 KB
Line 
1# Anemon Dhcp
2# Copyright (C) 2005 Mathieu Ignacio -- mignacio@april.org
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
17
18class strlist :
19    def __init__(self,data="") :
20        str_type = type(data)
21        self._str = ""
22        self._list = []
23       
24        if str_type == str :
25            self._str = data
26            for each in range(len(self._str)) :
27                self._list.append(ord(self._str[each]))
28        elif str_type == list :
29            self._list = data
30            self._str = "".join(map(chr,self._list))
31        else : raise TypeError , 'strlist init : Valid types are str and  list of int'
32
33    # return string
34    def str(self) :
35        return self._str
36
37    # return list (useful for DhcpPacket class)
38    def list(self) :
39        return self._list
40
41    # return int
42    # FIXME
43    def int(self) :
44        return 0
45
46
47
48    """ Useful function for native python operations """
49
50    def __hash__(self) :
51        return self._str.__hash__()
52
53    def __repr__(self) :
54        return self._str
55
56    def __nonzero__(self) :
57        if self._str != "" : return 1
58        return 0
59
60    def __cmp__(self,other) :
61        if self._str == other : return 0
62        return 1
63                   
64
65
Note: See TracBrowser for help on using the repository browser.