Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Version 3 #156

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9bc4fbb
Drop 'transform', and remove 'inplace' transformations.
tomchristie Jan 29, 2018
30e4cb1
Merge branch 'master' into remove-transform
tomchristie Jan 30, 2018
b9f9dd7
Drop action= and encoding= parameters on client, in favor of override
tomchristie Jan 30, 2018
4fb5e88
Drop HTTPTransport 'credentials' in favor of 'auth'
tomchristie Jan 30, 2018
b0eb95c
Drop HTTP request_callback and response_callback in favor of custom s…
tomchristie Jan 30, 2018
ad00b0a
Drop unused import
tomchristie Jan 30, 2018
15dcdc9
Removing data from documents. Drop 'Array'.
tomchristie Jan 30, 2018
f3c8dde
Drop CallbackAdapater. We don't use it anywhere. Could later farm it …
tomchristie Jan 31, 2018
7d06d93
Drop DomainCredentials, now that we have proper auth classes
tomchristie Jan 31, 2018
ced53cf
Refactor to use session.request
tomchristie Jan 31, 2018
93946cd
Drop unneccessary default parameters
tomchristie Jan 31, 2018
e99f71b
Move _guess_extension out of utils and into codes/download
tomchristie Jan 31, 2018
61d4198
Drop 'Document.clone'
tomchristie Feb 13, 2018
bc6aa9e
Add typesys. Add OpenAPI, JSONSchema.
tomchristie Feb 14, 2018
df86966
.errors always a classmethod
tomchristie Feb 14, 2018
f106bd0
Create absolute URLs for Links from OpenAPI
tomchristie Feb 14, 2018
6b3296a
Drop coreschema
tomchristie Feb 14, 2018
8644689
Ordered schema representations. Support OpenAPI encoding.
tomchristie Feb 14, 2018
325d032
Include yaml in requirements
tomchristie Feb 14, 2018
5984a33
Drop coreschema
tomchristie Feb 14, 2018
9444bc0
Preserve ordering of OpenAPI 'paths' across python versions
tomchristie Feb 14, 2018
b3fa5c2
Default to JSON-flavoured OpenAPI
tomchristie Feb 15, 2018
235f50e
Schemas in tests should be bytestrings
tomchristie Feb 15, 2018
dc4edea
Ensure OpenAPI.encode returns bytestrings
tomchristie Feb 15, 2018
c85818c
dict is ordered in Python 3.6
tomchristie Feb 15, 2018
566abbe
Force ordering of document using in test case
tomchristie Feb 15, 2018
6530dc2
Enforced ordering in Object
tomchristie Feb 20, 2018
09518cd
Drop commented-out YAML code
tomchristie Feb 20, 2018
73c5015
Drop itypes from transports/codecs/client
tomchristie Feb 20, 2018
2d6e0bc
Drop BaseCodec dump/load/supports
tomchristie Feb 20, 2018
48784f4
Add document.version
tomchristie Feb 20, 2018
5e19106
Drop itypes from Error
tomchristie Feb 20, 2018
d1c006f
Drop itypes from Link
tomchristie Feb 20, 2018
b52553e
Drop itypes
tomchristie Feb 20, 2018
b1e3418
Drop client.reload
tomchristie Feb 20, 2018
7b0cf7d
_to_immutable -> _to_objects
tomchristie Feb 20, 2018
e663b9f
Drop reload from tests
tomchristie Feb 20, 2018
f09ca74
'enum' defined on types
tomchristie Feb 20, 2018
93482e9
Add openapi codec to setup
tomchristie Feb 20, 2018
54199e3
Add Field.title
tomchristie Feb 20, 2018
8c1748e
Use Link.method. Put .action towards deprecation.
tomchristie Feb 20, 2018
ae79ef5
Plain old classes for typesys
tomchristie Feb 21, 2018
01a0a51
Add typesys.Ref
tomchristie Feb 21, 2018
46a9559
assert types on __init__
tomchristie Feb 21, 2018
f772992
Tests and refinements to typesys
tomchristie Feb 21, 2018
a50e0e3
exact_items validation for Array
tomchristie Feb 21, 2018
b56b1d6
Add allow_null to typesys
tomchristie Feb 21, 2018
c58ad81
Work on JSON Schema and typesys
tomchristie Mar 1, 2018
15f24dc
Work on Union and JSONSchema
tomchristie Mar 1, 2018
cb8e273
Cleanups on typesys
tomchristie Mar 1, 2018
f19c680
Uniqueness checking always that always uses set()
tomchristie Mar 5, 2018
a87f66a
Add Section, Add Link.id
tomchristie Mar 5, 2018
382eef8
Slugify tag names to get section ids
tomchristie Mar 5, 2018
4a5993a
Add path_links and query_links to Section
tomchristie Mar 6, 2018
5e3de6c
Add path_fields and query_fields to Link
tomchristie Mar 6, 2018
1d7a121
Tweak
tomchristie Mar 6, 2018
58ec296
Fix 'security' in OpenAPI
tomchristie Mar 6, 2018
947e03b
If no operationId then use summary for Link.id
tomchristie Mar 6, 2018
7486932
Building out OpenAPI v3 spec
tomchristie Mar 6, 2018
69a5a69
First pass at parsing OpenAPI requestBody schemas
tomchristie Mar 6, 2018
3a793b9
Add initial requestBody schema support
tomchristie Mar 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removing data from documents. Drop 'Array'.
  • Loading branch information
