Ejemplo n.º 1
0
class WampProtocol:
    """
   Base protocol class for Wamp RPC/PubSub.
   """

    MESSAGE_TYPEID_WELCOME = 0
    """
   Server-to-client welcome message containing session ID.
   """

    MESSAGE_TYPEID_PREFIX = 1
    """
   Client-to-server message establishing a URI prefix to be used in CURIEs.
   """

    MESSAGE_TYPEID_CALL = 2
    """
   Client-to-server message initiating an RPC.
   """

    MESSAGE_TYPEID_CALL_RESULT = 3
    """
   Server-to-client message returning the result of a successful RPC.
   """

    MESSAGE_TYPEID_CALL_ERROR = 4
    """
   Server-to-client message returning the error of a failed RPC.
   """

    MESSAGE_TYPEID_SUBSCRIBE = 5
    """
   Client-to-server message subscribing to a topic.
   """

    MESSAGE_TYPEID_UNSUBSCRIBE = 6
    """
   Client-to-server message unsubscribing from a topic.
   """

    MESSAGE_TYPEID_PUBLISH = 7
    """
   Client-to-server message publishing an event to a topic.
   """

    MESSAGE_TYPEID_EVENT = 8
    """
   Server-to-client message providing the event of a (subscribed) topic.
   """

    ERROR_URI_BASE = "http://autobahn.tavendo.de/error#"

    ERROR_URI_GENERIC = ERROR_URI_BASE + "generic"
    ERROR_DESC_GENERIC = "generic error"

    ERROR_URI_INTERNAL = ERROR_URI_BASE + "internal"
    ERROR_DESC_INTERNAL = "internal error"

    def connectionMade(self):
        self.debugWamp = self.factory.debugWamp
        self.prefixes = PrefixMap()

    def connectionLost(self, reason):
        pass

    def _protocolError(self, reason):
        if self.debugWamp:
            log.msg("Closing Wamp session on protocol violation : %s" % reason)

        ## FIXME: subprotocols are probably not supposed to close with CLOSE_STATUS_CODE_PROTOCOL_ERROR
        ##
        self.protocolViolation("Wamp RPC/PubSub protocol violation ('%s')" %
                               reason)

    def shrink(self, uri):
        """
      Shrink given URI to CURIE according to current prefix mapping.
      If no appropriate prefix mapping is available, return original URI.

      :param uri: URI to shrink.
      :type uri: str
      :returns str -- CURIE or original URI.
      """
        return self.prefixes.shrink(uri)

    def resolve(self, curieOrUri):
        """
      Resolve given CURIE/URI according to current prefix mapping or return
      None if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or None.
      """
        return self.prefixes.resolve(curieOrUri)

    def resolveOrPass(self, curieOrUri):
        """
      Resolve given CURIE/URI according to current prefix mapping or return
      string verbatim if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or original string.
      """
        return self.prefixes.resolveOrPass(curieOrUri)
Ejemplo n.º 2
0
class WampProtocol:
   """
   Base protocol class for Wamp RPC/PubSub.
   """

   MESSAGE_TYPEID_WELCOME        = 0
   """
   Server-to-client welcome message containing session ID.
   """

   MESSAGE_TYPEID_PREFIX         = 1
   """
   Client-to-server message establishing a URI prefix to be used in CURIEs.
   """

   MESSAGE_TYPEID_CALL           = 2
   """
   Client-to-server message initiating an RPC.
   """

   MESSAGE_TYPEID_CALL_RESULT    = 3
   """
   Server-to-client message returning the result of a successful RPC.
   """

   MESSAGE_TYPEID_CALL_ERROR     = 4
   """
   Server-to-client message returning the error of a failed RPC.
   """

   MESSAGE_TYPEID_SUBSCRIBE      = 5
   """
   Client-to-server message subscribing to a topic.
   """

   MESSAGE_TYPEID_UNSUBSCRIBE    = 6
   """
   Client-to-server message unsubscribing from a topic.
   """

   MESSAGE_TYPEID_PUBLISH        = 7
   """
   Client-to-server message publishing an event to a topic.
   """

   MESSAGE_TYPEID_EVENT          = 8
   """
   Server-to-client message providing the event of a (subscribed) topic.
   """


   ERROR_URI_BASE = "http://autobahn.tavendo.de/error#"

   ERROR_URI_GENERIC = ERROR_URI_BASE + "generic"
   ERROR_DESC_GENERIC = "generic error"

   ERROR_URI_INTERNAL = ERROR_URI_BASE + "internal"
   ERROR_DESC_INTERNAL = "internal error"

   def connectionMade(self):
      self.debugWamp = self.factory.debugWamp
      self.prefixes = PrefixMap()


   def connectionLost(self, reason):
      pass


   def _protocolError(self, reason):
      if self.debugWamp:
         log.msg("Closing Wamp session on protocol violation : %s" % reason)

      ## FIXME: subprotocols are probably not supposed to close with CLOSE_STATUS_CODE_PROTOCOL_ERROR
      ##
      self.protocolViolation("Wamp RPC/PubSub protocol violation ('%s')" % reason)


   def shrink(self, uri):
      """
      Shrink given URI to CURIE according to current prefix mapping.
      If no appropriate prefix mapping is available, return original URI.

      :param uri: URI to shrink.
      :type uri: str
      :returns str -- CURIE or original URI.
      """
      return self.prefixes.shrink(uri)


   def resolve(self, curieOrUri):
      """
      Resolve given CURIE/URI according to current prefix mapping or return
      None if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or None.
      """
      return self.prefixes.resolve(curieOrUri)


   def resolveOrPass(self, curieOrUri):
      """
      Resolve given CURIE/URI according to current prefix mapping or return
      string verbatim if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or original string.
      """
      return self.prefixes.resolveOrPass(curieOrUri)
