コード例 #1
0
 def validate(self, value):
     super().validate(value)
     if value[0] < -180.0 or value[0] > 180.0:
         raise s.SchemaError(
             "invalid longitude; must be -180.0 ≤ longitude ≤ 180.0")
     if value[1] < -90.0 or value[1] > 90.0:
         raise s.SchemaError(
             "invalid latitude; must be -90.0 ≤ latitude ≤ 90.0")
コード例 #2
0
 def bin_decode(self, value):
     try:
         return self.json_decode(self.schema.strip(wkb.loads(value)))
     except Exception as e:
         raise s.SchemaError(
             f"invalid WKB representation of {self.__class__.__name__}"
         ) from e
コード例 #3
0
 def _process_resource(self, resource_name, args, inp, out):
     """Process a command for a resource."""
     resource = self.resources[resource_name]
     operation_name = _a2p(args.pop(0)) if args else None
     operation = resource.operations.get(operation_name)
     if not operation:
         return self._help_resource(resource_name)
     params = operation.params or {}
     returns = operation.returns
     body = params.get("_body")
     with _open_redirects(inp, out, args, body, returns) as (inp, out):
         try:
             parsed = self._parse_arguments(params, args)
         except ValueError:
             return self._help_operation(resource_name, operation)
         try:
             for name in parsed:
                 parsed[name] = params[name].str_decode(parsed[name])
             for name in (n for n in params if n != "_body"):
                 if params[name].required and name not in parsed:
                     raise s.SchemaError("missing required parameter")
             if body:
                 name = "{body}"
                 description = (body.description
                                or "{}.".format(name)).lower()
                 if inp == sys.stdin:
                     self._print("Enter {}".format(description))
                     self._print(
                         "When complete, input EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return):"
                     )
                 else:
                     self._print("Reading body from {}...".format(
                         getattr(inp, "name", "stream")))
                 if isinstance(body, s.reader):
                     parsed["_body"] = inp
                 else:
                     parsed["_body"] = _read(inp, body)
             name = None
             result = operation.call(**parsed)
         except s.SchemaError as se:
             if name:
                 se.push(_p2a(name))
             self._help_operation(resource_name, operation)
             raise
         self._print("SUCCESS.")
         if returns:
             description = (returns.description or "response.").lower()
             if out is not sys.stdout:
                 self._print("Writing response to {}...".format(
                     getattr(out, "name", "stream")))
             if isinstance(returns, s.reader):
                 copyfileobj(result, out)
                 result.close()
             else:
                 _write(out, returns, result)
             if out is sys.stdout:
                 self._print()
     return True
コード例 #4
0
 def validate(self, value):
     super().validate(value)
     if value[0] != value[-1]:
         raise s.SchemaError(
             "last point in linear ring must be the same as the first point"
         )
コード例 #5
0
ファイル: sqlite.py プロジェクト: arminbhy/roax
 def sql_decode(self, schema, value):
     try:
         return self.type(value)
     except ValueError as ve:
         raise s.SchemaError(str(ve)) from ve
コード例 #6
0
 def validate(self, value):
     if not e164.pattern.match(value):
         raise s.SchemaError("Invalid E.164 number format")
     super().validate(value)
コード例 #7
0
 def validate(self, value):
     if not value.isidentifier():
         raise s.SchemaError("Invalid nick format")
     super().validate(value)
コード例 #8
0
def test_SchemaError_str():
    assert str(s.SchemaError("text", "/a/b")) == "/a/b: text"