def __call__(self, environ, start_response): def serialize(dataset): location = construct_url(environ, with_query_string=False) base = location[:location.rfind('/')] context = { 'root': construct_url(environ, with_query_string=False, with_path_info=False, script_name='').rstrip('/'), 'base': base, 'location': location, 'version': '.'.join(str(d) for d in __version__), } renderer = environ.get('pydap.renderer', self.renderer) template = renderer.loader('help.html') output = renderer.render(template, context, output_format='text/html') if hasattr(dataset, 'close'): dataset.close() return [output] self.serialize = serialize return BaseResponse.__call__(self, environ, start_response)
def __call__(self, environ, start_response): def serialize(dataset): location = construct_url(environ, with_query_string=False) base = location[:location.rfind('/')] context = { 'root': construct_url(environ, with_query_string=False, with_path_info=False, script_name='').rstrip('/'), 'base': base, 'location': location, 'version' : '.'.join(str(d) for d in __version__), } renderer = environ.get('pydap.renderer', self.renderer) template = renderer.loader('help.html') output = renderer.render(template, context, output_format='text/html') if hasattr(dataset, 'close'): dataset.close() return [output] self.serialize = serialize return BaseResponse.__call__(self, environ, start_response)
def __call__(self, environ, start_response): # If we came from a post, parse response and redirect to ascii. if environ["REQUEST_METHOD"] == "POST": # Parse POST and redirect to proper response. form = parse_formvars(environ) projection, selection = [], [] for k in form: # Selection. if k.startswith("var1") and form[k] != "--": name = k[5:] sel = "%s%s%s" % (form[k], form["op_%s" % name], form["var2_%s" % name]) selection.append(sel) # Projection. if form[k] == "on": var = [k] i = 0 while "%s[%d]" % (k, i) in form: var.append("[%s]" % form["%s[%d]" % (k, i)]) i += 1 var = "".join(var) if var not in projection: projection.append(var) projection = ",".join(projection) selection = "&".join(selection) query = projection + "&" + selection # Get current location. location = construct_url(environ, with_query_string=False) # Empty queries SHOULD NOT return everything, because this # means the user didn't select any variables. if not query.rstrip("?&"): app = HTTPBadRequest("You did not select any variables.") else: # Replace html extension for ascii and redirect. response = form["response"] redirect = "%s.%s?%s" % (location[:-5], response, query) app = HTTPSeeOther(redirect) return app(environ, start_response) else: self.serialize = self._render(environ) return BaseResponse.__call__(self, environ, start_response)
def __call__(self, environ, start_response): # If we came from a post, parse response and redirect to ascii. if environ['REQUEST_METHOD'] == 'POST': # Parse POST and redirect to proper response. form = parse_formvars(environ) projection, selection = [], [] for k in form: # Selection. if k.startswith('var1') and form[k] != '--': name = k[5:] sel = '%s%s%s' % (form[k], form['op_%s' % name], form['var2_%s' % name]) selection.append(sel) # Projection. if form[k] == 'on': var = [k] i = 0 while '%s[%d]' % (k, i) in form: var.append('[%s]' % form[ '%s[%d]' % (k, i) ]) i += 1 var = ''.join(var) if var not in projection: projection.append(var) projection = ','.join(projection) selection = '&'.join(selection) query = projection + '&' + selection # Get current location. location = construct_url(environ, with_query_string=False) # Empty queries SHOULD NOT return everything, because this # means the user didn't select any variables. if not query.rstrip('?&'): app = HTTPBadRequest('You did not select any variables.') else: # Replace html extension for ascii and redirect. response = form['response'] redirect = '%s.%s?%s' % (location[:-5], response, query) app = HTTPSeeOther(redirect) return app(environ, start_response) else: self.serialize = self._render(environ) return BaseResponse.__call__(self, environ, start_response)
def __call__(self, environ, start_response): # Create a Beaker cache dependent on the query string, since # most (all?) pre-computed values will depend on the specific # dataset. We strip all WMS related arguments since they don't # affect the dataset. query = parse_dict_querystring(environ) try: dap_query = [ '%s=%s' % (k, query[k]) for k in query if k.lower() not in WMS_ARGUMENTS ] dap_query = [pair.rstrip('=') for pair in dap_query] dap_query.sort() # sort for uniqueness dap_query = '&'.join(dap_query) location = construct_url(environ, with_query_string=True, querystring=dap_query) self.cache = environ['beaker.cache'].get_cache( 'pydap.responses.wms+' + location) except KeyError: self.cache = None # Handle GetMap and GetCapabilities requests type_ = query.get('REQUEST', 'GetMap') if type_ == 'GetCapabilities': self.serialize = self._get_capabilities(environ) self.headers.append(('Content-type', 'text/xml')) self.headers.append(('Access-Control-Allow-Origin', '*')) elif type_ == 'GetMap': self.serialize = self._get_map(environ) self.headers.append(('Content-type', 'image/png')) elif type_ == 'GetColorbar': self.serialize = self._get_colorbar(environ) self.headers.append(('Content-type', 'image/png')) else: raise HTTPBadRequest('Invalid REQUEST "%s"' % type_) return BaseResponse.__call__(self, environ, start_response)
def __call__(self, environ, start_response): # Create a Beaker cache dependent on the query string, since # most (all?) pre-computed values will depend on the specific # dataset. We strip all WMS related arguments since they don't # affect the dataset. query = parse_dict_querystring(environ) try: dap_query = ['%s=%s' % (k, query[k]) for k in query if k.lower() not in WMS_ARGUMENTS] dap_query = [pair.rstrip('=') for pair in dap_query] dap_query.sort() # sort for uniqueness dap_query = '&'.join(dap_query) location = construct_url(environ, with_query_string=True, querystring=dap_query) self.cache = environ['beaker.cache'].get_cache( 'pydap.responses.wms+' + location) except KeyError: self.cache = None # Handle GetMap and GetCapabilities requests type_ = query.get('REQUEST', 'GetMap') if type_ == 'GetCapabilities': self.serialize = self._get_capabilities(environ) self.headers.append( ('Content-type', 'text/xml') ) self.headers.append( ('Access-Control-Allow-Origin', '*') ) elif type_ == 'GetMap': self.serialize = self._get_map(environ) self.headers.append( ('Content-type', 'image/png') ) elif type_ == 'GetColorbar': self.serialize = self._get_colorbar(environ) self.headers.append( ('Content-type', 'image/png') ) else: raise HTTPBadRequest('Invalid REQUEST "%s"' % type_) return BaseResponse.__call__(self, environ, start_response)