def open(self, url, data=None): assert data is None, 'POST requests not supported by CGIClient' parsed_url = urlparse.urlparse(url) environ = os.environ.copy() environ.update({ 'QUERY_STRING': parsed_url.query, 'REQUEST_METHOD': 'GET', 'GATEWAY_INTERFACE': 'CGI/1.1', 'SERVER_ADDR': '127.0.0.1', 'SERVER_NAME': 'localhost', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SOFTWARE': 'MapProxy', }) start_time = time.time() try: p = subprocess.Popen([self.script], env=environ, stdout=subprocess.PIPE, cwd=self.working_directory or os.path.dirname(self.script)) except OSError as ex: if ex.errno == errno.ENOENT: raise SourceError('CGI script not found (%s)' % (self.script, )) elif ex.errno == errno.EACCES: raise SourceError('No permission for CGI script (%s)' % (self.script, )) else: raise stdout = p.communicate()[0] ret = p.wait() if ret != 0: raise HTTPClientError('Error during CGI call (exit code: %d)' % (ret, )) if self.no_headers: content = stdout headers = dict() else: headers, content = split_cgi_response(stdout) status_match = re.match('(\d\d\d) ', headers.get('Status', '')) if status_match: status_code = status_match.group(1) else: status_code = '-' size = len(content) content = IOwithHeaders(BytesIO(content), headers) log_request('%s:%s' % (self.script, parsed_url.query), status_code, size=size, method='CGI', duration=time.time() - start_time) return content
def wms_capapilities_url(url, version): parsed_url = urlparse.urlparse(url) base_req = BaseRequest( url=url.split('?', 1)[0], param=url_decode(parsed_url.query), ) base_req.params['service'] = 'WMS' base_req.params['version'] = version base_req.params['request'] = 'GetCapabilities' return base_req.complete_url
def open(self, url, data=None): assert data is None, 'POST requests not supported by CGIClient' parsed_url = urlparse.urlparse(url) environ = os.environ.copy() environ.update({ 'QUERY_STRING': parsed_url.query, 'REQUEST_METHOD': 'GET', 'GATEWAY_INTERFACE': 'CGI/1.1', 'SERVER_ADDR': '127.0.0.1', 'SERVER_NAME': 'localhost', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SOFTWARE': 'MapProxy', }) start_time = time.time() try: p = subprocess.Popen([self.script], env=environ, stdout=subprocess.PIPE, cwd=self.working_directory or os.path.dirname(self.script) ) except OSError as ex: if ex.errno == errno.ENOENT: raise SourceError('CGI script not found (%s)' % (self.script,)) elif ex.errno == errno.EACCES: raise SourceError('No permission for CGI script (%s)' % (self.script,)) else: raise stdout = p.communicate()[0] ret = p.wait() if ret != 0: raise HTTPClientError('Error during CGI call (exit code: %d)' % (ret, )) if self.no_headers: content = stdout headers = dict() else: headers, content = split_cgi_response(stdout) status_match = re.match('(\d\d\d) ', headers.get('Status', '')) if status_match: status_code = status_match.group(1) else: status_code = '-' size = len(content) content = IOwithHeaders(BytesIO(content), headers) log_request('%s:%s' % (self.script, parsed_url.query), status_code, size=size, method='CGI', duration=time.time()-start_time) return content
def setup(self): url = os.environ[self.riak_url_env] urlparts = urlparse.urlparse(url) protocol = urlparts.scheme.lower() node = {'host': urlparts.hostname} if ':' in urlparts.hostname: if protocol == 'pbc': node['pb_port'] = urlparts.port if protocol in ('http', 'https'): node['http_port'] = urlparts.port db_name = 'mapproxy_test_%d' % random.randint(0, 100000) TileCacheTestBase.setup(self) self.cache = RiakCache([node], protocol, db_name, tile_grid=tile_grid(3857, name='global-webmarcator'))
def setup(self): if not os.environ.get(self.riak_url_env): raise SkipTest() url = os.environ[self.riak_url_env] urlparts = urlparse.urlparse(url) protocol = urlparts.scheme.lower() node = {'host': urlparts.hostname} if ':' in urlparts.hostname: if protocol == 'pbc': node['pb_port'] = urlparts.port if protocol in ('http', 'https'): node['http_port'] = urlparts.port db_name = 'mapproxy_test_%d' % random.randint(0, 100000) TileCacheTestBase.setup(self) self.cache = RiakCache([node], protocol, db_name, tile_grid=tile_grid(3857, name='global-webmarcator'))