예제 #1
0
    def get(self, name):
        h = self.request.host
        name = urllib2.unquote(name)

        # Is this a static redirect in the application code?
        #
        if h in _hosts:
            d = _hosts[h](name)
            if d:
                self.redirect(d)
                return

        # I moved everything off S3.
        #
        if h == 'd.spearce.org':
            h = 'www.spearce.org'

        # This might be an UploadedFile
        #
        f = memcache.get(h + name)
        if f == '':
            self.response.set_status(404)
            self.response.out.write('404 Not Found')
            return

        if f is None:
            f = UploadedFile.get_by_key_name(h + name)
            if f is None:
                memcache.set(h + name, '', time=24 * 3600)
                self.response.set_status(404)
                self.response.out.write('404 Not Found')
                return

            memcache.set(h + name, f)

        last_mod = f.modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
        expires = f.modified + datetime.timedelta(days=2)

        self.response.headers['Content-Type'] = str(f.guessed_type)
        self.response.headers['Last-Modified'] = last_mod
        self.response.headers['Cache-Control'] = "public, max-age=172800"
        self.response.headers['Expires'] = expires.strftime(
            "%a, %d %b %Y %H:%M:%S GMT")

        if self.request.headers.has_key('If-Modified-Since'):
            ims = self.request.headers.get('If-Modified-Since')
            if ims == last_mod:
                self.error(304)
                return
            modsince = datetime.datetime.strptime(ims,
                                                  "%a, %d %b %Y %H:%M:%S %Z")
            if modsince >= f.modified:
                self.error(304)
                return

        self.send_blob(f.blob.key(), str(f.guessed_type))
예제 #2
0
  def get(self, name):
    h = self.request.host
    name = urllib2.unquote(name)

    # Is this a static redirect in the application code?
    #
    if h in _hosts:
      d = _hosts[h](name)
      if d:
        self.redirect(d)
        return

    # I moved everything off S3.
    #
    if h == 'd.spearce.org':
      h = 'www.spearce.org'

    # This might be an UploadedFile
    #
    f = memcache.get(h + name)
    if f == '':
      self.response.set_status(404)
      self.response.out.write('404 Not Found')
      return

    if f is None:
      f = UploadedFile.get_by_key_name(h + name)
      if f is None:
        memcache.set(h + name, '', time = 24 * 3600)
        self.response.set_status(404)
        self.response.out.write('404 Not Found')
        return

      memcache.set(h + name, f)

    last_mod = f.modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
    expires = f.modified + datetime.timedelta(days=2)

    self.response.headers['Content-Type'] = str(f.guessed_type)
    self.response.headers['Last-Modified'] = last_mod
    self.response.headers['Cache-Control'] = "public, max-age=172800"
    self.response.headers['Expires'] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")

    if self.request.headers.has_key('If-Modified-Since'):
      ims = self.request.headers.get('If-Modified-Since')
      if ims == last_mod:
        self.error(304)
        return
      modsince = datetime.datetime.strptime(ims, "%a, %d %b %Y %H:%M:%S %Z")
      if modsince >= f.modified:
        self.error(304)
        return

    self.send_blob(f.blob.key(), str(f.guessed_type))
예제 #3
0
  def post(self):
    upload = list(self.get_uploads())[0]
    host = self.request.host
    name = self.request.get('path')
    content_type = self.request.get('content_type')

    o = UploadedFile.get_by_key_name(host + name)
    if o:
      o = o.blob.key()

    f = UploadedFile(key_name = host + name,
                     content_type = content_type,
                     blob = upload.key(),
                     modified = datetime.datetime.now())
    f.put()
    memcache.set(f.key().name(), f)

    if o and o != upload.key():
      b = blobstore.BlobInfo.get(o)
      if b:
        b.delete()
    self.redirect('/admin/upload')
예제 #4
0
    def post(self):
        upload = list(self.get_uploads())[0]
        host = self.request.host
        name = self.request.get('path')
        content_type = self.request.get('content_type')

        o = UploadedFile.get_by_key_name(host + name)
        if o:
            o = o.blob.key()

        f = UploadedFile(key_name=host + name,
                         content_type=content_type,
                         blob=upload.key(),
                         modified=datetime.datetime.now())
        f.put()
        memcache.set(f.key().name(), f)

        if o and o != upload.key():
            b = blobstore.BlobInfo.get(o)
            if b:
                b.delete()
        self.redirect('/admin/upload')