aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorTom Christie2012-10-17 22:07:56 +0100
committerTom Christie2012-10-17 22:07:56 +0100
commit99d48f90030d174ef80498b48f56af6489865f0d (patch)
tree4c4181d708fc6733c3f4459af7235fe1a17f0632 /docs
parent6717d654d0bbfdfca4aaea84a5b4814c4e5f7567 (diff)
downloaddjango-rest-framework-99d48f90030d174ef80498b48f56af6489865f0d.tar.bz2
Drop .parse_string_or_stream() - keep API minimal.
Diffstat (limited to 'docs')
-rw-r--r--docs/api-guide/parsers.md10
-rw-r--r--docs/tutorial/1-serialization.md7
2 files changed, 10 insertions, 7 deletions
diff --git a/docs/api-guide/parsers.md b/docs/api-guide/parsers.md
index 4f145ba3..a950c0e0 100644
--- a/docs/api-guide/parsers.md
+++ b/docs/api-guide/parsers.md
@@ -91,11 +91,11 @@ You will typically want to use both `FormParser` and `MultiPartParser` together
# Custom parsers
-To implement a custom parser, you should override `BaseParser`, set the `.media_type` property, and implement the `.parse_stream(self, stream, parser_context)` method.
+To implement a custom parser, you should override `BaseParser`, set the `.media_type` property, and implement the `.parse(self, stream, parser_context)` method.
The method should return the data that will be used to populate the `request.DATA` property.
-The arguments passed to `.parse_stream()` are:
+The arguments passed to `.parse()` are:
### stream
@@ -116,7 +116,7 @@ The following is an example plaintext parser that will populate the `request.DAT
media_type = 'text/plain'
- def parse_stream(self, stream, parser_context=None):
+ def parse(self, stream, parser_context=None):
"""
Simply return a string representing the body of the request.
"""
@@ -124,7 +124,7 @@ The following is an example plaintext parser that will populate the `request.DAT
## Uploading file content
-If your custom parser needs to support file uploads, you may return a `DataAndFiles` object from the `.parse_stream()` method. `DataAndFiles` should be instantiated with two arguments. The first argument will be used to populate the `request.DATA` property, and the second argument will be used to populate the `request.FILES` property.
+If your custom parser needs to support file uploads, you may return a `DataAndFiles` object from the `.parse()` method. `DataAndFiles` should be instantiated with two arguments. The first argument will be used to populate the `request.DATA` property, and the second argument will be used to populate the `request.FILES` property.
For example:
@@ -133,7 +133,7 @@ For example:
A naive raw file upload parser.
"""
- def parse_stream(self, stream, parser_context):
+ def parse(self, stream, parser_context):
content = stream.read()
name = 'example.dat'
content_type = 'application/octet-stream'
diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md
index e21433ba..5b58f293 100644
--- a/docs/tutorial/1-serialization.md
+++ b/docs/tutorial/1-serialization.md
@@ -134,12 +134,15 @@ We've now got a few comment instances to play with. Let's take a look at serial
At this point we've translated the model instance into python native datatypes. To finalise the serialization process we render the data into `json`.
- stream = JSONRenderer().render(serializer.data)
- stream
+ content = JSONRenderer().render(serializer.data)
+ content
# '{"id": 1, "email": "leila@example.com", "content": "nothing to say", "created": "2012-08-22T16:20:09.822"}'
Deserialization is similar. First we parse a stream into python native datatypes...
+ import StringIO
+
+ stream = StringIO.StringIO(content)
data = JSONParser().parse(stream)
...then we restore those native datatypes into to a fully populated object instance.