[Checkins] SVN: Zope3/branches/3.3/src/zope/app/file/browser/file. Backport changes from trunk.

Yusei Tahara yusei at domen.cx
Thu Feb 1 23:46:29 EST 2007


Log message for revision 72316:
  Backport changes from trunk.
  Changed default charset of text file (``zope.app.file.file``) to utf-8.
  Added ObjectModifiedEvent when a text file object is modified through
  the edit form in the ZMI.
  

Changed:
  U   Zope3/branches/3.3/src/zope/app/file/browser/file.py
  U   Zope3/branches/3.3/src/zope/app/file/browser/file.txt

-=-
Modified: Zope3/branches/3.3/src/zope/app/file/browser/file.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/file/browser/file.py	2007-02-01 22:49:37 UTC (rev 72315)
+++ Zope3/branches/3.3/src/zope/app/file/browser/file.py	2007-02-02 04:46:28 UTC (rev 72316)
@@ -337,8 +337,15 @@
         >>> view.getData()
         {'data': u'', 'contentType': ''}
 
+        We install an event logger so we can see the events generated.
+
+        >>> def eventLog(event):
+        ...    print event
+        >>> zope.event.subscribers.append(eventLog)
+
         >>> view.setData({'contentType': 'text/plain; charset=ISO-8859-13',
-        ...               'data': u'text \u0105'})
+        ...               'data': u'text \u0105'}) # doctest:+ELLIPSIS
+        <zope.app.event.objectevent.ObjectModifiedEvent object at ...>
         u'Updated on ${date_time}'
 
         >>> view.context.contentType
@@ -349,6 +356,10 @@
         >>> view.getData()['data']
         u'text \u0105'
 
+        Cleanup eventlog.
+
+        >>> zope.event.subscribers.remove(eventLog)
+
     You will get an error if you try to specify a charset that cannot encode
     all the characters
 
@@ -439,6 +450,10 @@
         self.context.contentType = data['contentType']
         formatter = self.request.locale.dates.getFormatter('dateTime',
                                                            'medium')
+
+        event = lifecycleevent.ObjectModifiedEvent(self.context)
+        zope.event.notify(event)
+
         return _("Updated on ${date_time}",
                  mapping={'date_time': formatter.format(datetime.utcnow())})
 
@@ -460,16 +475,16 @@
 def extractCharset(content_type):
     """Extract charset information from a MIME type.
 
-        >>> extractCharset('text/plain; charset=UTF-8')
-        'UTF-8'
+        >>> extractCharset('text/plain; charset=US-ASCII')
+        'US-ASCII'
         >>> extractCharset('text/html; charset=ISO-8859-1')
         'ISO-8859-1'
         >>> extractCharset('text/plain')
-        'ASCII'
+        'UTF-8'
 
     """
     if content_type and content_type.strip():
         major, minor, params = contenttype.parse(content_type)
-        return params.get("charset", "ASCII")
+        return params.get("charset", "UTF-8")
     else:
-        return "ASCII"
+        return "UTF-8"

Modified: Zope3/branches/3.3/src/zope/app/file/browser/file.txt
===================================================================
--- Zope3/branches/3.3/src/zope/app/file/browser/file.txt	2007-02-01 22:49:37 UTC (rev 72315)
+++ Zope3/branches/3.3/src/zope/app/file/browser/file.txt	2007-02-02 04:46:28 UTC (rev 72316)
@@ -205,8 +205,8 @@
       </form>
   ...
 
