def parse(self, params, path_info, host, post_data, request_method): self.host = host try: self.get_layer(path_info, params) except NoLayerException as e: a = Action() if params.has_key('service') and params['service'].lower() == 'wfs': for layer in self.service.datasources: self.datasources.append(layer) if params.has_key('request'): a.request = params['request'] else: a.request = "GetCapabilities" else: a.method = "metadata" self.actions.append(a) return wfsrequest = WFSRequest() try: Request.parse(self, params, path_info, host, post_data, request_method, format_obj=wfsrequest) except: raise
def parse(self, params, path_info, host, post_data, request_method): self.host = host try: self.get_layer(path_info, params) except NoLayerException as e: a = Action() if params.has_key( 'service') and params['service'].lower() == 'wfs': for layer in self.service.datasources: self.datasources.append(layer) if params.has_key('request'): a.request = params['request'] else: a.request = "GetCapabilities" else: a.method = "metadata" self.actions.append(a) return wfsrequest = WFSRequest() try: Request.parse(self, params, path_info, host, post_data, request_method, format_obj=wfsrequest) except: raise
def handle_post(self, params, path_info, host, post_data, request_method, format_obj = None): """Read data from the request and turn it into an UPDATE/DELETE action.""" if format_obj: actions = [] id = self.get_id_from_path_info(path_info) if id is not False: action = Action() action.method = "update" action.id = id features = format_obj.decode(post_data) action.feature = features[0] actions.append(action) else: if hasattr(format_obj, 'decode'): features = format_obj.decode(post_data) for feature in features: action = Action() action.method = "insert" action.feature = feature actions.append(action) elif hasattr(format_obj, 'parse'): format_obj.parse(post_data) transactions = format_obj.getActions() if transactions is not None: for transaction in transactions: action = Action() action.method = transaction.__class__.__name__.lower() action.wfsrequest = transaction actions.append(action) return actions else: raise Exception("Service type does not support adding features.")
def parse(self, params, path_info, host, post_data, request_method, format_obj = None): """Used by most of the subclasses without changes. Does general processing of request information using request method and path/parameter information, to build up a list of actions. Returns a list of Actions. If the first action in the list is of method 'metadata', encode_metadata is called (no datasource is touched), and encode_metadata is called. Otherwise, the actions are passed onto DataSources to create lists of Features.""" self.host = host try: self.get_layer(path_info, params) except NoLayerException as e: a = Action() if params.has_key('service') and params['service'].lower() == 'wfs': # FIXME: not sure about this - need to add layer name, not object reference to datasource for layer in self.service.datasources: self.datasources.append(layer['name']) if params.has_key('request'): a.request = params['request'] else: a.request = "GetCapabilities" else: a.method = "metadata" self.actions.append(a) return for datasource in self.datasources: if not self.service.datasources.has_key(datasource): raise LayerNotFoundException("Request", datasource, self.service.datasources.keys()) action = Action() if request_method == "GET" or (request_method == "OPTIONS" and (post_data is None or len(post_data) <= 0)): action = self.get_select_action(path_info, params) elif request_method == "POST" or request_method == "PUT" or (request_method == "OPTIONS" and len(post_data) > 0): actions = self.handle_post(params, path_info, host, post_data, request_method, format_obj = format_obj) for action in actions: self.actions.append(action) return elif request_method == "DELETE": id = self.get_id_from_path_info(path_info) if id is not False: action.id = id action.method = "delete" self.actions.append(action)
def insertUnique(self, feature): if not feature.properties.has_key(self.unique): raise Exception("Unique key (%s) missing from feature." % self.unique) action = Action() action.attributes[self.unique] = feature.properties[self.unique] features = self.select(action) if len(features) > 1: raise Exception( "There are two features with the unique key %s. Something's wrong with that." % feature.properties[self.unique]) thunk = self.freeze_feature(feature) if len(features) == 0: return self.append(thunk) else: self.db[features[0].id] = thunk return features[0].id
def get_select_action(self, path_info, params): """Generate a select action from a URL. Used unmodified by most subclasses. Handles attribute query by following the rules passed in the DS or in the request, bbox, maxfeatures, and startfeature by looking for the parameters in the params. """ action = Action() action.method = "select" id = self.get_id_from_path_info(path_info) if id is not False: action.id = id else: import sys for ds in self.datasources: queryable = [] #ds = self.service.datasources[self.datasource] if hasattr(ds, 'queryable'): queryable = ds.queryable.split(",") elif params.has_key("queryable"): queryable = params['queryable'].split(",") for key, value in params.items(): qtype = None if "__" in key: key, qtype = key.split("__") if key == 'bbox': action.bbox = map(float, value.split(",")) elif key == "maxfeatures": action.maxfeatures = int(value) elif key == "startfeature": action.startfeature = int(value) elif key == "request": action.request = value elif key == "version": action.version = value elif key == "filter": action.wfsrequest = WFSRequest() try: action.wfsrequest.parse(value) except Exception, E: ''' ''' elif key in queryable or key.upper() in queryable and hasattr(self.service.datasources[ds], 'query_action_types'): if qtype: if qtype in self.service.datasources[ds].query_action_types: action.attributes[key+'__'+qtype] = {'column': key, 'type': qtype, 'value':value} else: raise ApplicationException("%s, %s, %s\nYou can't use %s on this layer. Available query action types are: \n%s" % (self, self.query_action_types, qtype, qtype, ",".join(self.service.datasources[ds].query_action_types) or "None")) else: action.attributes[key+'__eq'] = {'column': key, 'type': 'eq', 'value':value}