def __init__(self, url, http, body='', expectedHeader=None, expectedFields=[], onUnexpectedResponse=None): if onUnexpectedResponse is None: onUnexpectedResponse = self.__onUnexpectedResponse response = HTTPUtil.getHTTPResponse(url, http, body) if expectedHeader is not None: if response[0] != expectedHeader: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return response = response[1:] self.dict = {} for line in response: if not len(line): continue try: name, value = line.split('=', 1) except ValueError, e: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return if len(expectedFields): if name not in expectedFields: self.notify.warning( "received field '%s' that is not in expected field list" % name) self.dict[name] = value
def __init__(self, url, http, body = '', expectedHeader = None, expectedFields = [], onUnexpectedResponse = None): if onUnexpectedResponse is None: onUnexpectedResponse = self.__onUnexpectedResponse response = HTTPUtil.getHTTPResponse(url, http, body) if expectedHeader is not None: if response[0] != expectedHeader: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return response = response[1:] self.dict = {} for line in response: if not len(line): continue try: name, value = line.split('=', 1) except ValueError, e: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return if len(expectedFields): if name not in expectedFields: self.notify.warning("received field '%s' that is not in expected field list" % name) self.dict[name] = value
def __init__(self, url, http, body='', expectedHeader=None, expectedFields=[], onUnexpectedResponse=None): """ expectedHeader is what we expect on the first line of the response. expectedFields is a list of keys that we expect to get back; if we don't get all of them, it's considered an error on error, will raise a RemoteValueSet.UnexpectedResponse (unless you override 'onUnexpectedResponse'; onUnexpectedResponse should be a function that takes an error-message string. Note that the internal state of a RemoteValueSet will be undefined if onUnexpectedResponse is called.) """ if onUnexpectedResponse is None: onUnexpectedResponse = self.__onUnexpectedResponse # get the response from the server response = HTTPUtil.getHTTPResponse(url, http, body) if expectedHeader is not None: if response[0] != expectedHeader: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return # eat the header response = response[1:] # put the key/value pairs in a dictionary self.dict = {} for line in response: # skip blank lines if not len(line): continue # separate the constant name and its value # '1' means only make one split (the first one, from the left) try: name, value = line.split('=', 1) except ValueError, e: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return if len(expectedFields): if not name in expectedFields: self.notify.warning("received field '%s' that is not " "in expected field list" % name) self.dict[name] = value
def __init__(self, url, body='', expectedHeader=None, expectedFields=[], onUnexpectedResponse=None): if onUnexpectedResponse is None: onUnexpectedResponse = self._RemoteValueSet__onUnexpectedResponse response = HTTPUtil.getHTTPResponse(url, body) if expectedHeader is not None: if response[0] != expectedHeader: errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None response = response[1:] self.dict = {} for line in response: if not len(line): continue try: (name, value) = line.split('=', 1) except ValueError: e = None errMsg = 'unexpected response: %s' % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None if len(expectedFields): if not (name in expectedFields): self.notify.warning( "received field '%s' that is not in expected field list" % name) self.dict[name] = value for name in expectedFields: if not self.dict.has_key(name): errMsg = "missing expected field '%s'" % name self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None
def __init__(self, url, http, body="", expectedHeader=None, expectedFields=[], onUnexpectedResponse=None): if onUnexpectedResponse is None: onUnexpectedResponse = self._RemoteValueSet__onUnexpectedResponse response = HTTPUtil.getHTTPResponse(url, http, body) if expectedHeader is not None: if response[0] != expectedHeader: errMsg = "unexpected response: %s" % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None response = response[1:] self.dict = {} for line in response: if not len(line): continue try: (name, value) = line.split("=", 1) except ValueError: e = None errMsg = "unexpected response: %s" % response self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None if len(expectedFields): if name not in expectedFields: self.notify.warning("received field '%s' that is not in expected field list" % name) self.dict[name] = value for name in expectedFields: if not self.dict.has_key(name): errMsg = "missing expected field '%s'" % name self.notify.warning(errMsg) onUnexpectedResponse(errMsg) return None continue