Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
54b06570
Commit
54b06570
authored
Nov 05, 2013
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Py26 compat for 'with gzip.open'.
parent
cb450885
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
src/ZODB/scripts/repozo.py
src/ZODB/scripts/repozo.py
+13
-1
src/ZODB/scripts/tests/test_repozo.py
src/ZODB/scripts/tests/test_repozo.py
+3
-13
No files found.
src/ZODB/scripts/repozo.py
View file @
54b06570
...
@@ -109,6 +109,18 @@ class NoFiles(Exception):
...
@@ -109,6 +109,18 @@ class NoFiles(Exception):
pass
pass
class
_GzipCloser
(
object
):
def
__init__
(
self
,
fqn
,
mode
):
self
.
_opened
=
gzip
.
open
(
fqn
,
mode
)
def
__enter__
(
self
):
return
self
.
_opened
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
_opened
.
close
()
def
usage
(
code
,
msg
=
''
):
def
usage
(
code
,
msg
=
''
):
outfp
=
sys
.
stderr
outfp
=
sys
.
stderr
if
code
==
0
:
if
code
==
0
:
...
@@ -690,7 +702,7 @@ def do_verify(options):
...
@@ -690,7 +702,7 @@ def do_verify(options):
def
get_checksum_and_size_of_gzipped_file
(
filename
,
quick
):
def
get_checksum_and_size_of_gzipped_file
(
filename
,
quick
):
with
gzip
.
open
(
filename
,
'rb'
)
as
fp
:
with
_GzipCloser
(
filename
,
'rb'
)
as
fp
:
if
quick
:
if
quick
:
return
None
,
file_size
(
fp
)
return
None
,
file_size
(
fp
)
else
:
else
:
...
...
src/ZODB/scripts/tests/test_repozo.py
View file @
54b06570
...
@@ -26,19 +26,6 @@ except ImportError:
...
@@ -26,19 +26,6 @@ except ImportError:
_NOISY
=
os
.
environ
.
get
(
'NOISY_REPOZO_TEST_OUTPUT'
)
_NOISY
=
os
.
environ
.
get
(
'NOISY_REPOZO_TEST_OUTPUT'
)
class
_GzipCloser
(
object
):
def
__init__
(
self
,
fqn
,
mode
):
import
gzip
self
.
_opened
=
gzip
.
open
(
fqn
,
mode
)
def
__enter__
(
self
):
return
self
.
_opened
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
_opened
.
close
()
def
_write_file
(
name
,
bits
,
mode
=
'wb'
):
def
_write_file
(
name
,
bits
,
mode
=
'wb'
):
with
open
(
name
,
mode
)
as
f
:
with
open
(
name
,
mode
)
as
f
:
f
.
write
(
bits
)
f
.
write
(
bits
)
...
@@ -218,6 +205,7 @@ class Test_copyfile(OptionsTestBase, unittest.TestCase):
...
@@ -218,6 +205,7 @@ class Test_copyfile(OptionsTestBase, unittest.TestCase):
self
.
assertEqual
(
_read_file
(
target
),
b'x'
*
100
)
self
.
assertEqual
(
_read_file
(
target
),
b'x'
*
100
)
def
test_w_gzip
(
self
):
def
test_w_gzip
(
self
):
from
ZODB.scripts.repozo
import
_GzipCloser
options
=
self
.
_makeOptions
(
gzip
=
True
)
options
=
self
.
_makeOptions
(
gzip
=
True
)
source
=
options
.
file
=
os
.
path
.
join
(
self
.
_repository_directory
,
source
=
options
.
file
=
os
.
path
.
join
(
self
.
_repository_directory
,
'source.txt'
)
'source.txt'
)
...
@@ -236,6 +224,7 @@ class Test_concat(OptionsTestBase, unittest.TestCase):
...
@@ -236,6 +224,7 @@ class Test_concat(OptionsTestBase, unittest.TestCase):
return
concat
(
files
,
ofp
)
return
concat
(
files
,
ofp
)
def
_makeFile
(
self
,
name
,
text
,
gzip_file
=
False
):
def
_makeFile
(
self
,
name
,
text
,
gzip_file
=
False
):
from
ZODB.scripts.repozo
import
_GzipCloser
import
tempfile
import
tempfile
if
self
.
_repository_directory
is
None
:
if
self
.
_repository_directory
is
None
:
self
.
_repository_directory
=
tempfile
.
mkdtemp
()
self
.
_repository_directory
=
tempfile
.
mkdtemp
()
...
@@ -802,6 +791,7 @@ class Test_do_verify(OptionsTestBase, unittest.TestCase):
...
@@ -802,6 +791,7 @@ class Test_do_verify(OptionsTestBase, unittest.TestCase):
repozo
.
error
=
orig_error
repozo
.
error
=
orig_error
def
_makeFile
(
self
,
hour
,
min
,
sec
,
ext
,
text
=
None
):
def
_makeFile
(
self
,
hour
,
min
,
sec
,
ext
,
text
=
None
):
from
ZODB.scripts.repozo
import
_GzipCloser
assert
self
.
_repository_directory
,
'call _makeOptions first!'
assert
self
.
_repository_directory
,
'call _makeOptions first!'
name
=
'2010-05-14-%02d-%02d-%02d%s'
%
(
hour
,
min
,
sec
,
ext
)
name
=
'2010-05-14-%02d-%02d-%02d%s'
%
(
hour
,
min
,
sec
,
ext
)
if
text
is
None
:
if
text
is
None
:
...
...
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