2
0

models.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  14. The Initial Developer of the Original Code is
  15. Anthony Minessale II <anthm@freeswitch.org>
  16. Portions created by the Initial Developer are Copyright (C)
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s): Traun Leyden <tleyden@branchcut.com>
  19. """
  20. """
  21. Data models for objects inside freeswitch
  22. """
  23. import re
  24. class ConfMember:
  25. def __init__(self, rawstring):
  26. self.rawstring = rawstring
  27. self.member_id = None
  28. self.member_uri = None
  29. self.uuid = None
  30. self.caller_id_name = None
  31. self.caller_id_number = None
  32. self.flags = None
  33. self.volume_in = None
  34. self.volume_out = None
  35. self.energy_level = None
  36. self.parse(self.rawstring)
  37. def parse(self, rawstring):
  38. """
  39. 1;sofia/mydomain.com/user@somewhere.com;898e6552-24ab-11dc-9df7-9fccd4095451;FreeSWITCH;0000000000;hear|speak;0;0;300
  40. """
  41. fields = rawstring.split(";")
  42. self.member_id = fields[0]
  43. self.member_uri = fields[1]
  44. self.uuid = fields[2]
  45. self.caller_id_name = fields[3]
  46. self.caller_id_number = fields[4]
  47. self.flags = fields[5]
  48. self.volume_in = fields[6]
  49. self.volume_out = fields[7]
  50. self.energy_level = fields[8]
  51. def brief_member_uri(self):
  52. """
  53. if self.member_uri is sofia/mydomain.com/foo@bar.com
  54. return foo@bar.com
  55. """
  56. if not self.member_uri:
  57. return None
  58. if self.member_uri.find("/") == -1:
  59. return self.member_uri
  60. r = self.member_uri.split("/")[-1] # tokenize on "/" and return last item
  61. return r
  62. def __repr__(self):
  63. return self.__str__()
  64. def __str__(self):
  65. return "%s (%s)" % (self.member_id, self.member_uri)