+ changing profile and background images [DONE]
+ finish search api [DONE]
+ autodetect authenticated user's ID [DONE]
-+ make oauth handler more web app friendly
-+ address file locking portability issues in file cache
++ address file locking portability issues in file cache [DONE]
Future...
=========
+ async requests
+ prepare for social graph changes mentioned on mailinglist
+ twitterfall reply API integration?
++ implement win32 file locking for FileCache
+
raise TweepError(error_msg)
# Pass returned body into parser and return parser output
- out = parser(resp.read(), api)
+ try:
+ out = parser(resp.read(), api)
+ except Exception:
+ raise TweepError("Failed to parse returned data")
+
conn.close()
# validate result
import fcntl
import cPickle as pickle
+try:
+ import fcntl
+except ImportError:
+ # Probably on a windows system
+ # TODO: use win32file
+ pass
+
from . import memcache
self.lock = threading.Lock()
FileCache.cache_locks[cache_dir] = self.lock
+ if os.name == 'posix':
+ self._lock_file = self._lock_file_posix
+ self._unlock_file = self._unlock_file_posix
+ elif os.name == 'nt':
+ self._lock_file = self._lock_file_win32
+ self._unlock_file = self._unlock_file_win32
+ else:
+ print 'Warning! FileCache locking not supported on this system!'
+ self._lock_file = self._lock_file_dummy
+ self._unlock_file = self._unlock_file_dummy
+
def _get_path(self, key):
md5 = hashlib.md5()
md5.update(key)
return os.path.join(self.cache_dir, md5.hexdigest())
- def _lock_file(self, path, exclusive=True):
+ def _lock_file_dummy(self, path, exclusive=True):
+ return None
+
+ def _unlock_file_dummy(self, lock):
+ return
+
+ def _lock_file_posix(self, path, exclusive=True):
lock_path = path + '.lock'
if exclusive is True:
f_lock = open(lock_path, 'w')
return None
return f_lock
+ def _unlock_file_posix(self, lock):
+ lock.close()
+
+ def _lock_file_win32(self, path, exclusive=True):
+ # TODO: implement
+ return None
+
+ def _unlock_file_win32(self, lock):
+ # TODO: implement
+ return
+
def _delete_file(self, path):
os.remove(path)
os.remove(path + '.lock')
# close and unlock file
datafile.close()
- f_lock.close()
+ self._unlock_file(f_lock)
def get(self, key, timeout=None):
return self._get(self._get_path(key), timeout)