Skip to content

Commit

Permalink
Allow a SAPRoutedStreamSocket to bypass the NI layer if no route was …
Browse files Browse the repository at this point in the history
…specified but talk mode was set to raw. By doing this a client can ask for a routed stream socket for protocols that doesn't use the NI layer (e.g. HTTP).
  • Loading branch information
martingalloar committed Feb 17, 2017
1 parent ba9660c commit c33e720
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pysap/SAPRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,10 @@ def send(self, packet):
@classmethod
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`.
"""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}
Expand Down Expand Up @@ -666,10 +669,17 @@ def get_nisocket(cls, host=None, port=None, route=None, password=None,
: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 no route was provided, check the talk mode
if route is None:
return SAPNIStreamSocket.get_nisocket(host, port, **kwargs)
# If talk mode is raw, create a new StreamSocket and get rid of the
# NI layer completely
if talk_mode == 1:
sock = socket.create_connection((host, port))
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
Expand Down

0 comments on commit c33e720

Please sign in to comment.