[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/file/browser/f Added a functional doctest for File objects, in preparation to tackle

Marius Gedminas marius at pov.lt
Fri Jul 29 12:21:25 EDT 2005


Log message for revision 37549:
  Added a functional doctest for File objects, in preparation to tackle
  http://www.zope.org/Collectors/Zope3-dev/302
  
  

Changed:
  A   Zope3/trunk/src/zope/app/file/browser/file.txt
  U   Zope3/trunk/src/zope/app/file/browser/ftests.py

-=-
Added: Zope3/trunk/src/zope/app/file/browser/file.txt
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/file.txt	2005-07-29 16:14:51 UTC (rev 37548)
+++ Zope3/trunk/src/zope/app/file/browser/file.txt	2005-07-29 16:21:24 UTC (rev 37549)
@@ -0,0 +1,276 @@
+File objects
+============
+
+Adding Files
+------------
+
+You can add File objects from the common tasks menu in the ZMI.
+
+  >>> print http(r"""
+  ... GET /@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  ...
+      <title>Z3: </title>
+  ...
+                          <div class="box" id="commonTasks">
+                              <h4>Add:</h4>
+                              <div class="body">
+  ...
+      <div class="content...">
+        <a href="http://localhost/@@+/action.html?type_name=zope.app.file.File"
+           class="">File</a>
+      </div>
+  ...
+
+Let's follow that link.
+
+  >>> print http(r"""
+  ... GET /@@+/action.html?type_name=zope.app.file.File HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... """)
+  HTTP/1.1 303 See Other
+  Content-Length: ...
+  Location: http://localhost/+/zope.app.file.File=
+  <BLANKLINE>
+
+The file add form lets you specify the content type, the object name, and
+optionally upload the contents of the file.
+
+  >>> print http(r"""
+  ... GET /+/zope.app.file.File= HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  ...
+      <title>Z3: +</title>
+  ...
+  ...
+    <form action="http://localhost/+/zope.app.file.File%3D"
+          method="post" enctype="multipart/form-data">
+      <h3>Add a File</h3>
+      ...<input class="textType" id="field.contentType"
+                name="field.contentType" size="20" type="text" value="" />...
+      ...<input class="fileType" id="field.data" name="field.data" size="20"
+                type="file" />...
+        <div class="controls"><hr />
+          <input type="submit" value="Refresh" />
+          <input type="submit" value="Add"
+                 name="UPDATE_SUBMIT" />
+          &nbsp;&nbsp;<b>Object Name</b>&nbsp;&nbsp;
+          <input type="text" name="add_input_name" value="" />
+        </div>
+  ...
+    </form>
+  ...
+
+Binary files
+------------
+
+Let us upload a binary file.
+
+  >>> print http("""
+  ... POST /+/zope.app.file.File%3D HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Type: multipart/form-data; boundary=---------------------------73793505419963331401738523176
+  ...
+  ... -----------------------------73793505419963331401738523176
+  ... Content-Disposition: form-data; name="field.contentType"
+  ... 
+  ... application/octet-stream
+  ... -----------------------------73793505419963331401738523176
+  ... Content-Disposition: form-data; name="field.data"; filename="hello.txt.gz"
+  ... Content-Type: application/x-gzip
+  ... 
+  ... \x1f\x8b\x08\x08\xcb\x48\xea\x42\x00\x03\x68\x65\x6c\x6c\x6f\x2e\
+  ... \x74\x78\x74\x00\xcb\x48\xcd\xc9\xc9\xe7\x02\x00\x20\x30\x3a\x36\
+  ... \x06\x00\x00\x00
+  ... -----------------------------73793505419963331401738523176
+  ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+  ... 
+  ... Add
+  ... -----------------------------73793505419963331401738523176
+  ... Content-Disposition: form-data; name="add_input_name"
+  ... 
+  ...
+  ... -----------------------------73793505419963331401738523176--
+  ... """)
+  HTTP/1.1 303 See Other
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  Location: http://localhost/@@contents.html
+  <BLANKLINE>
+  ...
+
+Since we did not specify the object name in the form, Zope 3 will use the
+filename.
+
+  >>> response = http("""
+  ... GET /hello.txt.gz HTTP/1.1
+  ... """)
+  >>> print response
+  HTTP/1.1 200 Ok
+  Content-Length: 36
+  Content-Type: application/octet-stream
+  <BLANKLINE>
+  ...
+
+Let's make sure the (binary) content of the file is correct
+  
+  >>> response.getBody().encode('base64')
+  'H4sICMtI6kIAA2hlbGxvLnR4dADLSM3JyecCACAwOjYGAAAA\n'
+
+
+Text files
+----------
+
+Let us now create a text file.
+
+  >>> print http(r"""
+  ... POST /+/zope.app.file.File%3D HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Type: multipart/form-data; boundary=---------------------------167769037320366690221542301033
+  ... 
+  ... -----------------------------167769037320366690221542301033
+  ... Content-Disposition: form-data; name="field.contentType"
+  ... 
+  ... text/plain
+  ... -----------------------------167769037320366690221542301033
+  ... Content-Disposition: form-data; name="field.data"; filename=""
+  ... Content-Type: application/octet-stream
+  ... 
+  ... 
+  ... -----------------------------167769037320366690221542301033
+  ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+  ... 
+  ... Add
+  ... -----------------------------167769037320366690221542301033
+  ... Content-Disposition: form-data; name="add_input_name"
+  ... 
+  ... sample.txt
+  ... -----------------------------167769037320366690221542301033--
+  ... """)
+  HTTP/1.1 303 See Other
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  Location: http://localhost/@@contents.html
+  <BLANKLINE>
+  ...
+
+The file is initially empty, since we did not upload anything.
+
+  >>> print http("""
+  ... GET /sample.txt HTTP/1.1
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: 0
+  Content-Type: text/plain;charset=utf-8
+  <BLANKLINE>
+
+Since it is a text file, we can edit it directly in a web form.
+
+  >>> print http(r"""
+  ... GET /sample.txt/edit.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  ...
+      <title>Z3: sample.txt</title>
+  ...
+      <form action="http://localhost/sample.txt/edit.html"
+            method="post" enctype="multipart/form-data">
+        <div>
+          <h3>Change a file</h3>
+  ...<input class="textType" id="field.contentType" name="field.contentType"
+            size="20" type="text" value="text/plain"  />...
+  ...<textarea cols="60" id="field.data" name="field.data" rows="15" ></textarea>...
+  ...
+          <div class="controls">
+            <input type="submit" value="Refresh" />
+            <input type="submit" name="UPDATE_SUBMIT"
+                   value="Change" />
+          </div>
+  ...
+      </form>
+  ...
+
+Files of type text/plain without any charset information can only contain ASCII
+text.
+
+  >>> print http(r"""
+  ... POST /sample.txt/edit.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: ...
+  ... Content-Type: multipart/form-data; boundary=---------------------------165727764114325486311042046845
+  ... 
+  ... -----------------------------165727764114325486311042046845
+  ... Content-Disposition: form-data; name="field.contentType"
+  ... 
+  ... text/plain
+  ... -----------------------------165727764114325486311042046845
+  ... Content-Disposition: form-data; name="field.data"
+  ... 
+  ... This is a sample text file.
+  ... 
+  ... It can only contain US-ASCII characters.
+  ... -----------------------------165727764114325486311042046845
+  ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+  ... 
+  ... Change
+  ... -----------------------------165727764114325486311042046845--
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: ...
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  ...
+      <title>Z3: sample.txt</title>
+  ...
+      <form action="http://localhost/sample.txt/edit.html"
+            method="post" enctype="multipart/form-data">
+        <div>
+          <h3>Change a file</h3>
+  <BLANKLINE>
+          <p>Updated on ...</p>
+  <BLANKLINE>
+        <div class="row">
+  ...<input class="textType" id="field.contentType" name="field.contentType"
+            size="20" type="text" value="text/plain"  />...
+        <div class="row">
+  ...<textarea cols="60" id="field.data" name="field.data" rows="15"
+  >This is a sample text file.
+  <BLANKLINE>
+  It can only contain US-ASCII characters.</textarea></div>
+  ...
+          <div class="controls">
+            <input type="submit" value="Refresh" />
+            <input type="submit" name="UPDATE_SUBMIT"
+                   value="Change" />
+          </div>
+  ...
+      </form>
+  ...
+
+Here's the file
+
+  >>> print http(r"""
+  ... GET /sample.txt HTTP/1.1
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: ...
+  Content-Type: text/plain;charset=utf-8
+  <BLANKLINE>
+  This is a sample text file.
+  <BLANKLINE>
+  It can only contain US-ASCII characters.
+


Property changes on: Zope3/trunk/src/zope/app/file/browser/file.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/file/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/ftests.py	2005-07-29 16:14:51 UTC (rev 37548)
+++ Zope3/trunk/src/zope/app/file/browser/ftests.py	2005-07-29 16:21:24 UTC (rev 37549)
@@ -264,6 +264,7 @@
         unittest.makeSuite(FileTest),
         unittest.makeSuite(ImageTest),
         functional.FunctionalDocFileSuite('url.txt'),
+        functional.FunctionalDocFileSuite('file.txt'),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list