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.

58 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright © 2009, withgod <withgod@sourceforge.net>
  4. * 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. class MumbleCtlBase(object):
  18. """ This class defines the base interface that the Mumble model expects. """
  19. cache = {};
  20. @staticmethod
  21. def newInstance( connstring, slicefile=None, icesecret=None ):
  22. """ Create a new CTL object for the given connstring.
  23. Optional parameters are the path to the slice file and the
  24. Ice secret necessary to authenticate to Murmur.
  25. The path can be omitted only if using DBus or running Murmur
  26. 1.2.3 or later, which exports a getSlice method to retrieve
  27. the Slice from.
  28. """
  29. # check cache
  30. if connstring in MumbleCtlBase.cache:
  31. return MumbleCtlBase.cache[connstring];
  32. # connstring defines whether to connect via ICE or DBus.
  33. # Dbus service names: some.words.divided.by.periods
  34. # ICE specs are WAY more complex, so if DBus doesn't match, use ICE.
  35. rd = re.compile( r'^(\w+\.)*\w+$' );
  36. if rd.match( connstring ):
  37. from MumbleCtlDbus import MumbleCtlDbus
  38. ctl = MumbleCtlDbus( connstring )
  39. else:
  40. from MumbleCtlIce import MumbleCtlIce
  41. ctl = MumbleCtlIce( connstring, slicefile, icesecret )
  42. MumbleCtlBase.cache[connstring] = ctl;
  43. return ctl;
  44. @staticmethod
  45. def clearCache():
  46. MumbleCtlBase.cache = {};