-Files of type text/plain without any charset information can only contain ASCII
-text.
+Files of type text/plain without any charset information can contain UTF-8 text.
+So you can use ASCII text.
 
   >>> print http(r"""
   ... POST /sample.txt/edit.html HTTP/1.1
@@ -223,7 +223,7 @@
   ...
   ... This is a sample text file.
   ...
-  ... It can only contain US-ASCII characters.
+  ... It can contain US-ASCII characters.
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
   ...
@@ -251,7 +251,7 @@
   ...<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>
+  It can contain US-ASCII characters.</textarea></div>
   ...
           <div class="controls">
             <input type="submit" value="Refresh" />
@@ -274,14 +274,13 @@
   <BLANKLINE>
   This is a sample text file.
   <BLANKLINE>
-  It can only contain US-ASCII characters.
+  It can contain US-ASCII characters.
 
 
 Non-ASCII Text Files
 --------------------
 
-If we want an uploaded text file to contain non-ASCII characters, we have to
-explicitly specify the charset.
+We can also use non-ASCII charactors in text file.
 
   >>> print http("""
   ... POST /sample.txt/edit.html HTTP/1.1
@@ -292,13 +291,13 @@
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="field.contentType"
   ...
-  ... text/plain; charset=UTF-8
+  ... text/plain
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="field.data"
   ...
   ... This is a sample text file.
   ...
-  ... It can now contain UTF-8 characters, e.g. \xe2\x98\xbb (U+263B BLACK SMILING FACE).
+  ... It can contain non-ASCII(UTF-8) characters, e.g. \xe2\x98\xbb (U+263B BLACK SMILING FACE).
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
   ...
@@ -321,12 +320,12 @@
   <BLANKLINE>
         <div class="row">
   ...<input class="textType" id="field.contentType" name="field.contentType"
-            size="20" type="text" value="text/plain; charset=UTF-8"  />...
+            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 now contain UTF-8 characters, e.g. ... (U+263B BLACK SMILING FACE).</textarea></div>
+  It can contain non-ASCII(UTF-8) characters, e.g. ... (U+263B BLACK SMILING FACE).</textarea></div>
   ...
           <div class="controls">
             <input type="submit" value="Refresh" />
@@ -345,17 +344,17 @@
   >>> print response
   HTTP/1.1 200 Ok
   Content-Length: ...
-  Content-Type: text/plain; charset=UTF-8
+  Content-Type: text/plain
   Last-Modified: ...
   <BLANKLINE>
   This is a sample text file.
   <BLANKLINE>
-  It can now contain UTF-8 characters, e.g. ... (U+263B BLACK SMILING FACE).
+  It can contain non-ASCII(UTF-8) characters, e.g. ... (U+263B BLACK SMILING FACE).
 
   >>> u'\u263B' in response.getBody().decode('UTF-8')
   True
 
-You can use other charsets too.  Note that the browser form is always UTF-8.
+And you can explicitly specify the charset. Note that the browser form is always UTF-8.
 
   >>> print http("""
   ... POST /sample.txt/edit.html HTTP/1.1
@@ -443,7 +442,7 @@
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="field.contentType"
   ...
-  ... text/plain
+  ... text/plain; charset=US-ASCII
   ... -----------------------------165727764114325486311042046845
   ... Content-Disposition: form-data; name="field.data"
   ...
@@ -468,10 +467,10 @@
         <div>
           <h3>Change a file</h3>
   <BLANKLINE>
-          <p>The character set you specified (ASCII) cannot encode all characters in text.</p>
+          <p>The character set you specified (US-ASCII) cannot encode all characters in text.</p>
   <BLANKLINE>
         <div class="row">
-  ...<input class="textType" id="field.contentType" name="field.contentType" size="20" type="text" value="text/plain"  />...
+  ...<input class="textType" id="field.contentType" name="field.contentType" size="20" type="text" value="text/plain; charset=US-ASCII"  />...
         <div class="row">
   ...<textarea cols="60" id="field.data" name="field.data" rows="15" >This is a slightly changed sample text file.
   <BLANKLINE>
@@ -552,7 +551,7 @@
   Content-Type: text/html;charset=utf-8
   <BLANKLINE>
   ...
-     <li>The character set specified in the content type (ASCII) does not match file content.</li>
+     <li>The character set specified in the content type (UTF-8) does not match file content.</li>
   ...
 
 



More information about the Checkins mailing list