Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
e39c2d2e
Commit
e39c2d2e
authored
Sep 13, 2009
by
Josh Roesslein
Browse files
Made file locking more portable for FileCache.
parent
40e82fdb
Changes
5
Hide whitespace changes
Inline
Side-by-side
CHANGES
View file @
e39c2d2e
...
...
@@ -23,5 +23,6 @@ during upgrade will be listed here.
when user is not followed.
+ python 2.5 import syntax error fixed
+ python 2.5 timeout support for streaming API
+ win32 failed import of fcntl in cache.py
+ Changed indents from 2 to 4 spaces
ROADMAP
View file @
e39c2d2e
...
...
@@ -5,8 +5,7 @@ The plan of attack for the next version of Tweepy.
+ 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...
=========
...
...
@@ -17,3 +16,5 @@ Future...
+ async requests
+ prepare for social graph changes mentioned on mailinglist
+ twitterfall reply API integration?
+ implement win32 file locking for FileCache
tests.py
View file @
e39c2d2e
...
...
@@ -11,8 +11,8 @@ from tweepy import *
"""Configurations"""
# Must supply twitter account credentials for tests
username
=
'
tweebly
'
password
=
'
josh1987twitter
'
username
=
''
password
=
''
"""Unit tests"""
...
...
tweepy/binder.py
View file @
e39c2d2e
...
...
@@ -104,7 +104,11 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
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
...
...
tweepy/cache.py
View file @
e39c2d2e
...
...
@@ -11,6 +11,13 @@ import hashlib
import
fcntl
import
cPickle
as
pickle
try
:
import
fcntl
except
ImportError
:
# Probably on a windows system
# TODO: use win32file
pass
from
.
import
memcache
...
...
@@ -127,12 +134,29 @@ class FileCache(Cache):
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'
)
...
...
@@ -145,6 +169,17 @@ class FileCache(Cache):
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'
)
...
...
@@ -161,7 +196,7 @@ class FileCache(Cache):
# 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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment