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.

59 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009, withgod <withgod@sourceforge.net>
  5. * 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  6. *
  7. * Mumble-Django is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This package is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. """
  17. import re
  18. class MumbleCtlBase(object):
  19. """ This class defines the base interface that the Mumble model expects. """
  20. cache = {}
  21. @staticmethod
  22. def newInstance( connstring, slicefile=None, icesecret=None ):
  23. """ Create a new CTL object for the given connstring.
  24. Optional parameters are the path to the slice file and the
  25. Ice secret necessary to authenticate to Murmur.
  26. The path can be omitted only if using DBus or running Murmur
  27. 1.2.3 or later, which exports a getSlice method to retrieve
  28. the Slice from.
  29. """
  30. # check cache
  31. if connstring in MumbleCtlBase.cache:
  32. return MumbleCtlBase.cache[connstring]
  33. # connstring defines whether to connect via ICE or DBus.
  34. # Dbus service names: some.words.divided.by.periods
  35. # ICE specs are WAY more complex, so if DBus doesn't match, use ICE.
  36. rd = re.compile( r'^(\w+\.)*\w+$' )
  37. if rd.match( connstring ):
  38. from MumbleCtlDbus import MumbleCtlDbus
  39. ctl = MumbleCtlDbus( connstring )
  40. else:
  41. from MumbleCtlIce import MumbleCtlIce
  42. ctl = MumbleCtlIce( connstring, slicefile, icesecret )
  43. MumbleCtlBase.cache[connstring] = ctl
  44. return ctl
  45. @staticmethod
  46. def clearCache():
  47. MumbleCtlBase.cache = {}