def __init__(self, xig_core, url, xbee_addr, ignore_response=False): self.__core = xig_core self.__write_buf = "" self.__read_buf = "" self.__state = HTTPSession.STATE_INIT self.__xbee_addr = xbee_addr self.__max_buf_size = self.__core.getConfig().global_max_buf_size self.__command_parser = StreamingCommandParser() self.__httpConn = None self.__httpMethod = "GET" self.__httpRequest = "" self.__httpResponse = None # Must use different constants for different platforms: if sys.platform.startswith("digi"): self.__eWouldBlockExcs = (errno.EWOULDBLOCK, ) elif sys.platform.startswith("win"): self.__eWouldBlockExcs = (errno.EWOULDBLOCK, errno.WSAEWOULDBLOCK) else: # Sanity, a la Linux & Mac OSX self.__eWouldBlockExcs = (errno.EWOULDBLOCK, errno.EAGAIN) # Parse URL: self.__urlUsername = None self.__urlPassword = "" self.parse_url(url) # Perform HTTP connection: try: self.__connect(ignore_response) except httplib.InvalidURL: self.__do_error("unable to perform HTTP request; invalid URL") # Setup command parser: self.__command_parser.register_command( Command("abort\r", self.__commandAbortHandler)) self.__command_parser.register_command( Command("abort\n", self.__commandAbortHandler)) self.__command_parser.register_command( Command("xig://abort\r", self.__commandAbortHandler)) self.__command_parser.register_command( Command("xig://abort\n", self.__commandAbortHandler))
def __init__(self, xig_core, url, xbee_addr): self.__core = xig_core self.__toxbee_buf = "" self.__fromxbee_buf = "" self.__xbee_addr = xbee_addr self.__state = UDPSession.STATE_INIT self.__max_buf_size = self.__core.getConfig().global_max_buf_size self.__command_parser = StreamingCommandParser() # Parse URL: parsedUrl = urlparse.urlsplit(url) self.__urlScheme = parsedUrl[0] self.__urlNetLoc = parsedUrl[1] logger.info("session to %s" % (self.__urlNetLoc)) # check for portnumber in url if ':' not in self.__urlNetLoc: self.__do_error( "UDP URL requires port number (e.g. udp://host:port)") return self.__urlNetLoc, portStr = self.__urlNetLoc.split(':') try: self.__urlPort = int(portStr) except ValueError: self.__do_error("UDP port number must be integer") return # Create command handlers: self.__command_parser.register_command( Command("xig://abort\r", self.__commandAbortHandler)) self.__command_parser.register_command( Command("xig://abort\n", self.__commandAbortHandler)) # Perform UDP connection: self.__create_socket()