Mercurial > ~astiob > upreckon > hgweb
comparison files.py @ 98:62a96d51bf94
Fixed ZipArchive.extract with relative paths on Windows
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Wed, 02 Mar 2011 19:52:03 +0000 |
parents | c62c9bfd614a |
children | cdd0f970d112 |
comparison
equal
deleted
inserted
replaced
97:bbf9c434fa57 | 98:62a96d51bf94 |
---|---|
106 | 106 |
107 def __init__(self, path): | 107 def __init__(self, path): |
108 self.file = zipfile.ZipFile(path) | 108 self.file = zipfile.ZipFile(path) |
109 | 109 |
110 def extract(self, name, target): | 110 def extract(self, name, target): |
111 member = self.file.getinfo(name) | |
112 # FIXME: 2.5 lacks ZipFile.extract | |
111 if os.path.isabs(target): | 113 if os.path.isabs(target): |
112 # To my knowledge, this is as portable as it gets | 114 # To my knowledge, this is as portable as it gets |
113 path = os.path.join(os.path.splitdrive(target)[0], os.path.sep) | 115 path = os.path.join(os.path.splitdrive(target)[0], os.path.sep) |
114 else: | 116 member.filename = os.path.relpath(target, path) |
115 path = None | 117 self.file.extract(member, path) |
116 | 118 else: |
117 member = self.file.getinfo(name) | 119 member.filename = os.path.relpath(target) |
118 member.filename = os.path.relpath(target, path) | 120 self.file.extract(member) |
119 # FIXME: 2.5 lacks ZipFile.extract | |
120 self.file.extract(member, path) | |
121 | 121 |
122 def open(self, name): | 122 def open(self, name): |
123 return self.file.open(name, 'rU') | 123 return self.file.open(name, 'rU') |
124 | 124 |
125 def exists(self, queried_name): | 125 def exists(self, queried_name): |