tomchristie committed Jan 30, 2018
commit 15dcdc9cbde6015963977814da205c22c89d55a9
4 changes: 2 additions & 2 deletions coreapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding: utf-8
from coreapi import auth, codecs, exceptions, transports, utils
from coreapi.client import Client
from coreapi.document import Array, Document, Link, Object, Error, Field
from coreapi.document import Document, Link, Object, Error, Field


__version__ = '2.3.3'
__all__ = [
'Array', 'Document', 'Link', 'Object', 'Error', 'Field',
'Document', 'Link', 'Object', 'Error', 'Field',
'Client',
'auth', 'codecs', 'exceptions', 'transports', 'utils',
]
10 changes: 1 addition & 9 deletions coreapi/codecs/corejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from coreapi.codecs.base import BaseCodec
from coreapi.compat import force_bytes, string_types, urlparse
from coreapi.compat import COMPACT_SEPARATORS, VERBOSE_SEPARATORS
from coreapi.document import Document, Link, Array, Object, Error, Field
from coreapi.document import Document, Link, Object, Error, Field
from coreapi.exceptions import ParseError
import coreschema
import json
Expand Down Expand Up @@ -222,9 +222,6 @@ def _document_to_primitive(node, base_url=None):
for key, value in node.items()
])

elif isinstance(node, Array):
return [_document_to_primitive(value) for value in node]

return node


Expand Down Expand Up @@ -284,11 +281,6 @@ def _primitive_to_document(data, base_url=None):
content = _get_content(data, base_url=base_url)
return Object(content)

elif isinstance(data, list):
# Array
content = [_primitive_to_document(item, base_url) for item in data]
return Array(content)

# String, Integer, Number, Boolean, null.
return data

Expand Down
13 changes: 1 addition & 12 deletions coreapi/codecs/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import unicode_literals
from coreapi.codecs.base import BaseCodec
from coreapi.compat import console_style, string_types
from coreapi.document import Document, Link, Array, Object, Error
from coreapi.document import Document, Link, Object, Error
import json


