Exemple #1
0
 def __init__(self,
              connection: Union[ManagesNames, AbstractConnection],
              authmethods: Union[str, List[str]] = 'anonymous',
              authid: str = None,
              authrole: str = None,
              authextra: dict = None,
              resumable: bool = None,
              resume_session: int = None,
              resume_token: str = None,
              **session_kwargs):
     super().__init__(connection=connection,
                      authmethods=authmethods,
                      authid=authid,
                      authrole=authrole,
                      authextra=authextra,
                      resumable=resumable,
                      resume_session=resume_session,
                      resume_token=resume_token,
                      **session_kwargs)
     self.__init_has_name__(connection)
     self.__init_has_future__(connection.manager.loop.create_future())
     call_manager_class = get_class(environ['call_manager'])
     self._call_manager = call_manager_class(self)
     self._call_manager_proxy = ManagesNamesProxy(self._call_manager)
     registration_manager_class = get_class(environ['registration_manager'])
     self._register_manager = registration_manager_class(self)
     self._register_manager_proxy = ManagesNamesProxy(
         self._register_manager)
     publisher_manager_class = get_class(environ['publisher_manager'])
     self._publisher_manager = publisher_manager_class(self)
     self._publisher_manager_proxy = ManagesNamesProxy(
         self._publisher_manager)
     subscription_manager_class = get_class(environ['subscription_manager'])
     self._subscribe_manager = subscription_manager_class(self)
     self._subscribe_manager_proxy = ManagesNamesProxy(
         self._subscribe_manager)
     application_runner_class = get_class(environ['application_runner'])
     runner = application_runner_class(connection.uri, connection.realm,
                                       connection.extra,
                                       connection.serializers,
                                       connection.ssl, connection.proxy,
                                       connection.headers)
     asyncio.ensure_future(
         runner.run(
             make=self._factory,
             start_loop=False,
             log_level='info'  # TODO: Support custom log levels?
         ),
         loop=connection.manager.loop)
Exemple #2
0
    def __call__(self,
                 uri: str,
                 realm: str = None,
                 extra=None,
                 serializers=None,
                 ssl=None,
                 proxy=None,
                 headers=None,
                 *,
                 name: str = None) -> AbstractConnection:

        print(f'Generating connection to {realm}@{uri} with name {name}')
        connection_class = get_class(environ['connection'])
        connection = connection_class(manager=self,
                                      uri=uri,
                                      realm=realm,
                                      extra=extra,
                                      serializers=serializers,
                                      ssl=ssl,
                                      proxy=proxy,
                                      headers=headers)
        connection_id = id(connection)
        self._items[connection_id] = connection
        self._items__names[connection_id] = name
        self._names__items[name] = connection_id
        return connection
Exemple #3
0
    def __call__(self,
                 procedure: str,
                 on_progress: Callable = None,
                 *,
                 name: str = None,
                 **call_options_kwargs) -> AbstractCall:
        """
        Generates a Callable which can be called to initiate an asynchronous
        request to the WAMP router this Session is connected to

        :param procedure:
        :param on_progress:
        :param timeout:
        :param name: Optional. Keyword-only argument.
        :return:
        """
        # while name is None or name in self.__call_name__calls:
        #     name = generate_name(name)
        print(f'Generating call to {procedure} with name {name}')
        call_class = get_class(environ['call'])
        call = call_class(manager=self,
                          procedure=procedure,
                          on_progress=on_progress,
                          call_options_kwargs=call_options_kwargs)
        call_id = id(call)
        self._items[call_id] = call
        self._items__names[call_id] = name
        self._names__items[name] = call_id
        return call
Exemple #4
0
 def session(self,
             authmethods: Union[str, List[str]] = 'anonymous',
             authid: str = None,
             authrole: str = None,
             authextra: dict = None,
             resumable: bool = None,
             resume_session: int = None,
             resume_token: str = None,
             *,
             name: str = None,
             **session_kwargs) -> AbstractSession:
     print(f'Generating {authmethods} session to {self._realm}@{self._uri} '
           f'with name {name}')
     session_class = get_class(environ['session'])
     session = session_class(connection=self,
                             authmethods=authmethods,
                             authid=authid,
                             authrole=authrole,
                             authextra=authextra,
                             resumable=resumable,
                             resume_session=resume_session,
                             resume_token=resume_token,
                             **session_kwargs)
     session_id = id(session)
     self._items[session_id] = session
     self._items__names[session_id] = name
     self._names__items[name] = session_id
     return session
