Attachment 'if_modified_since.patch'

Download

   1 --- moinmoin-installed\Lib\site-packages\MoinMoin\Copy of request.py	2006-07-25 15:57:22.373580500 +0200
   2 +++ moinmoin-installed\Lib\site-packages\MoinMoin\request.py	2006-07-25 16:09:05.515236400 +0200
   3 @@ -67,6 +67,7 @@
   4  
   5      # Defaults (used by sub classes)
   6      http_accept_language = 'en'
   7 +    if_modified_since = 0
   8      server_name = 'localhost'
   9      server_port = '80'
  10  
  11 @@ -1400,6 +1401,7 @@
  12              
  13              # Copy headers
  14              self.http_accept_language = self.twistd.getHeader('Accept-Language')
  15 +            self.if_modified_since = self.twistd.getHeader('If-Modified-Since')
  16              self.saved_cookie = self.twistd.getHeader('Cookie')
  17              self.http_user_agent = self.twistd.getHeader('User-Agent')
  18              
  19 @@ -1627,6 +1629,8 @@
  20              # Copy headers
  21              self.http_accept_language = (sa.headers.getheader('accept-language') 
  22                                           or self.http_accept_language)
  23 +            self.if_modified_since = (sa.headers.getheader('If-Modified-Since') 
  24 +                                      or self.if_modified_since)
  25              self.http_user_agent = sa.headers.getheader('user-agent', '')            
  26              co = filter(None, sa.headers.getheaders('cookie'))
  27              self.saved_cookie = ', '.join(co) or ''
  28 --- moinmoin-installed\Lib\site-packages\MoinMoin\action\Copy of AttachFile.py	2006-05-11 18:24:00.000000000 +0200
  29 +++ moinmoin-installed\Lib\site-packages\MoinMoin\action\AttachFile.py	2006-07-27 16:18:00.419076800 +0200
  30 @@ -30,6 +30,9 @@
  31  from MoinMoin import config, user, util, wikiutil, packages
  32  from MoinMoin.Page import Page
  33  from MoinMoin.util import MoinMoinNoFooter, filesys
  34 +from MoinMoin.util import timefuncs
  35 +import time
  36 +import email.Utils
  37  
  38  action_name = __name__.split('.')[-1]
  39  
  40 @@ -633,22 +636,53 @@
  41      filename, fpath = _access_file(pagename, request)
  42      if not filename: return # error msg already sent in _access_file
  43  
  44 +    use_cached_version = False
  45 +    filemtime = int(time.mktime(time.gmtime(os.path.getmtime(fpath)))) # in GMT
  46 +    client_filemtime = -1
  47 +    if hasattr(request, "if_modified_since") and request.if_modified_since != 0:
  48 +        client_date = email.Utils.parsedate(request.if_modified_since)
  49 +        if client_date:
  50 +            client_filemtime = int(time.mktime(client_date))
  51 +            if int(time.mktime(time.gmtime(filemtime))) == client_filemtime:
  52 +                use_cached_version = True
  53 +
  54      # get mimetype
  55      type, enc = mimetypes.guess_type(filename)
  56      if not type:
  57          type = "application/octet-stream"
  58  
  59 -    # send header
  60 -    request.http_headers([
  61 -        "Content-Type: %s" % type,
  62 -        "Content-Length: %d" % os.path.getsize(fpath),
  63 -        # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
  64 -        # There is no solution that is compatible to IE except stripping non-ascii chars
  65 -        "Content-Disposition: attachment; filename=\"%s\"" % filename.encode(config.charset),
  66 -    ])
  67  
  68 -    # send data
  69 -    shutil.copyfileobj(open(fpath, 'rb'), request, 8192)
  70 +    if use_cached_version:
  71 +        user_headers = []
  72 +        for header in request.user_headers:
  73 +            ignore_header = False
  74 +            for h in ["Pragma:", "Expires:", "Cache-Control:"]:
  75 +                if header.lower().startswith(h.lower()):
  76 +                    ignore_header = True
  77 +                    continue
  78 +            if not ignore_header:
  79 +                user_headers.append(header)
  80 +        request.user_headers = user_headers
  81 +        
  82 +        # send header
  83 +        request.http_headers([
  84 +            "Content-Type: %s" % type,
  85 +            "Content-Length: 0",
  86 +            "Last-Modified: " + timefuncs.formathttpdate(filemtime),
  87 +        ])
  88 +        request.setResponseCode(304)
  89 +    else:
  90 +        # send header
  91 +        request.http_headers([
  92 +            "Content-Type: %s" % type,
  93 +            "Content-Length: %d" % os.path.getsize(fpath),
  94 +            # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
  95 +            # There is no solution that is compatible to IE except stripping non-ascii chars
  96 +            "Content-Disposition: attachment; filename=\"%s\"" % filename.encode(config.charset),
  97 +            "Last-Modified: " + timefuncs.formathttpdate(filemtime),
  98 +        ])
  99 +        # send data
 100 +        shutil.copyfileobj(open(fpath, 'rb'), request, 8192)
 101  
 102      raise MoinMoinNoFooter
 103  

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] (2006-07-27 13:28:42, 41.0 KB) [[attachment:EXIF.py]]
  • [get | view] (2006-07-27 18:28:39, 2.8 KB) [[attachment:EXIF_patch.patch]]
  • [get | view] (2006-07-27 18:29:41, 50.5 KB) [[attachment:Gallery.patch]]
  • [get | view] (2006-07-27 19:15:39, 25.6 KB) [[attachment:Gallery2.patch]]
  • [get | view] (2006-07-27 13:33:03, 3175.6 KB) [[attachment:Gallery2_additional_files_win32.zip]]
  • [get | view] (2006-07-27 18:25:50, 4.5 KB) [[attachment:if_modified_since.patch]]
 All files | Selected Files: delete move to page copy to page

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