Expand Down Expand Up @@ -76,17 +76,6 @@ def _to_plaintext(node, indent=0, base_url=None, colorize=False, extra_offset=No

return head if (not body) else head + '\n' + body

elif isinstance(node, Array):
head_indent = ' ' * indent
body_indent = ' ' * (indent + 1)

body = ',\n'.join([
body_indent + _to_plaintext(value, indent + 1, base_url=base_url, colorize=colorize)
for value in node
])

return '[]' if (not body) else '[\n' + body + '\n' + head_indent + ']'

elif isinstance(node, Link):
return (
colorize_keys('link(') +
Expand Down
12 changes: 2 additions & 10 deletions coreapi/codecs/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# It may move into a utility function in the future.
from __future__ import unicode_literals
from coreapi.codecs.base import BaseCodec
from coreapi.document import Document, Link, Array, Object, Error, Field
from coreapi.document import Document, Link, Object, Error, Field


def _to_repr(node):
Expand Down Expand Up @@ -31,11 +31,6 @@ def _to_repr(node):
for key, value in node.items()
])

elif isinstance(node, Array):
return '[%s]' % ', '.join([
_to_repr(value) for value in node
])

elif isinstance(node, Link):
args = "url=%s" % repr(node.url)
if node.action:
Expand Down Expand Up @@ -71,10 +66,7 @@ class PythonCodec(BaseCodec):
media_type = 'text/python'

def encode(self, document, **options):
# Object and Array only have the class name wrapper if they
# are the outermost element.
# Object only has the class name wrapper if it is the outermost element.
if isinstance(document, Object):
return 'Object(%s)' % _to_repr(document)
elif isinstance(document, Array):
return 'Array(%s)' % _to_repr(document)
return _to_repr(document)
20 changes: 3 additions & 17 deletions coreapi/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
def _to_immutable(value):
if isinstance(value, dict):
return Object(value)
elif isinstance(value, list):
return Array(value)
return value


Expand Down Expand Up @@ -169,20 +167,6 @@ def links(self):
])


class Array(itypes.List):
"""
An immutable list type container.
"""
def __init__(self, *args):
self._data = [_to_immutable(value) for value in list(*args)]

def __repr__(self):
return _repr(self)

def __str__(self):
return _str(self)


