You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

type_strlist.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # pydhcplib
  2. # Copyright (C) 2008 Mathieu Ignacio -- mignacio@april.org
  3. #
  4. # This file is part of pydhcplib.
  5. # Pydhcplib is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. class strlist :
  18. def __init__(self,data="") :
  19. str_type = type(data)
  20. self._str = ""
  21. self._list = []
  22. if str_type == str :
  23. self._str = data
  24. for each in range(len(self._str)) :
  25. self._list.append(ord(self._str[each]))
  26. elif str_type == list :
  27. self._list = data
  28. self._str = "".join(map(chr,self._list))
  29. else : raise TypeError , 'strlist init : Valid types are str and list of int'
  30. # return string
  31. def str(self) :
  32. return self._str
  33. # return list (useful for DhcpPacket class)
  34. def list(self) :
  35. return self._list
  36. # return int
  37. # FIXME
  38. def int(self) :
  39. return 0
  40. """ Useful function for native python operations """
  41. def __hash__(self) :
  42. return self._str.__hash__()
  43. def __repr__(self) :
  44. return self._str
  45. def __nonzero__(self) :
  46. if self._str != "" : return 1
  47. return 0
  48. def __cmp__(self,other) :
  49. if self._str == other : return 0
  50. return 1