예제 #1
0
    def get_nisocket(cls, host=None, port=None, route=None, password=None,
                     talk_mode=None, router_version=None, **kwargs):
        """Helper function to obtain a :class:`SAPRoutedStreamSocket`.

        :param host: target host to connect to if not specified in the route
        :type host: C{string}

        :param port: target port to connect to if not specified in the route
        :type port: ``int``

        :param route: route to use for determining the SAP Router to connect
        :type route: C{string} or ``list`` of :class:`SAPRouterRouteHop`

        :param password: target password if not specified in the route
        :type password: C{string}

        :param talk_mode: the talk mode to use for requesting the route
        :type talk_mode: ``int``

        :param router_version: the router version to use for requesting the
            route
        :type router_version: ``int``

        :keyword kwargs: arguments to pass to :class:`SAPRoutedStreamSocket`
            constructor

        :return: connected socket through the specified route
        :rtype: :class:`SAPRoutedStreamSocket`

        :raise SAPRouteException: if the route request to the target host/port
            was not accepted by the SAP Router

        :raise socket.error: if the connection to the target host/port failed
            or the SAP Router returned an error
        """
        # If no route was provided, use the standard SAPNIStreamSocket
        # get_nisocket method
        if route is None:
            return SAPNIStreamSocket.get_nisocket(host, port, **kwargs)

        # If the route was provided using a route string, convert it to a
        # list of hops
        if isinstance(route, str):
            route = SAPRouterRouteHop.from_string(route)

        # If the host and port were specified, we need to add a new hop to
        # the route
        if host is not None and port is not None:
            route.append(SAPRouterRouteHop(hostname=host,
                                           port=port,
                                           password=password))

        # Connect to the first hop in the route (it should be the SAP Router)
        sock = socket.create_connection((route[0].hostname, int(route[0].port)))

        # Create a SAPRoutedStreamSocket instance specifying the route
        return cls(sock, route, talk_mode, router_version, **kwargs)
예제 #2
0
    def get_nisocket(cls, host=None, port=None, route=None, password=None,
                     talk_mode=None, router_version=None, **kwargs):
        """Helper function to obtain a :class:`SAPRoutedStreamSocket`.

        :param host: target host to connect to if not specified in the route
        :type host: C{string}

        :param port: target port to connect to if not specified in the route
        :type port: ``int``

        :param route: route to use for determining the SAP Router to connect
        :type route: C{string} or ``list`` of :class:`SAPRouterRouteHop`

        :param password: target password if not specified in the route
        :type password: C{string}

        :param talk_mode: the talk mode to use for requesting the route
        :type talk_mode: ``int``

        :param router_version: the router version to use for requesting the
            route
        :type router_version: ``int``

        :keyword kwargs: arguments to pass to :class:`SAPRoutedStreamSocket`
            constructor

        :return: connected socket through the specified route
        :rtype: :class:`SAPRoutedStreamSocket`

        :raise SAPRouteException: if the route request to the target host/port
            was not accepted by the SAP Router

        :raise socket.error: if the connection to the target host/port failed
            or the SAP Router returned an error
        """
        # If no route was provided, use the standard SAPNIStreamSocket
        # get_nisocket method
        if route is None:
            return SAPNIStreamSocket.get_nisocket(host, port, **kwargs)

        # If the route was provided using a route string, convert it to a
        # list of hops
        if isinstance(route, str):
            route = SAPRouterRouteHop.from_string(route)

        # If the host and port were specified, we need to add a new hop to
        # the route
        if host is not None and port is not None:
            route.append(SAPRouterRouteHop(hostname=host,
                                           port=port,
                                           password=password))

        # Connect to the first hop in the route (it should be the SAP Router)
        sock = socket.create_connection((route[0].hostname, int(route[0].port)))

        # Create a SAPRoutedStreamSocket instance specifying the route
        return cls(sock, route, talk_mode, router_version, **kwargs)
예제 #3
0
    def get_nisocket(cls, host, port, **kwargs):
        """Helper function to obtain a :class:`SAPNIStreamSocket`.

        :param host: host to connect to
        :type host: C{string}

        :param port: port to connect to
        :type port: ``int``

        :keyword kwargs: arguments to pass to :class:`SAPNIStreamSocket` constructor

        :return: connected socket
        :rtype: :class:`SAPNIStreamSocket`

        :raise socket.error: if the connection to the target host/port failed
        """
        sock = socket.create_connection((host, port))
        return cls(sock, **kwargs)
