使用标准文件函数访问zip档案中的文件

zipaccess的Python项目详细描述


修补程序函数[模块]:文件+打开,和OS.PATH:存在+文件 启用使用标准文件函数访问ZIP存档文件中的文件。

套餐:
http://pypi.python.org/pypi/zipaccess
项目:
https://github.com/iki/zipaccess
问题:
https://github.com/iki/zipaccess/issues
更新:
https://github.com/iki/zipaccess/commits/master.atom
通过pip安装:
pip install zipaccess
通过easy_install安装:
easy_install zipaccess
源通过git
git clone https://github.com/iki/zipaccess
源通过hg-git
hg clone git://github.com/iki/zipaccess

用法

用作类。不要实例化它:

class AnyZipAccess(zipaccess.ZipAccess):
    any_zip = True  # custom modifications here

AnyZipAccess.enable()

或用作模块:

zipaccess.enable()
zipaccess.addzip('data.zip')

或者,将zipaccess.zipaccess注册为os.zipaccess:

zipaccess.enable(register=True)

因此,其他模块可以轻松使用:

try:
    os.zipaccess.enable(locals())
except AttributeError:
    pass

关于Google App Engine(gae)

的说明

在gae上,即使在本地名称空间中,内置模块的更改也不会反映出来。

要在任何GAE模块中使用ZIP访问,您需要为该模块本地变量启用它:

try:
    import zipaccess
    zipaccess.enable(locals())
except ImportError:
    pass

或者,仅在本地启用ZIP访问(如果已注册):

try:
    os.zipaccess.enable(locals())
except AttributeError:
    pass

或在外部启用目标模块:

zipaccess.enable([
    'babel.core',
    'babel.localedata',
    'tipfy.template',
    'werkzeug.debug.tbtools',
    ])
# It imports all the modules though, which may be not what you want.
# If you know, how to hook on module import, let me kindly know.

注意,OS.PATH ISO文件和OS.PATH存在全局补丁。即使在盖伊, 它们适用于给定实例的所有模块。如果某些模块支持 zip文件,它们通常首先检查是否存在常规文件,如果没有,则 拆分路径并检查是否存在zip文件。 启用ZIP访问后,常规文件检查将成功,这是正常的 只要随后使用的file()或open()函数也被修补。

示例:

The tipfy.debugger.get_loader() function checks if templates are located in a regular directory or in a zip file (^{tt5}$ usually). Then it returns tipfy.template.Loader or tipfy.template.ZipLoader accordingly. With zipaccess enabled, the standard tipfy.template.Loader will be used, and therefore ^{tt6}$ is needed to make it work.

See https://github.com/moraes/tipfy/blob/master/tipfy/debugger/__init__.py#L26.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar