def translateEntry(meta): # Translates parameter setting into hash tmp = md5() for key in ifilter(lambda k: k in meta, keys_store): if str(meta[key]): tmp.update(str2bytes(key)) tmp.update(str2bytes(str(meta[key]))) return { ParameterInfo.HASH: tmp.hexdigest(), 'GC_PARAM': meta['GC_PARAM'], ParameterInfo.ACTIVE: meta[ParameterInfo.ACTIVE] }
def request(self, mode, url, headers, params=None, data=None, cert=None): request_fun = { RestSession.GET: lambda: 'GET', RestSession.PUT: lambda: 'PUT', RestSession.POST: lambda: 'POST', RestSession.DELETE: lambda: 'DELETE' }[mode] if params: url += '?%s' % urlencode(params) if data: data = str2bytes(data) request = Request(url=url, data=data, headers=headers) request.get_method = request_fun if cert: class HTTPSClientAuthHandler(HTTPSHandler): def https_open(self, req): return self.do_open(self.getConnection, req) def getConnection(self, host, timeout=None): return HTTPSConnection(host, key_file=cert, cert_file=cert) opener = build_opener(HTTPSClientAuthHandler()) else: opener = build_opener() return bytes2str(opener.open(request).read())
def request(self, mode, url, headers, params=None, data=None, cert=None): request_fun = {RestSession.GET: lambda: 'GET', RestSession.PUT: lambda: 'PUT', RestSession.POST: lambda: 'POST', RestSession.DELETE: lambda: 'DELETE'}[mode] if params: url += '?%s' % Urllib2Session.urlencode(params) if data: data = str2bytes(data) request = Urllib2Session.Request(url=url, data=data, headers=headers) request.get_method = request_fun return bytes2str(self._get_opener(cert).open(request).read())
def _handle_input(cls, fd_write, buffer, event_shutdown): local_buffer = '' while not event_shutdown.is_set(): if local_buffer: # local buffer has leftover bytes from last write - just poll for more local_buffer = buffer.get(timeout=0, default='') else: # empty local buffer - wait for data to process local_buffer = buffer.get(timeout=1, default='') if local_buffer: _wait_fd(fd_write_list=[fd_write]) if not event_shutdown.is_set(): written = ignore_exception(OSError, 0, os.write, fd_write, str2bytes(local_buffer)) local_buffer = local_buffer[written:]
def _handle_input(cls, fd_write, buffer, event_shutdown): local_buffer = '' while not event_shutdown.is_set(): if local_buffer: # local buffer has leftover bytes from last write - just poll for more local_buffer = buffer.get(timeout=0, default='') else: # empty local buffer - wait for data to process local_buffer = buffer.get(timeout=1, default='') if local_buffer: _wait_fd(fd_write_list=[fd_write]) if not event_shutdown.is_set(): written = ignore_exception(OSError, 0, os.write, fd_write, str2bytes(local_buffer)) local_buffer = local_buffer[written:]
def request(self, mode, url, headers, params=None, data=None, cert=None): request_fun = { RestSession.GET: lambda: 'GET', RestSession.PUT: lambda: 'PUT', RestSession.POST: lambda: 'POST', RestSession.DELETE: lambda: 'DELETE' }[mode] if params: url += '?%s' % Urllib2Session.urlencode(params) if data: data = str2bytes(data) request = Urllib2Session.Request(url=url, data=data, headers=headers) request.get_method = request_fun return bytes2str(self._get_opener(cert).open(request).read())
def _handle_input(cls, fd, buffer, event_shutdown): local_buffer = '' while not event_shutdown.is_set(): if local_buffer: # if local buffer has leftover bytes from last write - just poll for more local_buffer = buffer.get(timeout=0, default='') else: # empty local buffer - wait for data to process local_buffer = buffer.get(timeout=1, default='') if local_buffer: waitFD(write=[fd]) if not event_shutdown.is_set(): try: written = os.write(fd, str2bytes(local_buffer)) except OSError: written = 0 local_buffer = local_buffer[written:]
def _handle_input(cls, fd, buffer, event_shutdown): local_buffer = '' while not event_shutdown.is_set(): if local_buffer: # if local buffer has leftover bytes from last write - just poll for more local_buffer = buffer.get(timeout = 0, default = '') else: # empty local buffer - wait for data to process local_buffer = buffer.get(timeout = 1, default = '') if local_buffer: waitFD(write = [fd]) if not event_shutdown.is_set(): try: written = os.write(fd, str2bytes(local_buffer)) except OSError: written = 0 local_buffer = local_buffer[written:]
def _request(self, request_fun, url, api, headers, params=None, data=None): url = self._get_url(url, api) if params: url += '?%s' % urlencode(params) request_headers = self._get_headers(headers) if data: data = str2bytes(data) request = Request(url=url, data=data, headers=request_headers) request.get_method = request_fun if self._cert: cert_handler = self._https_handler() opener = build_opener(cert_handler) else: opener = build_opener() return bytes2str(opener.open(request).read())
def _request(self, request_fun, url, api, headers, params = None, data = None): url = self._get_url(url, api) if params: url += '?%s' % urlencode(params) request_headers = self._get_headers(headers) if data: data = str2bytes(data) request = Request(url = url, data = data, headers = request_headers) request.get_method = request_fun if self._cert: cert_handler = self._https_handler() opener = build_opener(cert_handler) else: opener = build_opener() return bytes2str(opener.open(request).read())
def request(self, mode, url, headers, params = None, data = None, cert = None): request_fun = {RestSession.GET: lambda: 'GET', RestSession.PUT: lambda: 'PUT', RestSession.POST: lambda: 'POST', RestSession.DELETE: lambda: 'DELETE'}[mode] if params: url += '?%s' % urlencode(params) if data: data = str2bytes(data) request = Request(url = url, data = data, headers = headers) request.get_method = request_fun if cert: class HTTPSClientAuthHandler(HTTPSHandler): def https_open(self, req): return self.do_open(self.getConnection, req) def getConnection(self, host, timeout = None): return HTTPSConnection(host, key_file = cert, cert_file = cert) opener = build_opener(HTTPSClientAuthHandler()) else: opener = build_opener() return bytes2str(opener.open(request).read())
def write(self, data): self._fp.write(str2bytes(data))
def __init__(self, name, lines): BytesBufferBase.__init__(self, str2bytes(str.join('', lines))) self.name = name self.size = len(self.getvalue())
def write(self, data): self._fp.write(str2bytes(data))
def __init__(self, name, lines): BytesBufferBase.__init__(self, str2bytes(str.join('', lines))) self.name = name self.size = len(self.getvalue())