Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
0a8a21cf
Commit
0a8a21cf
authored
Feb 18, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some fixes for Python2.5 compatibility
parent
a534d7d3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
25 deletions
+38
-25
fs/ftpfs.py
+13
-2
fs/memoryfs.py
+1
-1
fs/tests/__init__.py
+14
-9
fs/tests/test_fs.py
+1
-8
fs/tests/test_ftpfs.py
+1
-4
fs/tests/test_remote.py
+6
-0
fs/wrapfs/limitsizefs.py
+2
-1
No files found.
fs/ftpfs.py
View file @
0a8a21cf
...
@@ -12,7 +12,15 @@ import fs
...
@@ -12,7 +12,15 @@ import fs
from
fs.base
import
*
from
fs.base
import
*
from
fs.path
import
pathsplit
from
fs.path
import
pathsplit
from
ftplib
import
FTP
,
_GLOBAL_DEFAULT_TIMEOUT
,
error_perm
,
error_temp
,
error_proto
,
error_reply
from
ftplib
import
FTP
,
error_perm
,
error_temp
,
error_proto
,
error_reply
try
:
from
ftplib
import
_GLOBAL_DEFAULT_TIMEOUT
_FTPLIB_TIMEOUT
=
True
except
ImportError
:
_GLOBAL_DEFAULT_TIMEOUT
=
None
_FTPLIB_TIMEOUT
=
False
import
threading
import
threading
from
time
import
sleep
from
time
import
sleep
import
datetime
import
datetime
...
@@ -882,7 +890,10 @@ class FTPFS(FS):
...
@@ -882,7 +890,10 @@ class FTPFS(FS):
def
_open_ftp
(
self
):
def
_open_ftp
(
self
):
try
:
try
:
ftp
=
FTP
()
ftp
=
FTP
()
ftp
.
connect
(
self
.
host
,
self
.
port
,
self
.
timeout
)
if
_FTPLIB_TIMEOUT
:
ftp
.
connect
(
self
.
host
,
self
.
port
,
self
.
timeout
)
else
:
ftp
.
connect
(
self
.
host
,
self
.
port
)
ftp
.
login
(
self
.
user
,
self
.
passwd
,
self
.
acct
)
ftp
.
login
(
self
.
user
,
self
.
passwd
,
self
.
acct
)
except
socket_error
,
e
:
except
socket_error
,
e
:
raise
RemoteConnectionError
(
str
(
e
),
details
=
e
)
raise
RemoteConnectionError
(
str
(
e
),
details
=
e
)
...
...
fs/memoryfs.py
View file @
0a8a21cf
...
@@ -69,7 +69,7 @@ class MemoryFile(object):
...
@@ -69,7 +69,7 @@ class MemoryFile(object):
__repr__
=
__str__
__repr__
=
__str__
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
u
nicode
(
self
.
__str__
()
)
return
u
"<MemoryFile in
%
s
%
s>"
%
(
self
.
memory_fs
,
self
.
path
)
def
__del__
(
self
):
def
__del__
(
self
):
if
not
self
.
closed
:
if
not
self
.
closed
:
...
...
fs/tests/__init__.py
View file @
0a8a21cf
...
@@ -572,7 +572,7 @@ class ThreadingTestCases:
...
@@ -572,7 +572,7 @@ class ThreadingTestCases:
__lock
=
threading
.
RLock
()
__lock
=
threading
.
RLock
()
def
_yield
(
self
):
def
_yield
(
self
):
time
.
sleep
(
0.01
)
time
.
sleep
(
0.0
0
1
)
def
_lock
(
self
):
def
_lock
(
self
):
self
.
__lock
.
acquire
()
self
.
__lock
.
acquire
()
...
@@ -589,14 +589,19 @@ class ThreadingTestCases:
...
@@ -589,14 +589,19 @@ class ThreadingTestCases:
return
threading
.
Thread
(
target
=
runThread
)
return
threading
.
Thread
(
target
=
runThread
)
def
_runThreads
(
self
,
*
funcs
):
def
_runThreads
(
self
,
*
funcs
):
errors
=
[]
check_interval
=
sys
.
getcheckinterval
()
threads
=
[
self
.
_makeThread
(
f
,
errors
)
for
f
in
funcs
]
sys
.
setcheckinterval
(
1
)
for
t
in
threads
:
try
:
t
.
start
()
errors
=
[]
for
t
in
threads
:
threads
=
[
self
.
_makeThread
(
f
,
errors
)
for
f
in
funcs
]
t
.
join
()
for
t
in
threads
:
for
(
c
,
e
,
t
)
in
errors
:
t
.
start
()
raise
c
,
e
,
t
for
t
in
threads
:
t
.
join
()
for
(
c
,
e
,
t
)
in
errors
:
raise
c
,
e
,
t
finally
:
sys
.
setcheckinterval
(
check_interval
)
def
test_setcontents
(
self
):
def
test_setcontents
(
self
):
def
setcontents
(
name
,
contents
):
def
setcontents
(
name
,
contents
):
...
...
fs/tests/test_fs.py
View file @
0a8a21cf
...
@@ -20,7 +20,6 @@ from fs import osfs
...
@@ -20,7 +20,6 @@ from fs import osfs
class
TestOSFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
class
TestOSFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
def
setUp
(
self
):
def
setUp
(
self
):
sys
.
setcheckinterval
(
1
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"fstest"
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"fstest"
)
self
.
fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
self
.
fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
...
@@ -33,8 +32,7 @@ class TestOSFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
...
@@ -33,8 +32,7 @@ class TestOSFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
class
TestSubFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
class
TestSubFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
def
setUp
(
self
):
def
setUp
(
self
):
sys
.
setcheckinterval
(
1
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"fstest"
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"fstest"
)
self
.
parent_fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
self
.
parent_fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
self
.
parent_fs
.
makedir
(
"foo/bar"
,
recursive
=
True
)
self
.
parent_fs
.
makedir
(
"foo/bar"
,
recursive
=
True
)
...
@@ -53,7 +51,6 @@ from fs import memoryfs
...
@@ -53,7 +51,6 @@ from fs import memoryfs
class
TestMemoryFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
class
TestMemoryFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
def
setUp
(
self
):
def
setUp
(
self
):
sys
.
setcheckinterval
(
1
)
self
.
fs
=
memoryfs
.
MemoryFS
()
self
.
fs
=
memoryfs
.
MemoryFS
()
...
@@ -61,15 +58,11 @@ from fs import mountfs
...
@@ -61,15 +58,11 @@ from fs import mountfs
class
TestMountFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
class
TestMountFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
def
setUp
(
self
):
def
setUp
(
self
):
sys
.
setcheckinterval
(
1
)
self
.
mount_fs
=
mountfs
.
MountFS
()
self
.
mount_fs
=
mountfs
.
MountFS
()
self
.
mem_fs
=
memoryfs
.
MemoryFS
()
self
.
mem_fs
=
memoryfs
.
MemoryFS
()
self
.
mount_fs
.
mountdir
(
"mounted/memfs"
,
self
.
mem_fs
)
self
.
mount_fs
.
mountdir
(
"mounted/memfs"
,
self
.
mem_fs
)
self
.
fs
=
self
.
mount_fs
.
opendir
(
"mounted/memfs"
)
self
.
fs
=
self
.
mount_fs
.
opendir
(
"mounted/memfs"
)
def
tearDown
(
self
):
pass
def
check
(
self
,
p
):
def
check
(
self
,
p
):
return
self
.
mount_fs
.
exists
(
os
.
path
.
join
(
"mounted/memfs"
,
relpath
(
p
)))
return
self
.
mount_fs
.
exists
(
os
.
path
.
join
(
"mounted/memfs"
,
relpath
(
p
)))
...
...
fs/tests/test_ftpfs.py
View file @
0a8a21cf
...
@@ -28,18 +28,15 @@ class TestFTPFS(unittest.TestCase, FSTestCases, ThreadingTestCases):
...
@@ -28,18 +28,15 @@ class TestFTPFS(unittest.TestCase, FSTestCases, ThreadingTestCases):
#ftp_port += 1
#ftp_port += 1
use_port
=
str
(
ftp_port
)
use_port
=
str
(
ftp_port
)
#ftp_port = 10000
#ftp_port = 10000
sys
.
setcheckinterval
(
1
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"ftpfstests"
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
u"ftpfstests"
)
self
.
ftp_server
=
subprocess
.
Popen
([
'python'
,
abspath
(
__file__
),
self
.
temp_dir
,
str
(
use_port
)])
self
.
ftp_server
=
subprocess
.
Popen
([
sys
.
executable
,
abspath
(
__file__
),
self
.
temp_dir
,
str
(
use_port
)])
# Need to sleep to allow ftp server to start
# Need to sleep to allow ftp server to start
time
.
sleep
(
.
2
)
time
.
sleep
(
.
2
)
self
.
fs
=
ftpfs
.
FTPFS
(
'127.0.0.1'
,
'user'
,
'12345'
,
port
=
use_port
,
timeout
=
5.0
)
self
.
fs
=
ftpfs
.
FTPFS
(
'127.0.0.1'
,
'user'
,
'12345'
,
port
=
use_port
,
timeout
=
5.0
)
def
tearDown
(
self
):
def
tearDown
(
self
):
if
sys
.
platform
==
'win32'
:
if
sys
.
platform
==
'win32'
:
import
win32api
import
win32api
win32api
.
TerminateProcess
(
int
(
process
.
_handle
),
-
1
)
win32api
.
TerminateProcess
(
int
(
process
.
_handle
),
-
1
)
...
...
fs/tests/test_remote.py
View file @
0a8a21cf
...
@@ -22,22 +22,26 @@ class TestCacheFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
...
@@ -22,22 +22,26 @@ class TestCacheFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
"""Test simple operation of CacheFS"""
"""Test simple operation of CacheFS"""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_check_interval
=
sys
.
getcheckinterval
()
sys
.
setcheckinterval
(
10
)
sys
.
setcheckinterval
(
10
)
self
.
fs
=
CacheFS
(
TempFS
())
self
.
fs
=
CacheFS
(
TempFS
())
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
fs
.
close
()
self
.
fs
.
close
()
sys
.
setcheckinterval
(
self
.
_check_interval
)
class
TestConnectionManagerFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
class
TestConnectionManagerFS
(
unittest
.
TestCase
,
FSTestCases
,
ThreadingTestCases
):
"""Test simple operation of ConnectionManagerFS"""
"""Test simple operation of ConnectionManagerFS"""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_check_interval
=
sys
.
getcheckinterval
()
sys
.
setcheckinterval
(
10
)
sys
.
setcheckinterval
(
10
)
self
.
fs
=
ConnectionManagerFS
(
TempFS
())
self
.
fs
=
ConnectionManagerFS
(
TempFS
())
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
fs
.
close
()
self
.
fs
.
close
()
sys
.
setcheckinterval
(
self
.
_check_interval
)
class
DisconnectingFS
(
WrapFS
):
class
DisconnectingFS
(
WrapFS
):
...
@@ -108,11 +112,13 @@ class TestConnectionManagerFS_disconnect(TestConnectionManagerFS):
...
@@ -108,11 +112,13 @@ class TestConnectionManagerFS_disconnect(TestConnectionManagerFS):
"""Test ConnectionManagerFS's ability to wait for reconnection."""
"""Test ConnectionManagerFS's ability to wait for reconnection."""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_check_interval
=
sys
.
getcheckinterval
()
sys
.
setcheckinterval
(
10
)
sys
.
setcheckinterval
(
10
)
c_fs
=
ConnectionManagerFS
(
DisconnectingFS
,
poll_interval
=
0.1
)
c_fs
=
ConnectionManagerFS
(
DisconnectingFS
,
poll_interval
=
0.1
)
self
.
fs
=
DisconnectRecoveryFS
(
c_fs
)
self
.
fs
=
DisconnectRecoveryFS
(
c_fs
)
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
fs
.
close
()
self
.
fs
.
close
()
sys
.
setcheckinterval
(
self
.
_check_interval
)
fs/wrapfs/limitsizefs.py
View file @
0a8a21cf
...
@@ -8,7 +8,8 @@ This module provides the class LimitSizeFS, an FS wrapper that can limit the
...
@@ -8,7 +8,8 @@ This module provides the class LimitSizeFS, an FS wrapper that can limit the
total size of files stored in the wrapped FS.
total size of files stored in the wrapped FS.
"""
"""
# for Python2.5 compatibility
from
__future__
import
with_statement
from
fs.errors
import
*
from
fs.errors
import
*
from
fs.base
import
FS
,
threading
,
synchronize
from
fs.base
import
FS
,
threading
,
synchronize
from
fs.wrapfs
import
WrapFS
from
fs.wrapfs
import
WrapFS
...
...
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