Ejemplo n.º 3
0
 def connectionMade(self):
     self.debugWamp = self.factory.debugWamp
     self.prefixes = PrefixMap()
Ejemplo n.º 4
0
 def connectionMade(self):
    self.debugWamp = self.factory.debugWamp
    self.prefixes = PrefixMap()
Ejemplo n.º 5
0
class AutobahnProtocol:
   """
   Base protocol class for Autobahn RPC/PubSub.
   """

   MESSAGE_TYPEID_NULL           = 0
   """
   Placeholder for message type of no message.
   """

   MESSAGE_TYPEID_PREFIX         = 1
   """
   Client-to-server message establishing a URI prefix to be used in CURIEs.
   """

   MESSAGE_TYPEID_CALL           = 2
   """
   Client-to-server message initiating an RPC.
   """

   MESSAGE_TYPEID_CALL_RESULT    = 3
   """
   Server-to-client message returning the result of a successful RPC.
   """

   MESSAGE_TYPEID_CALL_ERROR     = 4
   """
   Server-to-client message returning the error of a failed RPC.
   """

   MESSAGE_TYPEID_SUBSCRIBE      = 5
   """
   Client-to-server message subscribing to a topic.
   """

   MESSAGE_TYPEID_UNSUBSCRIBE    = 6
   """
   Client-to-server message unsubscribing from a topic.
   """

   MESSAGE_TYPEID_PUBLISH        = 7
   """
   Client-to-server message publishing an event to a topic.
   """

   MESSAGE_TYPEID_EVENT          = 8
   """
   Server-to-client message providing the event of a (subscribed) topic.
   """


   ERROR_URI_BASE = "http://autobahn.tavendo.de/error#"

   ERROR_URI_GENERIC = ERROR_URI_BASE + "generic"
   ERROR_DESC_GENERIC = "generic error"


   def __init__(self, debug = False):
      self.debug = debug
      self.prefixes = PrefixMap()


   def _newid(self):
      return ''.join([random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_") for i in range(16)])


   def _protocolError(self, reason):
      if self.debug:
         log.msg("Closing Autobahn session on protocol violation : %s" % reason)
      #self.failConnection()
      self.sendClose(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, "Autobahn RPC/PubSub protocol violation ('%s')" % reason)


   def shrinkUri(self, uri):
      """
      Shrink given URI to CURIE according to current prefix mapping.
      If no appropriate prefix mapping is available, return original URI.

      :param uri: URI to shrink.
      :type uri: str
      :returns str -- CURIE or original URI.
      """
      return self.prefixes.shrink(uri)


   def resolveCurie(self, curieOrUri):
      """
      Resolve given CURIE/URI according to current prefix mapping or return
      None if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or None.
      """
      return self.prefixes.resolve(curieOrUri)


   def resolveCurieOrPass(self, curieOrUri):
      """
      Resolve given CURIE/URI according to current prefix mapping or return
      string verbatim if cannot be resolved.

      :param curieOrUri: CURIE or URI.
      :type curieOrUri: str
      :returns: str -- Full URI for CURIE or original string.
      """
      return self.prefixes.resolveOrPass(curieOrUri)
Ejemplo n.º 6
0
 def __init__(self, debug = False):
    self.debug = debug
    self.prefixes = PrefixMap()
Ejemplo n.º 7
0
 def connectionMade(self):
    self.debug_autobahn = self.factory.debug_autobahn
    self.prefixes = PrefixMap()
 def connectionMade(self):
    self.debug_autobahn = self.factory.debug_autobahn
    self.prefixes = PrefixMap()