Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except KeyError:
logger.info('Unknown Command: {0}'.format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = '\x08\x00\x00\x00'.encode('utf-8')
return AmsResponseData(state, error_code, ''.encode('utf-8'))
# Set no error in response
error_code = ('\x00' * 4).encode('utf-8')
response_data = error_code + response_content
return AmsResponseData(state, request.ams_header.error_code,
response_data)
if __name__ == '__main__':
server = AdsTestServer(handler=AdvancedHandler())
try:
server.start()
server.join()
except:
server.close()
def setUpClass(cls):
# Start dummy ADS Endpoint
cls.test_server = AdsTestServer(logging=False)
cls.test_server.start()
# Endpoint AMS Address
cls.endpoint = AmsAddr(TEST_SERVER_AMS_NET_ID, TEST_SERVER_AMS_PORT)
# Open AMS Port
ads.open_port()
# wait a bit otherwise error might occur
time.sleep(1)
# NOTE: On a Windows machine, this route needs to be configured
# within the router service for the tests to work.
if platform_is_linux():
ads.add_route(cls.endpoint, TEST_SERVER_IP_ADDRESS)
def setUpClass(cls):
# type: () -> None
"""Setup the ADS testserver."""
cls.test_server = AdsTestServer(logging=True)
cls.test_server.start()
# wait a bit otherwise error might occur
time.sleep(1)
def setUpClass(cls):
# Start dummy ADS Endpoint
cls.test_server = AdsTestServer(AdvancedHandler(), logging=False)
cls.test_server.start()
# Endpoint AMS Address
cls.endpoint = AmsAddr(TEST_SERVER_AMS_NET_ID, TEST_SERVER_AMS_PORT)
# Open AMS Port
ads.open_port()
# wait a bit otherwise error might occur
time.sleep(1)
# NOTE: On a Windows machine, this route needs to be configured
# within the router service for the tests to work.
if platform_is_linux():
ads.add_route(cls.endpoint, TEST_SERVER_IP_ADDRESS)
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Set option to allow instant socket reuse after shutdown
self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.server.bind((self.ip_address, self.port))
# Make sure we clean up on exit
atexit.register(self.close)
# Daemonize the server thread
# Container for client connection threads
self.clients = [] # type: List[AdsClientConnection]
super(AdsTestServer, self).__init__(*args, **kwargs)
self.daemon = True
except KeyError:
logger.info("Unknown Command: {0}".format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = "\x08\x00\x00\x00".encode("utf-8")
return AmsResponseData(state, error_code, "".encode("utf-8"))
# Set no error in response
error_code = ("\x00" * 4).encode("utf-8")
response_data = error_code + response_content
return AmsResponseData(state, request.ams_header.error_code, response_data)
if __name__ == "__main__":
server = AdsTestServer(handler=AdvancedHandler())
try:
server.start()
server.join()
except:
server.close()
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Set option to allow instant socket reuse after shutdown
self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.server.bind((self.ip_address, self.port))
# Make sure we clean up on exit
atexit.register(self.close)
# Daemonize the server thread
# Container for client connection threads
self.clients = []
super(AdsTestServer, self).__init__(*args, **kwargs)
self.daemon = True