Attachment 'quote.patch'

Download

   1 * looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-714 to compare with
   2 * comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-714
   3 M  MoinMoin/wikiutil.py
   4 
   5 * modified files
   6 
   7 --- orig/MoinMoin/wikiutil.py
   8 +++ mod/MoinMoin/wikiutil.py
   9 @@ -6,7 +6,7 @@
  10      @license: GNU GPL, see COPYING for details.
  11  """
  12      
  13 -import os, re, difflib
  14 +import os, re, difflib, urllib
  15  
  16  from MoinMoin import util, version, config
  17  from MoinMoin.util import pysupport
  18 @@ -98,41 +98,21 @@
  19  # FIXME: better name would be quoteURL, as this is useful for any
  20  # string, not only wiki names.
  21  def quoteWikinameURL(pagename, charset=config.charset):
  22 -    """
  23 -    Return a simple encoding of filename in plain ascii.
  24 +    """ Return a url encoding of filename in plain ascii
  25  
  26      Warning: will raise UnicodeError if pagename can not be encoded
  27      using charset. The default config.charset, 'utf-8', can encode any
  28      character.
  29  
  30 -    FIXME: isn't it better to use here urllib.quote instead of duplicating
  31 -    the code? If we use cgi, urllib is already available. if we do
  32 -    duplicate the code from urllib, why we don't use also fast_quote as
  33 -    urllib does?
  34 -
  35 -    FIXME: If we don't use urllib.quote, maybe this is cleaner and faster
  36 -    to use re, in the same way quoteWikinameFS works.
  37 +    TODO: url encoding should use utf-8 - remove the charset option?
  38      
  39      @param pagename: the original pagename, maybe containing non-ascii chars
  40      @rtype: string
  41 -    @return: the quoted filename, all special chars encoded in (xx)
  42 +    @return: the quoted filename, all unsafe characters encoded
  43      """
  44 -    safe = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+-_,\'*'
  45 -    pagename = pagename.replace(u' ', u'_') # " " -> "_"
  46 -    filename = pagename.encode(charset)
  47 -    
  48 -    res = list(filename)
  49 -    c = None
  50 -    for i in range(len(res)):
  51 -        prev = c
  52 -        c = res[i]
  53 -        if c not in safe:
  54 -            # FIXME: why are we doing this?
  55 -            if c == '.' and prev == '/':
  56 -                res[i] = '(%02x)' % ord(c)
  57 -            else:
  58 -                res[i] = '%%%02x' % ord(c)
  59 -    return ''.join(res)
  60 +    pagename = pagename.replace(u' ', u'_')
  61 +    pagename = pagename.encode(charset)
  62 +    return urllib.quote(pagename)
  63  
  64  
  65  def escape(s, quote=0):

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-05-18 16:28:14, 2.3 KB) [[attachment:quote.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.