A Python UPnP Media Server
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.

203 lines
7.2 KiB

  1. """
  2. ################################################################################
  3. # Copyright (c) 2003, Pfizer
  4. # Copyright (c) 2001, Cayce Ullman.
  5. # Copyright (c) 2001, Brian Matthews.
  6. #
  7. # All rights reserved.
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions are met:
  11. # Redistributions of source code must retain the above copyright notice, this
  12. # list of conditions and the following disclaimer.
  13. #
  14. # Redistributions in binary form must reproduce the above copyright notice,
  15. # this list of conditions and the following disclaimer in the documentation
  16. # and/or other materials provided with the distribution.
  17. #
  18. # Neither the name of actzero, inc. nor the names of its contributors may
  19. # be used to endorse or promote products derived from this software without
  20. # specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
  26. # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. #
  33. ################################################################################
  34. """
  35. ident = '$Id: Config.py,v 1.9 2004/01/31 04:20:05 warnes Exp $'
  36. from version import __version__
  37. import copy, socket
  38. from types import *
  39. from NS import NS
  40. ################################################################################
  41. # Configuration class
  42. ################################################################################
  43. class SOAPConfig:
  44. __readonly = ('SSLserver', 'SSLclient', 'GSIserver', 'GSIclient')
  45. def __init__(self, config = None, **kw):
  46. d = self.__dict__
  47. if config:
  48. if not isinstance(config, SOAPConfig):
  49. raise AttributeError, \
  50. "initializer must be SOAPConfig instance"
  51. s = config.__dict__
  52. for k, v in s.items():
  53. if k[0] != '_':
  54. d[k] = v
  55. else:
  56. # Setting debug also sets returnFaultInfo,
  57. # dumpHeadersIn, dumpHeadersOut, dumpSOAPIn, and dumpSOAPOut
  58. self.debug = 0
  59. self.dumpFaultInfo = 1
  60. # Setting namespaceStyle sets typesNamespace, typesNamespaceURI,
  61. # schemaNamespace, and schemaNamespaceURI
  62. self.namespaceStyle = '1999'
  63. self.strictNamespaces = 0
  64. self.typed = 1
  65. self.buildWithNamespacePrefix = 1
  66. self.returnAllAttrs = 0
  67. # Strict checking of range for floats and doubles
  68. self.strict_range = 0
  69. # Default encoding for dictionary keys
  70. self.dict_encoding = 'ascii'
  71. # New argument name handling mechanism. See
  72. # README.MethodParameterNaming for details
  73. self.specialArgs = 1
  74. # If unwrap_results=1 and there is only element in the struct,
  75. # SOAPProxy will assume that this element is the result
  76. # and return it rather than the struct containing it.
  77. # Otherwise SOAPproxy will return the struct with all the
  78. # elements as attributes.
  79. self.unwrap_results = 1
  80. # Automatically convert SOAP complex types, and
  81. # (recursively) public contents into the corresponding
  82. # python types. (Private subobjects have names that start
  83. # with '_'.)
  84. #
  85. # Conversions:
  86. # - faultType --> raise python exception
  87. # - arrayType --> array
  88. # - compoundType --> dictionary
  89. #
  90. self.simplify_objects = 0
  91. # Per-class authorization method. If this is set, before
  92. # calling a any class method, the specified authorization
  93. # method will be called. If it returns 1, the method call
  94. # will proceed, otherwise the call will throw with an
  95. # authorization error.
  96. self.authMethod = None
  97. # Globus Support if pyGlobus.io available
  98. try:
  99. from pyGlobus import io;
  100. d['GSIserver'] = 1
  101. d['GSIclient'] = 1
  102. except:
  103. d['GSIserver'] = 0
  104. d['GSIclient'] = 0
  105. # Server SSL support if M2Crypto.SSL available
  106. try:
  107. from M2Crypto import SSL
  108. d['SSLserver'] = 1
  109. except:
  110. d['SSLserver'] = 0
  111. # Client SSL support if socket.ssl available
  112. try:
  113. from socket import ssl
  114. d['SSLclient'] = 1
  115. except:
  116. d['SSLclient'] = 0
  117. for k, v in kw.items():
  118. if k[0] != '_':
  119. setattr(self, k, v)
  120. def __setattr__(self, name, value):
  121. if name in self.__readonly:
  122. raise AttributeError, "readonly configuration setting"
  123. d = self.__dict__
  124. if name in ('typesNamespace', 'typesNamespaceURI',
  125. 'schemaNamespace', 'schemaNamespaceURI'):
  126. if name[-3:] == 'URI':
  127. base, uri = name[:-3], 1
  128. else:
  129. base, uri = name, 0
  130. if type(value) == StringType:
  131. if NS.NSMAP.has_key(value):
  132. n = (value, NS.NSMAP[value])
  133. elif NS.NSMAP_R.has_key(value):
  134. n = (NS.NSMAP_R[value], value)
  135. else:
  136. raise AttributeError, "unknown namespace"
  137. elif type(value) in (ListType, TupleType):
  138. if uri:
  139. n = (value[1], value[0])
  140. else:
  141. n = (value[0], value[1])
  142. else:
  143. raise AttributeError, "unknown namespace type"
  144. d[base], d[base + 'URI'] = n
  145. try:
  146. d['namespaceStyle'] = \
  147. NS.STMAP_R[(d['typesNamespace'], d['schemaNamespace'])]
  148. except:
  149. d['namespaceStyle'] = ''
  150. elif name == 'namespaceStyle':
  151. value = str(value)
  152. if not NS.STMAP.has_key(value):
  153. raise AttributeError, "unknown namespace style"
  154. d[name] = value
  155. n = d['typesNamespace'] = NS.STMAP[value][0]
  156. d['typesNamespaceURI'] = NS.NSMAP[n]
  157. n = d['schemaNamespace'] = NS.STMAP[value][1]
  158. d['schemaNamespaceURI'] = NS.NSMAP[n]
  159. elif name == 'debug':
  160. d[name] = \
  161. d['returnFaultInfo'] = \
  162. d['dumpHeadersIn'] = \
  163. d['dumpHeadersOut'] = \
  164. d['dumpSOAPIn'] = \
  165. d['dumpSOAPOut'] = value
  166. else:
  167. d[name] = value
  168. Config = SOAPConfig()