Exemple #5
0
def start_repl(loop: asyncio.AbstractEventLoop):
    """
    Start the REPL and attach it to the provided event loop
    :param loop:
    :return:
    """
    config_file = environ.get('config_file', DEFAULT_CONFIG_FILE)
    if os.path.exists(config_file):
        configure = partial(run_config, config_file=config_file)
    else:
        configure = default_configure
    manager_class = get_class(environ['connection_manager'])
    manager = manager_class(loop)
    yield from embed(globals={},
                     locals={
                         'connect': manager,
                         'connect_to': manager,
                         'connections': ManagesNamesProxy(manager),
                     },
                     title='AutoBahn-Python REPL',
                     return_asyncio_coroutine=True,
                     patch_stdout=True,
                     configure=configure,
                     history_filename=environ.get('history_file',
                                                  DEFAULT_HISTORY_FILE))
Exemple #6
0
 def __call__(self, *args, **kwargs) -> AbstractInvocation:
     name = self._generate_name()
     print(f'Invoking {self.procedure} with name {name}')
     invocation_class = get_class(environ['invocation'])
     invocation = invocation_class(call=self, args=args, kwargs=kwargs)
     invocation_id = id(invocation)
     self._items[invocation_id] = invocation
     self._items__names[invocation_id] = name
     self._names__items[name] = invocation_id
     return invocation
 def __call__(self, *args, **kwargs) -> AbstractPublication:
     name = self._generate_name()
     publication_class = get_class(environ['publication'])
     publication = publication_class(publisher=self,
                                     args=args,
                                     kwargs=kwargs)
     publication_id = id(publication)
     self._items[publication_id] = publication
     self._items__names[publication_id] = name
     self._names__items[name] = publication_id
     return publication
 def __call__(self,
              topic: str,
              *,
              name: str = None,
              **publish_options_kwargs) -> AbstractPublisher:
     print(f'Generating publisher for {topic} with name {name}')
     publisher_class: AbstractPublisher = get_class(environ['publisher'])
     publisher = publisher_class(
         manager=self,
         topic=topic,
         publish_options_kwargs=publish_options_kwargs)
     publisher_id = id(publisher)
     self._items[publisher_id] = publisher
     self._items__names[publisher_id] = name
     self._names__items[name] = publisher_id
     return publisher
 def __call__(self,
              topic: str,
              handler: Callable = None,
              *,
              name: str = None,
              **subscribe_options_kwargs) -> AbstractSubscription:
     print(f'Generating subscription for {topic} with name {name}')
     subscription_class = get_class(environ['subscription'])
     subscription = subscription_class(
         manager=self,
         topic=topic,
         handler=handler,
         subscribe_options_kwargs=subscribe_options_kwargs)
     subscription_id = id(subscription)
     self._items[subscription_id] = subscription
     self._items__names[subscription_id] = name
     self._names__items[name] = subscription_id
     return subscription
Exemple #10
0
 def __call__(self,
              procedure: str,
              endpoint: Callable = None,
              prefix: str = None,
              *,
              name: str = None,
              **register_options_kwargs) -> AbstractRegistration:
     print(f'Generating registration for {procedure} with name {name}')
     registration_class = get_class(environ['registration'])
     registration = registration_class(
         manager=self,
         procedure=procedure,
         endpoint=endpoint,
         prefix=prefix,
         register_options_kwargs=register_options_kwargs)
     register_id = id(registration)
     self._items[register_id] = registration
     self._items__names[register_id] = name
     self._names__items[name] = register_id
     return registration
Exemple #11
0
 def name_for(self, item):
     registration_class = get_class(environ['registration'])
     assert isinstance(item, registration_class)
     return super().name_for(id(item))
Exemple #12
0
 def name_for(self, item):
     connection_class = get_class(environ['connection'])
     assert isinstance(item, connection_class)
     return super().name_for(id(item))
 def name_for(self, item):
     publisher_class = get_class(environ['publisher'])
     assert isinstance(item, publisher_class)
     return super().name_for(id(item))
Exemple #14
0
 def name_for(self, item):
     call_class = get_class(environ['call'])
     assert isinstance(item, call_class)
     return super().name_for(id(item))
 def name_for(self, item):
     subscription_class = get_class(environ['subscription'])
     assert isinstance(item, subscription_class)
     return super().name_for(id(item))
Exemple #16
0
 def name_for(self, item):
     invocation_class = get_class(environ['invocation'])
     assert isinstance(item, invocation_class)
     return super().name_for(id(item))
Exemple #17
0
 def _factory(self, config: ComponentConfig):
     application_session_class = get_class(environ['application_session'])
     self._application_session = application_session_class(
         self, self._future, config)
     return self._application_session