class Link(itypes.Object):
"""
Links represent the actions that a client may perform.
Expand Down Expand Up @@ -295,8 +279,10 @@ def title(self):
def get_messages(self):
messages = []
for value in self.values():
if isinstance(value, Array):
if isinstance(value, list):
messages += [
item for item in value if isinstance(item, string_types)
]
elif isinstance(value, string_types):
messages += [value]
return messages
9 changes: 1 addition & 8 deletions coreapi/transports/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict
from coreapi import exceptions, utils
from coreapi.compat import cookiejar, urlparse
from coreapi.document import Document, Object, Link, Array, Error
from coreapi.document import Document, Object, Error
from coreapi.transports.base import BaseTransport
from coreapi.utils import guess_filename, is_file, File
import collections
Expand Down Expand Up @@ -242,13 +242,6 @@ def _coerce_to_error_content(node):
(key, _coerce_to_error_content(value))
for key, value in node.data.items()
])
elif isinstance(node, Array):
# Strip Links from Arrays.
return [
_coerce_to_error_content(item)
for item in node
if not isinstance(item, Link)
]
return node


Expand Down
109 changes: 3 additions & 106 deletions tests/test_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
from coreapi import Client
from coreapi import Array, Document, Object, Link, Error, Field
from coreapi import Document, Object, Link, Error, Field
from coreapi.exceptions import LinkLookupError
import pytest

Expand All @@ -13,7 +13,6 @@ def doc():
content={
'integer': 123,
'dict': {'key': 'value'},
'list': [1, 2, 3],
'link': Link(
url='/',
action='post',
Expand All @@ -28,11 +27,6 @@ def obj():
return Object({'key': 'value', 'nested': {'abc': 123}})


@pytest.fixture
def array():
return Array([{'a': 1}, {'b': 2}, {'c': 3}])


@pytest.fixture
def link():
return Link(
Expand Down Expand Up @@ -95,23 +89,6 @@ def test_object_does_not_support_key_deletion(obj):
del obj['key']


# Arrays are immutable.

def test_array_does_not_support_item_assignment(array):
with pytest.raises(TypeError):
array[1] = 456


def test_array_does_not_support_property_assignment(array):
with pytest.raises(TypeError):
array.integer = 456


def test_array_does_not_support_item_deletion(array):
with pytest.raises(TypeError):
del array[1]


# Links are immutable.

def test_link_does_not_support_property_assignment():
Expand All @@ -134,10 +111,6 @@ def test_document_dictionaries_coerced_to_objects(doc):
assert isinstance(doc['dict'], Object)


def test_document_lists_coerced_to_arrays(doc):
assert isinstance(doc['list'], Array)


# The `delete` and `set` methods return new instances.

def test_document_delete(doc):
Expand Down Expand Up @@ -172,56 +145,13 @@ def test_object_set(obj):
assert obj[key] is new[key]


def test_array_delete(array):
new = array.delete(1)
assert array is not new
assert len(new) == len(array) - 1
assert new[0] is array[0]
assert new[1] is array[2]


def test_array_set(array):
new = array.set(1, 456)
assert array is not new
assert len(new) == len(array)
assert new[0] is array[0]
assert new[1] == 456
assert new[2] is array[2]


# The `delete_in` and `set_in` functions return new instances.

def test_delete_in():
nested = Object({'key': [{'abc': 123}, {'def': 456}], 'other': 0})

assert nested.delete_in(['key', 0]) == {'key': [{'def': 456}], 'other': 0}
assert nested.delete_in(['key']) == {'other': 0}
assert nested.delete_in([]) is None


def test_set_in():
nested = Object({'key': [{'abc': 123}, {'def': 456}], 'other': 0})
insert = Object({'xyz': 789})

assert (
nested.set_in(['key', 0], insert) ==
{'key': [{'xyz': 789}, {'def': 456}], 'other': 0}
)
assert (
nested.set_in(['key'], insert) ==
{'key': {'xyz': 789}, 'other': 0}
)
assert nested.set_in([], insert) == {'xyz': 789}


# Container types have a uniquely identifying representation.

def test_document_repr(doc):
assert repr(doc) == (
"Document(url='http://example.org', title='Example', content={"
"'dict': {'key': 'value'}, "
"'integer': 123, "
"'list': [1, 2, 3], "
"'nested': {'child': Link(url='/123')}, "
"'link': Link(url='/', action='post', "
"fields=['optional', Field('required', required=True, location='path')])"
Expand All @@ -235,11 +165,6 @@ def test_object_repr(obj):
assert eval(repr(obj)) == obj


def test_array_repr(array):
assert repr(array) == "Array([{'a': 1}, {'b': 2}, {'c': 3}])"
assert eval(repr(array)) == array


def test_link_repr(link):
assert repr(link) == "Link(url='/', action='post', fields=[Field('required', required=True), 'optional'])"
assert eval(repr(link)) == link
Expand All @@ -259,11 +184,6 @@ def test_document_str(doc):
key: "value"
}
integer: 123
list: [
1,
2,
3
]
nested: {
child()
}
Expand Down Expand Up @@ -291,32 +211,14 @@ def test_object_str(obj):
""")


def test_array_str(array):
assert str(array) == _dedent("""
[
{
a: 1
},
{
b: 2
},
{
c: 3
}
]
""")


def test_link_str(link):
assert str(link) == "link(required, [optional])"


def test_error_str(error):
assert str(error) == _dedent("""
<Error>
messages: [
"failed"
]
messages: ["failed"]
""")


Expand All @@ -340,7 +242,6 @@ def test_document_equality(doc):
assert doc == {
'integer': 123,
'dict': {'key': 'value'},
'list': [1, 2, 3],
'link': Link(
url='/',
action='post',
Expand All @@ -354,14 +255,10 @@ def test_object_equality(obj):
assert obj == {'key': 'value', 'nested': {'abc': 123}}


def test_array_equality(array):
assert array == [{'a': 1}, {'b': 2}, {'c': 3}]


# Container types support len.

def test_document_len(doc):
assert len(doc) == 5
assert len(doc) == 4


def test_object_len(obj):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy