当前位置: 首页>>代码示例>>Python>>正文


Python File.get_by_key_name方法代码示例

本文整理汇总了Python中models.File.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python File.get_by_key_name方法的具体用法?Python File.get_by_key_name怎么用?Python File.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.File的用法示例。


在下文中一共展示了File.get_by_key_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get_by_key_name [as 别名]
    def delete(self, file_uuid):
        file = File.get_by_key_name(file_uuid)

        if file:
            map(lambda f: f.delete(), file.fragments)
            file.delete()
        else:
            self.error(404)
开发者ID:protomouse,项目名称:appengine-filestore,代码行数:10,代码来源:handlers.py

示例2: get

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get_by_key_name [as 别名]
    def get(self, file_uuid):
        file = File.get_by_key_name(file_uuid)

        if file:
            self.response.headers['Last-Modified'] = http_format_date(file.last_modified)
            self.response.headers['Cache-Control'] = 'max-age=%d' % config.cache_expiry

            if_modified_since = http_parse_date(self.request.headers.get('If-Modified-Since', None))
            if if_modified_since and if_modified_since >= file.last_modified.replace(microsecond=0):
                self.response.set_status(304)
            else:
                self.response.headers['Content-Disposition'] = 'inline; filename=%s' % file.name
                self.response.headers['Content-Type'] = file.content_type
                self.response.headers['Expires'] = http_format_date(time() + config.cache_expiry)

                for fragment in file.fragments:
                    self.response.out.write(fragment.data)
        else:
            self.error(404)
开发者ID:protomouse,项目名称:appengine-filestore,代码行数:21,代码来源:handlers.py

示例3: get

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import get_by_key_name [as 别名]
 def get(self):
   self.response.headers['Content-Type'] = 'text/plain'
   devhelp_url = '\n\nPlease visit http://www.dynmirror.net/help/developers/ for more information.'
   #If url is given, use that as the digest
   digest = os.path.basename(self.request.path)
   if len(digest) and not digest.endswith('.metalink'):
     return self.not_found('404 not found: If you do file look-ups by digest, it needs to end in ".metalink".' + devhelp_url)
   digest = digest[:-len('.metalink')]
   digests = {}
   url = self.request.get('url')
   fileLink = LinkElement()
   
   if len(url):
     #Try to load the digest from the database
     url = File.urlparse(url).geturl()
     
     #Add Coral link if wanted
     if self.request.get('coral', default_value = 'not_set') != 'not_set':
       cu = urlparse.urlparse(url) #Parse for the coral url
       if cu.scheme == 'http' and not cu.netloc.endswith('.nyud.net'):
         fileLink.urls.append({'v': 'http://' + cu.hostname + '.nyud.net' + cu.path, 'a':{'type': File.urlparse(url).scheme}})
     Hit(path = self.request.path, remote_addr = self.request.remote_addr, referer = self.request.headers.get('referer', ''), comment = url).save()
     f = File.get_by_key_name(url)
     if f == None:
       #Host a link only metalink
       fileLink.name = os.path.basename(url)
       fileLink.urls.insert(0, {'v': url, 'a':{'type': File.urlparse(url).scheme}})
       self.response.headers['Content-Type'] = 'application/metalink+xml'
       self.response.headers['Content-Disposition'] = 'attachment; filename="%s.metalink"' % os.path.basename(url).replace('"', '\\"')
       return self.render_to_response('metalink.xml', {'files': [fileLink], 'comment': 'Link only, because no validated link information could be found in the database. Make sure you use the _exact_ url you used to add the metadata.'})
     #inherit all the digest information from the file in db
     fileLink.name = f.name
     fileLink.size = f.size
     fileLink.digests.update(f.digests())
     if len(digest) > 0:
       return self.response.out.write('For security reasons, you can not combine digest and url, because we can not determine which is authorative and what to do in case they do not match in the database.' + devhelp_url)
   
   if len(digest) > 0:
     #Malformed digest
     if not hash_sizes.has_key(len(digest)):
       return self.not_found('404 Not Found, the digest is considered malformed. Make sure it is lowercase hex representing an MD5, SHA1, SHA256 or SHA512.' + devhelp_url)
     if not lower_hex_regex.match(digest):
       return self.not_found('404 Not Found, the digest is considered malformed because it did not match /[0-9a-f]/.' + devhelp_url)
     #OK, so a digest is given, set the digest in the fileLink to the given value
     fileLink.digests[hash_sizes[len(digest)]] = digest
   
   #TODO Unique hosts; hosts = set
   #Explode the file using all known digests, both url and digest
   names = {}
   sizes = {}
   cntry_regex = re.compile('.*\.(a[cdefgilmnoqrstuwxz]|c[acdfghiklmnoruvxyz]|b[abdefghijmnorstvwyz]|e[ceghrstu]|d[ejkmoz]|g[abdefghilmnpqrstuwy]|f[ijkmor]|i[delmnoqrst]|h[kmnrtu]|k[eghimnprwyz]|j[emop]|m[acdeghklmnopqrstuvwxyz]|l[abcikrstuvy]|o[m]|n[acefgilopruz]|q[a]|p[aefghklmnrstwy]|s[abcdeghijklmnortuvyz]|r[eosuw]|u[agkmsyz]|t[cdfghjklmnoprtvwz]|w[fs]|v[aceginu]|y[etu]|z[amw])$')
   for digest_type in fileLink.digests:
     files = File.all().filter('%s = ' % digest_type, fileLink.digests[digest_type]).fetch(20)
     for f in files:
       attr = {'type': 'http'}#Optimization, currently only HTTP supported f.scheme
       cntry = cntry_regex.match(f.hostname)
       if cntry:
         attr['location'] = cntry.group(1)
       fileLink.urls.append({'v': f.url(), 'a': attr})
       names.setdefault(f.name, 0)
       names[f.name] += 1
       sizes.setdefault(f.size, 0)
       sizes[f.size] += 1
   
   #If a name is given, just rename the file
   name = self.request.get('name')
   if name:
     fileLink.name = name
   if not fileLink.name:
     #Democratic naming
     names = [(names[k], k) for k in names]
     names.sort()
     fileLink.name = names[-1][1]
   if not fileLink.size:
     #Democratic size
     sizes[0] = 0
     sizes = [(sizes[k], k) for k in sizes]
     sizes.sort()
     fileLink.size = sizes[-1][1]
   random.shuffle(fileLink.urls)      
   self.response.headers['Content-Type'] = 'application/metalink+xml'
   self.response.headers['Content-Disposition'] = 'attachment; filename="%s.metalink"' % os.path.basename(fileLink.name).replace('"', '\\"')
   return self.render_to_response('metalink.xml', {'files': [fileLink]})
开发者ID:bneijt,项目名称:dynmirror.net,代码行数:85,代码来源:view_metalink.py


注:本文中的models.File.get_by_key_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。