/usr/lib/python2.7/dist-packages/flickrapi/contrib.py is in python-flickrapi 2.1.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """Contributed FlickrAPI extensions.
These FlickrAPI extensions have been contributed by other developers. They may
not be as thoroughly tested as the core Python FlickrAPI modules.
"""
import logging
import threading
import six
http_client = six.moves.http_client
from flickrapi import core
LOG = logging.getLogger(__name__)
class PersistentFlickrAPI(core.FlickrAPI):
"""FlickrAPI that uses persistent HTTP connections via httplib.
The HTTP connection is persisted in a thread-local way.
Note that it may be possible that the connection was closed for some
reason, in which case a Flickr call will fail. The next call will try to
re-establish the connection. Re-trying the call in such a case is the
responsibility of the caller.
"""
def __init__(self, *args, **kwargs):
core.FlickrAPI.__init__(self, *args, **kwargs)
# Thread-local HTTPConnection, see _http_post
self.thr = threading.local()
def _http_post(self, post_data):
"""Performs a HTTP POST call to the Flickr REST URL.
Raises a httplib.ImproperConnectionState exception when the connection
was closed unexpectedly.
"""
# Thread-local persistent connection
try:
if 'conn' not in self.thr.__dict__:
self.thr.conn = http_client.HTTPConnection(self.flickr_host)
LOG.info("connection opened to %s" % self.flickr_host, 3)
self.thr.conn.request("POST", self.flickr_rest_form, post_data,
{"Content-Type": "application/x-www-form-urlencoded"})
reply = self.thr.conn.getresponse().read()
except http_client.ImproperConnectionState as e:
LOG.error("connection error: %s" % e, 3)
self.thr.conn.close()
del self.thr.conn
raise
return reply
|