コード例 #1
0
ファイル: __init__.py プロジェクト: chinnurtb/wallaroo
 def getGroup(self, **query):
     name = (query.has_key("name") and query["name"]) or (query.has_key("NAME") and query["NAME"]) or None
     if name is None:
         fail(errors.make(errors.BAD_ARGUMENT), "invalid query type %r" % query)
     result = self.cm.make_proxy_object(group, name)
     result.refresh()
     
     return result
コード例 #2
0
ファイル: arc_utils.py プロジェクト: chinnurtb/wallaroo
    def modify_arcs(self, command, dests, options):
        keyfun = self.name
        command = command.upper()
        what = default_get(kwargs, "what", self.__class__.__name__.lower())
        errwhat = default_getattr(errors, what.upper(), errors.UNKNOWN)

        if command == "ADD":
            old_dests = preserve_order and getfun(self) or set(getfun(self))
            new_dests = preserve_order and dests or set(dests)
            if keyfun in new_dests and not heterogeneous:
                fail(
                    errors.make(errors.CIRCULAR_RELATIONSHIP,
                                errors.INVALID_RELATIONSHIP, errwhat),
                    "%s %s cannot %s itself" % (what, name, explain))

            setfun(self, uniq(itertools.chain(old_dests, new_dests)))
            self.update()
        elif command == "REPLACE":
            new_dests = preserve_order and dests or set(dests)
            if keyfun in new_dests and not heterogeneous:
                fail(
                    errors.make(errors.CIRCULAR_RELATIONSHIP,
                                errors.INVALID_RELATIONSHIP, errwhat),
                    "%s %s cannot %s itself" % (what, name, explain))

            setfun(self, new_dests)
            self.update()
        elif command == "REMOVE":
            setfun(
                self,
                [dest for new_dests in getfun(self) if not dest in set(dests)])
            self.update()
        elif command in ["INTERSECT", "DIFF", "UNION"]:
            if preserve_order:
                fail(
                    errors.make(errors.INTERNAL_ERROR, errors.NOT_IMPLEMENTED,
                                errwhat),
                    "%s not implemented for order-preserving relations" %
                    command)

            op = globals()["%s_collections" % command.lower()]
            old_dests = getfun(self)
            supplied_dests = set(dests)
            new_dests = op(old_dests, supplied_dests)

            if keyfun() in new_dests and not heterogeneous:
                fail(
                    errors.make(errors.CIRCULAR_RELATIONSHIP,
                                errors.INVALID_RELATIONSHIP, errwhat),
                    "%s %s cannot %s itself" % (what, name, explain))

            setfun(self, new_dests)
            self.update()
        else:
            fail(errors.make(errors.BAD_COMMAND, errwhat),
                 "Invalid command %s" % command)
コード例 #3
0
    def getGroup(self, **query):
        name = (query.has_key("name")
                and query["name"]) or (query.has_key("NAME")
                                       and query["NAME"]) or None
        if name is None:
            fail(errors.make(errors.BAD_ARGUMENT),
                 "invalid query type %r" % query)
        result = self.cm.make_proxy_object(group, name)
        result.refresh()

        return result
コード例 #4
0
ファイル: group.py プロジェクト: chinnurtb/wallaroo
 def modifyParams(self, command, params, **options):
     command = command.upper()
     if command == "ADD":
         for k, v in params.iteritems():
             self.parameters[k] = v
     elif command == "REMOVE":
         for k in [k for k in params if k in self.parameters]:
             del self.parameters[k]
     elif command == "REPLACE":
         self.parameters = params
     else:
         fail(errors.make(errors.BAD_COMMAND, errors.GROUP), "Invalid command %s" % command)
     self.update()
コード例 #5
0
ファイル: feature.py プロジェクト: chinnurtb/wallaroo
 def modifyParams(command, params, **options):
     command = command.upper()
     if command == "ADD":
         for k, v in params.iteritems():
             self.parameters[k] = v
     elif command == "REMOVE":
         for k in [k for k in params if k in self.parameters]:
             del self.parameters[k]
     elif command == "REPLACE":
         self.parameters = params
     else:
         fail(errors.make(errors.BAD_COMMAND, errors.FEATURE),
              "Invalid command %s" % command)
     self.update()
コード例 #6
0
def add_number_of_schools():
    try:
        request_content = PostRequestInput(request.data)
        house = House(request_content.get_house_location())
        request_content.add_to_house_details(
            key="Schools", value=house.get_amenity_frequency("school"))
    except json.decoder.JSONDecodeError:
        return fail(400, "Could convert body to JSON")
    except TypeError:
        return fail(400, "Something is wrong with the input's data stractures")
    except KeyError:
        return fail(404, "Input should have lat and lon")
    except OverpassServiceError:
        return fail(503, "Please try again later")
    return jsonify(request_content.build_response())
コード例 #7
0
ファイル: arc_utils.py プロジェクト: chinnurtb/wallaroo
 def modify_arcs(self, command, dests, options):
     keyfun = self.name
     command = command.upper()
     what = default_get(kwargs, "what", self.__class__.__name__.lower())
     errwhat = default_getattr(errors, what.upper(), errors.UNKNOWN)
     
     if command == "ADD":
         old_dests = preserve_order and getfun(self) or set(getfun(self))
         new_dests = preserve_order and dests or set(dests)
         if keyfun in new_dests and not heterogeneous:
             fail(errors.make(errors.CIRCULAR_RELATIONSHIP, errors.INVALID_RELATIONSHIP, errwhat), "%s %s cannot %s itself" % (what, name, explain))
         
         setfun(self, uniq(itertools.chain(old_dests, new_dests)))
         self.update()
     elif command == "REPLACE":
         new_dests = preserve_order and dests or set(dests)
         if keyfun in new_dests and not heterogeneous:
             fail(errors.make(errors.CIRCULAR_RELATIONSHIP, errors.INVALID_RELATIONSHIP, errwhat), "%s %s cannot %s itself" % (what, name, explain))
         
         setfun(self, new_dests)
         self.update()
     elif command == "REMOVE":
         setfun(self, [dest for new_dests in getfun(self) if not dest in set(dests)])
         self.update()
     elif command in ["INTERSECT", "DIFF", "UNION"]:
         if preserve_order:
             fail(errors.make(errors.INTERNAL_ERROR, errors.NOT_IMPLEMENTED, errwhat), "%s not implemented for order-preserving relations" % command)
         
         op = globals()["%s_collections" % command.lower()]
         old_dests = getfun(self)
         supplied_dests = set(dests)
         new_dests = op(old_dests, supplied_dests)
         
         if keyfun() in new_dests and not heterogeneous:
             fail(errors.make(errors.CIRCULAR_RELATIONSHIP, errors.INVALID_RELATIONSHIP, errwhat), "%s %s cannot %s itself" % (what, name, explain))
         
         setfun(self, new_dests)
         self.update()
     else:
         fail(errors.make(errors.BAD_COMMAND, errwhat), "Invalid command %s" % command)