diff --git a/coreapi/codecs/corejson.py b/coreapi/codecs/corejson.py index 5261618..091e7a3 100644 --- a/coreapi/codecs/corejson.py +++ b/coreapi/codecs/corejson.py @@ -128,15 +128,15 @@ def _get_content(item, base_url=None): Return a dictionary of content, for documents, objects and errors. """ return { - _unescape_key(key): _primative_to_document(value, base_url) + _unescape_key(key): _primitive_to_document(value, base_url) for key, value in item.items() if key not in ('_type', '_meta') } -def _document_to_primative(node, base_url=None): +def _document_to_primitive(node, base_url=None): """ - Take a Core API document and return Python primatives + Take a Core API document and return Python primitives ready to be rendered into the JSON style encoding. """ if isinstance(node, Document): @@ -156,7 +156,7 @@ def _document_to_primative(node, base_url=None): # Fill in key-value content. ret.update([ - (_escape_key(key), _document_to_primative(value, base_url=url)) + (_escape_key(key), _document_to_primitive(value, base_url=url)) for key, value in node.items() ]) return ret @@ -170,7 +170,7 @@ def _document_to_primative(node, base_url=None): # Fill in key-value content. ret.update([ - (_escape_key(key), _document_to_primative(value, base_url=base_url)) + (_escape_key(key), _document_to_primitive(value, base_url=base_url)) for key, value in node.items() ]) return ret @@ -193,7 +193,7 @@ def _document_to_primative(node, base_url=None): ret['description'] = node.description if node.fields: ret['fields'] = [ - _document_to_primative(field) for field in node.fields + _document_to_primitive(field) for field in node.fields ] return ret @@ -209,19 +209,19 @@ def _document_to_primative(node, base_url=None): elif isinstance(node, Object): return OrderedDict([ - (_escape_key(key), _document_to_primative(value, base_url=base_url)) + (_escape_key(key), _document_to_primitive(value, base_url=base_url)) for key, value in node.items() ]) elif isinstance(node, Array): - return [_document_to_primative(value) for value in node] + return [_document_to_primitive(value) for value in node] return node -def _primative_to_document(data, base_url=None): +def _primitive_to_document(data, base_url=None): """ - Take Python primatives as returned from parsing JSON content, + Take Python primitives as returned from parsing JSON content, and return a Core API document. """ if isinstance(data, dict) and data.get('_type') == 'document': @@ -278,7 +278,7 @@ def _primative_to_document(data, base_url=None): elif isinstance(data, list): # Array - content = [_primative_to_document(item, base_url) for item in data] + content = [_primitive_to_document(item, base_url) for item in data] return Array(content) # String, Integer, Number, Boolean, null. @@ -303,7 +303,7 @@ def decode(self, bytestring, **options): except ValueError as exc: raise ParseError('Malformed JSON. %s' % exc) - doc = _primative_to_document(data, base_url) + doc = _primitive_to_document(data, base_url) if isinstance(doc, Object): doc = Document(content=dict(doc)) @@ -331,5 +331,5 @@ def encode(self, document, **options): 'separators': COMPACT_SEPARATORS } - data = _document_to_primative(document) + data = _document_to_primitive(document) return force_bytes(json.dumps(data, **kwargs)) diff --git a/coreapi/document.py b/coreapi/document.py index da9044a..0fb62a7 100644 --- a/coreapi/document.py +++ b/coreapi/document.py @@ -50,7 +50,7 @@ def _key_sorting(item): Field.__new__.__defaults__ = (False, '', None, None, None, None) -# The Core API primatives: +# The Core API primitives: class Document(itypes.Dict): """ diff --git a/coreapi/utils.py b/coreapi/utils.py index 4283583..0b27d46 100644 --- a/coreapi/utils.py +++ b/coreapi/utils.py @@ -314,7 +314,7 @@ def _validate_form_field(value, allow_files=False, allow_list=True): elif allow_files and is_file(value): return value - msg = 'Must be a primative type.' + msg = 'Must be a primitive type.' raise exceptions.ParameterError(msg) @@ -332,5 +332,5 @@ def _validate_json_data(value): for item_key, item_val in value.items() } - msg = 'Must be a JSON primative.' + msg = 'Must be a JSON primitive.' raise exceptions.ParameterError(msg) diff --git a/tests/test_codecs.py b/tests/test_codecs.py index eb77a68..8ebbd63 100644 --- a/tests/test_codecs.py +++ b/tests/test_codecs.py @@ -1,6 +1,6 @@ # coding: utf-8 from coreapi.codecs import CoreJSONCodec -from coreapi.codecs.corejson import _document_to_primative, _primative_to_document +from coreapi.codecs.corejson import _document_to_primitive, _primitive_to_document from coreapi.document import Document, Link, Error, Field from coreapi.exceptions import ParseError, NoCodecAvailable from coreapi.utils import negotiate_decoder, negotiate_encoder @@ -27,10 +27,10 @@ def doc(): }) -# Documents have a mapping to python primatives in JSON style. +# Documents have a mapping to python primitives in JSON style. -def test_document_to_primative(doc): - data = _document_to_primative(doc) +def test_document_to_primitive(doc): + data = _document_to_primitive(doc) assert data == { '_type': 'document', '_meta': { @@ -46,7 +46,7 @@ def test_document_to_primative(doc): } -def test_primative_to_document(doc): +def test_primitive_to_document(doc): data = { '_type': 'document', '_meta': { @@ -60,27 +60,27 @@ def test_primative_to_document(doc): 'nested': {'child': {'_type': 'link', 'url': 'http://example.org/123'}}, '__type': 'needs escaping' } - assert _primative_to_document(data) == doc + assert _primitive_to_document(data) == doc -def test_error_to_primative(): +def test_error_to_primitive(): error = Error(title='Failure', content={'messages': ['failed']}) data = { '_type': 'error', '_meta': {'title': 'Failure'}, 'messages': ['failed'] } - assert _document_to_primative(error) == data + assert _document_to_primitive(error) == data -def test_primative_to_error(): +def test_primitive_to_error(): error = Error(title='Failure', content={'messages': ['failed']}) data = { '_type': 'error', '_meta': {'title': 'Failure'}, 'messages': ['failed'] } - assert _primative_to_document(data) == error + assert _primitive_to_document(data) == error # Codecs can load a document successfully. diff --git a/tests/test_document.py b/tests/test_document.py index 289a83d..db1d1c1 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -129,7 +129,7 @@ def test_error_does_not_support_property_assignment(): error.integer = 456 -# Children in documents are immutable primatives. +# Children in documents are immutable primitives. def test_document_dictionaries_coerced_to_objects(doc): assert isinstance(doc['dict'], Object)