Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
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.

50 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. import re
  17. def iptostring(addr):
  18. """ Get the client's IPv4 or IPv6 address, in a pretty format. """
  19. if max( addr[:10] ) == 0 and addr[10:12] == (255, 255):
  20. return "%d.%d.%d.%d" % tuple( addr[12:] )
  21. ip6addr = [(hi << 8 | lo) for (hi, lo) in zip(addr[0::2], addr[1::2])]
  22. # colon-separated string:
  23. ipstr = ':'.join([ ("%x" % part) for part in ip6addr ])
  24. # 0:0:0 -> ::
  25. return re.sub( "((^|:)(0:){2,})", '::', ipstr, 1 )
  26. class ObjectInfo( object ):
  27. """ Wraps arbitrary information to be easily accessed. """
  28. def __init__( self, **kwargs ):
  29. self.__dict__ = kwargs
  30. def __str__( self ):
  31. return unicode( self )
  32. def __repr__( self ):
  33. return unicode( self )
  34. def __unicode__( self ):
  35. return unicode( self.__dict__ )
  36. def __contains__( self, name ):
  37. return name in self.__dict__
  38. def __getitem__( self, name ):
  39. return self.__dict__[name]