~ubuntu-branches/ubuntu/karmic/postr/karmic

« back to all changes in this revision

Viewing changes to src/flickrest.py

  • Committer: Bazaar Package Importer
  • Author(s): Ross Burton
  • Date: 2007-06-05 19:49:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070605194947-xkgwi0dsqiukezmd
Tags: 0.6-1
* New upstream release
  - Fixed IPTC parsing (Closes: #419964)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# Copyright (C) 2007 Ross Burton <ross@burtonini.com>
4
4
#
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.
8
8
#
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
12
12
# details.
13
13
#
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))
79
79
    
 
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":
 
84
            return xml
 
85
        elif xml.tag == "rsp" and xml.get("stat") == "fail":
 
86
            err = xml.find("err")
 
87
            raise FlickrError(err.get("code"), err.get("msg"))
 
88
        else:
 
89
            # Fake an error in this case
 
90
            raise FlickrError(0, "Invalid response")
 
91
    
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):
84
 
                def cb(data):
85
 
                    self.logger.info("%s returned" % method)
86
 
                    xml = ElementTree.XML(data)
87
 
                    if xml.tag == "rsp" and xml.get("stat") == "ok":
88
 
                        return xml
89
 
                    elif xml.tag == "rsp" and xml.get("stat") == "fail":
90
 
                        err = xml.find("err")
91
 
                        raise FlickrError(err.get("code"), err.get("msg"))
92
 
                    else:
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]
98
99
 
153
154
            "Content-Type": "multipart/form-data; boundary=%s" % boundary,
154
155
            "Content-Length": str(len(form))
155
156
            }
 
157
 
 
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")
158
161
 
159
162
    def authenticate_2(self, state):
160
163
        def gotToken(e):