Revision d2d5c360 pithos/lib/client.py
b/pithos/lib/client.py | ||
---|---|---|
73 | 73 |
|
74 | 74 |
return resp.status, headers, data |
75 | 75 |
|
76 |
def req(self, method, path, body=None, headers=None, format='text', params=None): |
|
77 |
full_path = '/%s/%s%s?format=%s' % (self.api, self.account, path, format) |
|
76 |
def req(self, method, path, body=None, headers=None, format='text', |
|
77 |
params=None): |
|
78 |
full_path = '/%s/%s%s?format=%s' % (self.api, self.account, path, |
|
79 |
format) |
|
78 | 80 |
if params: |
79 | 81 |
for k,v in params.items(): |
80 | 82 |
if v: |
81 | 83 |
full_path = '%s&%s=%s' %(full_path, k, v) |
82 | 84 |
conn = HTTPConnection(self.host) |
83 | 85 |
|
86 |
#encode whitespace |
|
87 |
full_path = full_path.replace(' ', '%20') |
|
84 | 88 |
|
85 | 89 |
kwargs = {} |
86 | 90 |
kwargs['headers'] = headers or {} |
... | ... | |
108 | 112 |
print data |
109 | 113 |
|
110 | 114 |
|
115 |
if data: |
|
116 |
assert data[-1] == '\n' |
|
117 |
#remove trailing enter |
|
118 |
data = data and data[:-1] or data |
|
119 |
|
|
111 | 120 |
return resp.status, headers, data |
112 | 121 |
|
113 | 122 |
def delete(self, path, format='text'): |
... | ... | |
117 | 126 |
return self.req('GET', path, headers=headers, format=format, |
118 | 127 |
params=params) |
119 | 128 |
|
120 |
def head(self, path, format='text'): |
|
121 |
return self.req('HEAD', path, format=format) |
|
129 |
def head(self, path, format='text', params=None):
|
|
130 |
return self.req('HEAD', path, format=format, params=params)
|
|
122 | 131 |
|
123 | 132 |
def post(self, path, body=None, format='text', headers=None): |
124 | 133 |
return self.req('POST', path, body, headers=headers, format=format) |
... | ... | |
136 | 145 |
data = data.strip().split('\n') |
137 | 146 |
return data |
138 | 147 |
|
139 |
def _get_metadata(self, path, prefix=None): |
|
140 |
status, headers, data = self.head(path) |
|
148 |
def _get_metadata(self, path, prefix=None, params=None):
|
|
149 |
status, headers, data = self.head(path, params=params)
|
|
141 | 150 |
if status == '404': |
142 | 151 |
return None |
143 | 152 |
prefixlen = prefix and len(prefix) or 0 |
... | ... | |
162 | 171 |
def list_containers(self, detail=False, params=None, headers=None): |
163 | 172 |
return self._list('', detail, params, headers) |
164 | 173 |
|
165 |
def account_metadata(self, restricted=False): |
|
174 |
def account_metadata(self, restricted=False, until=None):
|
|
166 | 175 |
prefix = restricted and 'x-account-meta-' or None |
167 |
return self._get_metadata('', prefix) |
|
176 |
params = until and {'until':until} or None |
|
177 |
return self._get_metadata('', prefix, params=params) |
|
168 | 178 |
|
169 | 179 |
def update_account_metadata(self, **meta): |
170 | 180 |
self._set_metadata('', 'account', **meta) |
... | ... | |
185 | 195 |
def delete_container(self, container): |
186 | 196 |
self.delete('/' + container) |
187 | 197 |
|
188 |
def retrieve_container_metadata(self, container, restricted=False): |
|
198 |
def retrieve_container_metadata(self, container, restricted=False, |
|
199 |
until=None): |
|
189 | 200 |
prefix = restricted and 'x-container-meta-' or None |
190 |
return self._get_metadata('/%s' % container, prefix) |
|
201 |
params = until and {'until':until} or None |
|
202 |
return self._get_metadata('/%s' % container, prefix, params=params) |
|
191 | 203 |
|
192 | 204 |
def update_container_metadata(self, container, **meta): |
193 | 205 |
self._set_metadata('/' + container, 'container', **meta) |
... | ... | |
202 | 214 |
|
203 | 215 |
def create_object(self, container, object, f=stdin, chunked=False, |
204 | 216 |
blocksize=1024, headers=None): |
205 |
if not f: |
|
206 |
return |
|
217 |
""" |
|
218 |
creates an object |
|
219 |
if f is None then creates a zero length object |
|
220 |
if f is stdin or chunked is set then performs chunked transfer |
|
221 |
""" |
|
207 | 222 |
path = '/%s/%s' % (container, object) |
208 | 223 |
if not chunked and f != stdin: |
209 |
data = f.read()
|
|
224 |
data = f and f.read() or None
|
|
210 | 225 |
self.put(path, data, headers=headers) |
211 | 226 |
else: |
212 | 227 |
self._chunked_transfer(path, 'PUT', f, headers=headers, |
Also available in: Unified diff