Exemple #1
0
 def child(self, request, segments):
     """
     Find the appropriate image to return including cacheing and resizing
     """
     # Build the full filename from the segments.
     filestore, key = util.decode_file_resource_path('/'.join(segments))
     # get the requested filepath from the segments
     etag = str(request.if_none_match)
     f = self.get_file(request, filestore, key, etag)
     if f:
         return f
     return http.not_found()
Exemple #2
0
 def test_file_resource_path(self):
     tests = [
         (None, 'foo', 'foo'),
         (None, '@foo', '@@foo'),
         (None, 'f@o', 'f@o'),
         ('bar', 'foo', '@bar/foo'),
         ('bar', '@foo', '@bar/@foo'),
         ('bar', 'f@o', '@bar/f@o'),
     ]
     for (name, key, path) in tests:
         encoded = util.encode_file_resource_path(name, key)
         self.assertTrue(encoded == path)
         self.assertTrue(util.decode_file_resource_path(encoded) == (name, key))
Exemple #3
0
 def test_file_resource_path(self):
     tests = [
         (None, 'foo', 'foo'),
         (None, '@foo', '@@foo'),
         (None, 'f@o', 'f@o'),
         ('bar', 'foo', '@bar/foo'),
         ('bar', '@foo', '@bar/@foo'),
         ('bar', 'f@o', '@bar/f@o'),
     ]
     for (name, key, path) in tests:
         encoded = util.encode_file_resource_path(name, key)
         self.assertTrue(encoded == path)
         self.assertTrue(
             util.decode_file_resource_path(encoded) == (name, key))
Exemple #4
0
    def from_request_data(self, field, request_data):
        """
        Creates a File object if possible
        """
        # XXX We could add a file converter that converts this to a string data?

        if request_data['name'] == ['']:
            return None
        elif request_data['name'] == request_data['default']:
            return SchemaFile(None, None, None)
        else:
            key = util.decode_file_resource_path(request_data['name'][0])[1]
            try:
                cache_tag, headers, f = self.filestore.get(key)
            except KeyError:
                return None
            headers = dict(headers)
            return SchemaFile(f, headers['Filename'], headers['Content-Type'])
Exemple #5
0
    def from_request_data(self, field, request_data):
        """
        Creates a File object if possible
        """
        # XXX We could add a file converter that converts this to a string data?

        if request_data['name'] == ['']:
            return None
        elif request_data['name'] == request_data['default']:
            return SchemaFile(
                None,
                request_data.get('filename', [None])[0], None,
                {'old_name': list(i for i in request_data['name'])})
        else:
            key = util.decode_file_resource_path(request_data['name'][0])[1]
            try:
                cache_tag, headers, f = self.filestore.get(key)
            except KeyError:
                return None
            headers = dict(headers)
            return SchemaFile(f, headers['Filename'], headers['Content-Type'])