3
3
# Copyright (C) 2007 Ross Burton <ross@burtonini.com>
5
5
# This program is free software; you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2, or (at your option) any later version.
6
# the terms of the GNU Lesser General Public License as published by the Free
7
# Software Foundation; either version 2, or (at your option) any later version.
9
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
14
# You should have received a copy of the GNU General Public License along with
77
77
headers={"Content-Type": "application/x-www-form-urlencoded"},
78
78
postdata=urllib.urlencode(kwargs))
80
def __cb(self, data, method):
81
self.logger.info("%s returned" % method)
82
xml = ElementTree.XML(data)
83
if xml.tag == "rsp" and xml.get("stat") == "ok":
85
elif xml.tag == "rsp" and xml.get("stat") == "fail":
87
raise FlickrError(err.get("code"), err.get("msg"))
89
# Fake an error in this case
90
raise FlickrError(0, "Invalid response")
80
92
def __getattr__(self, method):
81
93
method = "flickr." + method.replace("_", ".")
82
94
if not self.__methods.has_key(method):
83
95
def proxy(method=method, **kwargs):
85
self.logger.info("%s returned" % method)
86
xml = ElementTree.XML(data)
87
if xml.tag == "rsp" and xml.get("stat") == "ok":
89
elif xml.tag == "rsp" and xml.get("stat") == "fail":
91
raise FlickrError(err.get("code"), err.get("msg"))
93
# Fake an error in this case
94
raise FlickrError(0, "Invalid response")
95
return self.__call(method, kwargs).addCallback(cb)
96
return self.__call(method, kwargs).addCallback(self.__cb, method)
96
97
self.__methods[method] = proxy
97
98
return self.__methods[method]
153
154
"Content-Type": "multipart/form-data; boundary=%s" % boundary,
154
155
"Content-Length": str(len(form))
158
self.logger.info("Calling upload")
156
159
return client.getPage("http://api.flickr.com/services/upload/", method="POST",
157
headers=headers, postdata=form)
160
headers=headers, postdata=form).addCallback(self.__cb, "upload")
159
162
def authenticate_2(self, state):