Permalink
Browse files

Rename uri to url (uri remains deprecated)

  • Loading branch information...
Jhuni0123 committed May 21, 2018
1 parent 12b57e3 commit e0109d691f465fadb6a8642991a4173987bf6e56
@@ -135,6 +135,8 @@ To be released.
);
~~~~~~~~
- Deprecated `uri` and `url` type is added. [[#126], [#277]]
### Docs target
- A new required configuration `targets.docs.title` was added.
@@ -253,6 +255,7 @@ To be released.
[#13]: https://github.com/spoqa/nirum/issues/13
[#100]: https://github.com/spoqa/nirum/issues/100
[#126]: https://github.com/spoqa/nirum/issues/126
[#178]: https://github.com/spoqa/nirum/issues/178
[#217]: https://github.com/spoqa/nirum/issues/217
[#220]: https://github.com/spoqa/nirum/issues/220
@@ -266,6 +269,7 @@ To be released.
[#267]: https://github.com/spoqa/nirum/pull/267
[#269]: https://github.com/spoqa/nirum/pull/269
[#272]: https://github.com/spoqa/nirum/pull/272
[#277]: https://github.com/spoqa/nirum/pull/277
[entry points]: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
[python2-numbers-integral]: https://docs.python.org/2/library/numbers.html#numbers.Integral
[python2-int]: https://docs.python.org/2/library/functions.html#int
@@ -184,7 +184,7 @@ a structure consists of fields which have their name and type. For example:
name name,
date? dob,
gender? gender,
uri? website-uri
url? website-url
);
It's represented in JSON to:
@@ -198,7 +198,7 @@ It's represented in JSON to:
},
"dob": null,
"gender": "male",
"uri": null
"url": null
}
When a payload is deserialized, undefined fields are just ignored.
@@ -229,7 +229,7 @@ a union type instead of a record type:
name name,
date? dob,
gender? gender,
uri? website-uri
url? website-url
);
It's represented in JSON to:
@@ -244,7 +244,7 @@ It's represented in JSON to:
},
"dob": null,
"gender": "male",
"uri": null
"url": null
}
In a similar way to a recrod type, undefined fields in a payload are ignored
@@ -53,8 +53,8 @@ record et-cetera (
uuid b,
# `uuid` stores a UUID. Represented as a string in JSON.
uri c,
# `uri` stores a URI. Represented as a string in JSON.
url c,
# `url` stores a URL. Represented as a string in JSON.
);
record containers (
@@ -5,12 +5,12 @@ union markdown-parse-error = symbol-error | syntax-error (text reason);
type html = text;
service pdf-service (
# A microservice which renders a PDF from the given URI or HTML.
# A microservice which renders a PDF from the given URL or HTML.
@http-resource(method="GET", path="/pdf/{uri}")
binary render-uri (
# Renders a PDF from the given URI.
uri uri,
@http-resource(method="GET", path="/pdf/{url}")
binary render-url (
# Renders a PDF from the given URL.
url url,
),
@http-resource(method="POST", path="/pdf/")
@@ -30,7 +30,7 @@ import Nirum.Constructs.TypeDeclaration ( JsonType (Boolean, Number, String)
, Int32
, Int64
, Text
, Uri
, Url
, Uuid
)
, Type (PrimitiveType)
@@ -112,7 +112,9 @@ coreTypes =
-- et cetera
, decl' "bool" Bool Boolean
, decl' "uuid" Uuid String
, decl' "uri" Uri String
, decl' "url" Url String
-- FIXME: deprecated
, decl' "uri" Url String
]
where
decl' name prim json =
@@ -19,7 +19,7 @@ module Nirum.Constructs.TypeDeclaration ( EnumMember (EnumMember)
, Int32
, Int64
, Text
, Uri
, Url
, Uuid
)
, Tag ( Tag
@@ -174,7 +174,7 @@ instance Declaration Tag where
-- | Primitive type identifiers.
data PrimitiveTypeIdentifier
= Bigint | Decimal | Int32 | Int64 | Float32 | Float64 | Text | Binary
| Date | Datetime | Bool | Uuid | Uri
| Date | Datetime | Bool | Uuid | Url
deriving (Eq, Ord, Show)
-- | Possible coded types of 'PrimitiveType' in JSON representation.
@@ -578,7 +578,7 @@ except #{builtins}.ValueError:
)
|]
compilePrimitiveTypeDeserializer Uri vInput vOutput vError =
compilePrimitiveTypeDeserializer Url vInput vOutput vError =
compilePrimitiveTypeDeserializer Text vInput vOutput vError
-- | Wrap a Python deserializer code block into an isolated scope.
@@ -80,4 +80,4 @@ compilePrimitiveTypeSerializer Datetime var = replace "$var" var [q|(
)|]
compilePrimitiveTypeSerializer Bool var = var
compilePrimitiveTypeSerializer Uuid var = [qq|str($var).lower()|]
compilePrimitiveTypeSerializer Uri var = var
compilePrimitiveTypeSerializer Url var = var
@@ -82,8 +82,8 @@ compilePrimitiveType primitiveTypeIdentifier' = do
(Uuid, _) -> do
uuid <- importStandardLibrary "uuid"
return [qq|$uuid.UUID|]
(Uri, Python2) -> builtins "basestring"
(Uri, Python3) -> builtins "str"
(Url, Python2) -> builtins "basestring"
(Url, Python3) -> builtins "str"
where
builtins :: Code -> CodeGen Code
builtins typename' = do
@@ -99,9 +99,9 @@ compilePrimitiveTypeValidator primitiveTypeId pythonVar = do
[ ValueValidator [qq|(($var).tzinfo is not None)|]
"naive datetime (lacking tzinfo)"
]
vv Uri var =
vv Url var =
[ ValueValidator [qq|('\\n' not in ($var))|]
"URI cannot contain new line characters"
"URL cannot contain new line characters"
]
vv _ _ = []
@@ -57,7 +57,7 @@ spec = pythonVersionSpecs $ \ ver -> do
let (uuidCode, uuidContext) = run' (compilePrimitiveType Uuid)
uuidCode `shouldBe` Right "_uuid.UUID"
standardImports uuidContext `shouldBe` [("_uuid", "uuid")]
code (compilePrimitiveType Uri) `shouldBe`
code (compilePrimitiveType Url) `shouldBe`
case ver of
Python2 -> "__builtin__.basestring"
Python3 -> "__builtin__.str"
@@ -115,7 +115,7 @@ record product (
text name,
int64? price,
bool sale,
uri? url,
url? url,
);
union animal = cat
@@ -142,3 +142,5 @@ record name-shadowing-field-record (
union optional-union = foo ( int32? bar )
| baz ( int32 qux )
;
unboxed website (uri);
@@ -41,7 +41,7 @@ unboxed record-unboxed (product);
union post
= image (text mime-type, binary data)
| link (uri link, text title, text? quote)
| link (url link, text title, text? quote)
| article (text title, text content)
;
@@ -15,7 +15,7 @@
Point1, Point2, Point3d, Pop, PingService, Product,
RecordWithMap, RecordWithOptionalRecordField,
Rnb, RpcError, Run, Song, Status, Stop, Way,
WesternName)
Website, WesternName)
from fixture.foo.bar import PathUnbox, IntUnbox, Point
from fixture.qux import Path, Name
from fixture.reserved_keyword_enum import ReservedKeywordEnum
@@ -538,3 +538,15 @@ def test_name_shadowing_field():
assert "bytes must be a value of {0}, not ['invalid']".format(
'bytes' if PY3 else 'str'
) == str(ei.value)
def test_uri():
""" Deprecated
"""
assert isinstance(Website, type)
website = Website(u'https://nirum.org')
assert website.value == u'https://nirum.org'
assert website.__nirum_serialize__() == u'https://nirum.org'
assert Website.__nirum_deserialize__(u'https://nirum.org') == website
with raises(ValueError):
Website(u'https://nirum.org\n')

0 comments on commit e0109d6

Please sign in to comment.