예제 #4
0
파일: SAPNI.py 프로젝트: aolihu/pysap
    def get_nisocket(cls, host, port, **kwargs):
        """Helper function to obtain a L{SAPNIStreamSocket}.

        @param host: host to connect to
        @type host: C{string}

        @param port: port to connect to
        @type port: C{int}

        @keyword kwargs: arguments to pass to L{SAPNIStreamSocket} constructor

        @return: connected socket
        @rtype: L{SAPNIStreamSocket}

        @raise socket.error: if the connection to the target host/port failed
        """
        sock = socket.create_connection((host, port))
        return cls(sock, **kwargs)
예제 #5
0
파일: SAPNI.py 프로젝트: deneme056/pysap
    def get_nisocket(cls, host, port, **kwargs):
        """Helper function to obtain a L{SAPNIStreamSocket}.

        @param host: host to connect to
        @type host: C{string}

        @param port: port to connect to
        @type port: C{int}

        @keyword kwargs: arguments to pass to L{SAPNIStreamSocket} constructor

        @return: connected socket
        @rtype: L{SAPNIStreamSocket}

        @raise socket.error: if the connection to the target host/port failed
        """
        sock = socket.create_connection((host, port))
        return cls(sock, **kwargs)
예제 #6
0
파일: SAPNI.py 프로젝트: HPxpat/pysap
    def get_nisocket(cls, host, port, **kwargs):
        """Helper function to obtain a :class:`SAPNIStreamSocket`.

        :param host: host to connect to
        :type host: C{string}

        :param port: port to connect to
        :type port: ``int``

        :keyword kwargs: arguments to pass to :class:`SAPNIStreamSocket` constructor

        :return: connected socket
        :rtype: :class:`SAPNIStreamSocket`

        :raise socket.error: if the connection to the target host/port failed
        """
        sock = socket.create_connection((host, port))
        return cls(sock, **kwargs)
예제 #7
0
    def get_nisocket(cls,
                     host=None,
                     port=None,
                     route=None,
                     password=None,
                     talk_mode=None,
                     router_version=None,
                     **kwargs):
        """Helper function to obtain a :class:`SAPRoutedStreamSocket`. If no
        route is specified, it returns a plain `SAPNIStreamSocket`. If no
        route is specified and the talk mode is raw, it returns a plain
        `StreamSocket` as it's assumed that the NI layer is not desired.

        :param host: target host to connect to if not specified in the route
        :type host: C{string}

        :param port: target port to connect to if not specified in the route
        :type port: ``int``

        :param route: route to use for determining the SAP Router to connect
        :type route: C{string} or ``list`` of :class:`SAPRouterRouteHop`

        :param password: target password if not specified in the route
        :type password: C{string}

        :param talk_mode: the talk mode to use for requesting the route
        :type talk_mode: ``int``

        :param router_version: the router version to use for requesting the
            route
        :type router_version: ``int``

        :keyword kwargs: arguments to pass to :class:`SAPRoutedStreamSocket`
            constructor

        :return: connected socket through the specified route
        :rtype: :class:`SAPRoutedStreamSocket`

        :raise SAPRouteException: if the route request to the target host/port
            was not accepted by the SAP Router

        :raise socket.error: if the connection to the target host/port failed
            or the SAP Router returned an error
        """
        # If no route was provided, check the talk mode
        if route is None:
            # If talk mode is raw, create a new StreamSocket and get rid of the
            # NI layer completely and force the base class to Raw.
            if talk_mode == ROUTER_TALK_MODE_NI_RAW_IO:
                sock = socket.create_connection((host, port))
                if "base_cls" in kwargs:
                    kwargs["basecls"] = Raw
                    del (kwargs["base_cls"])
                return StreamSocket(sock, **kwargs)

            # Otherwise use the standard SAPNIStreamSocket get_nisocket method
            else:
                return SAPNIStreamSocket.get_nisocket(host, port, **kwargs)

        # If the route was provided using a route string, convert it to a
        # list of hops
        if isinstance(route, str):
            route = SAPRouterRouteHop.from_string(route)

        # If the host and port were specified, we need to add a new hop to
        # the route
        if host is not None and port is not None:
            route.append(
                SAPRouterRouteHop(hostname=host, port=port, password=password))

        # Connect to the first hop in the route (it should be the SAP Router)
        sock = socket.create_connection(
            (route[0].hostname, int(route[0].port)))

        # Create a SAPRoutedStreamSocket instance specifying the route
        return cls(sock, route, talk_mode, router_version, **kwargs)