Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
75ee2531
Commit
75ee2531
authored
Sep 21, 2018
by
Kai Chen
Browse files
rename *Processor to *Handler and fix bug for python 2
parent
31e684fc
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
42 additions
and
36 deletions
+42
-36
mmcv/fileio/__init__.py
mmcv/fileio/__init__.py
+8
-3
mmcv/fileio/handlers/__init__.py
mmcv/fileio/handlers/__init__.py
+6
-0
mmcv/fileio/handlers/base.py
mmcv/fileio/handlers/base.py
+1
-1
mmcv/fileio/handlers/json_handler.py
mmcv/fileio/handlers/json_handler.py
+2
-2
mmcv/fileio/handlers/pickle_handler.py
mmcv/fileio/handlers/pickle_handler.py
+2
-3
mmcv/fileio/handlers/yaml_handler.py
mmcv/fileio/handlers/yaml_handler.py
+2
-2
mmcv/fileio/io.py
mmcv/fileio/io.py
+17
-17
mmcv/fileio/processors/__init__.py
mmcv/fileio/processors/__init__.py
+0
-4
tests/test_fileio.py
tests/test_fileio.py
+4
-4
No files found.
mmcv/fileio/__init__.py
View file @
75ee2531
from
.io
import
*
from
.io
import
load
,
dump
from
.processors
import
*
from
.handlers
import
BaseFileHandler
,
JsonHandler
,
PickleHandler
,
YamlHandler
from
.parse
import
*
from
.parse
import
list_from_file
,
dict_from_file
__all__
=
[
'load'
,
'dump'
,
'BaseFileHandler'
,
'JsonHandler'
,
'PickleHandler'
,
'YamlHandler'
,
'list_from_file'
,
'dict_from_file'
]
mmcv/fileio/handlers/__init__.py
0 → 100644
View file @
75ee2531
from
.base
import
BaseFileHandler
from
.json_handler
import
JsonHandler
from
.pickle_handler
import
PickleHandler
from
.yaml_handler
import
YamlHandler
__all__
=
[
'BaseFileHandler'
,
'JsonHandler'
,
'PickleHandler'
,
'YamlHandler'
]
mmcv/fileio/
processo
rs/base.py
→
mmcv/fileio/
handle
rs/base.py
View file @
75ee2531
from
abc
import
ABCMeta
,
abstractmethod
from
abc
import
ABCMeta
,
abstractmethod
class
BaseFile
Processo
r
(
object
):
class
BaseFile
Handle
r
(
object
):
__metaclass__
=
ABCMeta
__metaclass__
=
ABCMeta
...
...
mmcv/fileio/
processors/json
.py
→
mmcv/fileio/
handlers/json_handler
.py
View file @
75ee2531
import
json
import
json
from
.base
import
BaseFile
Processo
r
from
.base
import
BaseFile
Handle
r
class
Json
Processo
r
(
BaseFile
Processo
r
):
class
Json
Handle
r
(
BaseFile
Handle
r
):
@
staticmethod
@
staticmethod
def
load_from_path
(
filepath
):
def
load_from_path
(
filepath
):
...
...
mmcv/fileio/
processo
rs/pickle.py
→
mmcv/fileio/
handle
rs/pickle
_handler
.py
View file @
75ee2531
from
six.moves
import
cPickle
as
pickle
from
six.moves
import
cPickle
as
pickle
from
.base
import
BaseFile
Processo
r
from
.base
import
BaseFile
Handle
r
class
Pickle
Processo
r
(
BaseFile
Processo
r
):
class
Pickle
Handle
r
(
BaseFile
Handle
r
):
@
staticmethod
@
staticmethod
def
load_from_path
(
filepath
,
**
kwargs
):
def
load_from_path
(
filepath
,
**
kwargs
):
...
@@ -30,4 +30,3 @@ class PickleProcessor(BaseFileProcessor):
...
@@ -30,4 +30,3 @@ class PickleProcessor(BaseFileProcessor):
def
dump_to_fileobj
(
obj
,
file
,
**
kwargs
):
def
dump_to_fileobj
(
obj
,
file
,
**
kwargs
):
kwargs
.
setdefault
(
'protocol'
,
2
)
kwargs
.
setdefault
(
'protocol'
,
2
)
pickle
.
dump
(
obj
,
file
,
**
kwargs
)
pickle
.
dump
(
obj
,
file
,
**
kwargs
)
\ No newline at end of file
mmcv/fileio/
processors/yaml
.py
→
mmcv/fileio/
handlers/yaml_handler
.py
View file @
75ee2531
...
@@ -4,10 +4,10 @@ try:
...
@@ -4,10 +4,10 @@ try:
except
ImportError
:
except
ImportError
:
from
yaml
import
Loader
,
Dumper
from
yaml
import
Loader
,
Dumper
from
.base
import
BaseFile
Processo
r
from
.base
import
BaseFile
Handle
r
class
Yaml
Processo
r
(
BaseFile
Processo
r
):
class
Yaml
Handle
r
(
BaseFile
Handle
r
):
@
staticmethod
@
staticmethod
def
load_from_path
(
filepath
,
**
kwargs
):
def
load_from_path
(
filepath
,
**
kwargs
):
...
...
mmcv/fileio/io.py
View file @
75ee2531
from
.
processo
rs
import
Json
Processo
r
,
Pickle
Processor
,
YamlProcesso
r
from
.
handle
rs
import
Json
Handle
r
,
Pickle
Handler
,
YamlHandle
r
from
..utils
import
is_str
from
..utils
import
is_str
file_
processo
rs
=
{
file_
handle
rs
=
{
'json'
:
Json
Processo
r
,
'json'
:
Json
Handle
r
,
'yaml'
:
Yaml
Processo
r
,
'yaml'
:
Yaml
Handle
r
,
'yml'
:
Yaml
Processo
r
,
'yml'
:
Yaml
Handle
r
,
'pickle'
:
Pickle
Processo
r
,
'pickle'
:
Pickle
Handle
r
,
'pkl'
:
Pickle
Processo
r
'pkl'
:
Pickle
Handle
r
}
}
...
@@ -27,14 +27,14 @@ def load(file, file_format=None, **kwargs):
...
@@ -27,14 +27,14 @@ def load(file, file_format=None, **kwargs):
"""
"""
if
file_format
is
None
and
is_str
(
file
):
if
file_format
is
None
and
is_str
(
file
):
file_format
=
file
.
split
(
'.'
)[
-
1
]
file_format
=
file
.
split
(
'.'
)[
-
1
]
if
file_format
not
in
file_
processo
rs
:
if
file_format
not
in
file_
handle
rs
:
raise
TypeError
(
'Unsupported format: {}'
.
format
(
file_format
))
raise
TypeError
(
'Unsupported format: {}'
.
format
(
file_format
))
processo
r
=
file_
processo
rs
[
file_format
]
handle
r
=
file_
handle
rs
[
file_format
]
if
is_str
(
file
):
if
is_str
(
file
):
obj
=
processo
r
.
load_from_path
(
file
,
**
kwargs
)
obj
=
handle
r
.
load_from_path
(
file
,
**
kwargs
)
elif
hasattr
(
file
,
'read'
):
elif
hasattr
(
file
,
'read'
):
obj
=
processo
r
.
load_from_fileobj
(
file
,
**
kwargs
)
obj
=
handle
r
.
load_from_fileobj
(
file
,
**
kwargs
)
else
:
else
:
raise
TypeError
(
'"file" must be a filepath str or a file-object'
)
raise
TypeError
(
'"file" must be a filepath str or a file-object'
)
return
obj
return
obj
...
@@ -54,7 +54,7 @@ def dump(obj, file=None, file_format=None, **kwargs):
...
@@ -54,7 +54,7 @@ def dump(obj, file=None, file_format=None, **kwargs):
file_format (str, optional): Same as :func:`load`.
file_format (str, optional): Same as :func:`load`.
Returns:
Returns:
bool: True for success, False otherwise
bool: True for success, False otherwise
.
"""
"""
if
file_format
is
None
:
if
file_format
is
None
:
if
is_str
(
file
):
if
is_str
(
file
):
...
@@ -62,15 +62,15 @@ def dump(obj, file=None, file_format=None, **kwargs):
...
@@ -62,15 +62,15 @@ def dump(obj, file=None, file_format=None, **kwargs):
elif
file
is
None
:
elif
file
is
None
:
raise
ValueError
(
raise
ValueError
(
'file_format must be specified since file is None'
)
'file_format must be specified since file is None'
)
if
file_format
not
in
file_
processo
rs
:
if
file_format
not
in
file_
handle
rs
:
raise
TypeError
(
'Unsupported format: {}'
.
format
(
file_format
))
raise
TypeError
(
'Unsupported format: {}'
.
format
(
file_format
))
processo
r
=
file_
processo
rs
[
file_format
]
handle
r
=
file_
handle
rs
[
file_format
]
if
file
is
None
:
if
file
is
None
:
return
processo
r
.
dump_to_str
(
obj
,
**
kwargs
)
return
handle
r
.
dump_to_str
(
obj
,
**
kwargs
)
elif
is_str
(
file
):
elif
is_str
(
file
):
processo
r
.
dump_to_path
(
obj
,
file
,
**
kwargs
)
handle
r
.
dump_to_path
(
obj
,
file
,
**
kwargs
)
elif
hasattr
(
file
,
'write'
):
elif
hasattr
(
file
,
'write'
):
processo
r
.
dump_to_fileobj
(
obj
,
file
,
**
kwargs
)
handle
r
.
dump_to_fileobj
(
obj
,
file
,
**
kwargs
)
else
:
else
:
raise
TypeError
(
'"file" must be a filename str or a file-object'
)
raise
TypeError
(
'"file" must be a filename str or a file-object'
)
mmcv/fileio/processors/__init__.py
deleted
100644 → 0
View file @
31e684fc
from
.base
import
BaseFileProcessor
from
.json
import
JsonProcessor
from
.pickle
import
PickleProcessor
from
.yaml
import
YamlProcessor
tests/test_fileio.py
View file @
75ee2531
...
@@ -6,7 +6,7 @@ import mmcv
...
@@ -6,7 +6,7 @@ import mmcv
import
pytest
import
pytest
def
_test_
processo
r
(
file_format
,
test_obj
,
str_checker
,
mode
=
'r+'
):
def
_test_
handle
r
(
file_format
,
test_obj
,
str_checker
,
mode
=
'r+'
):
# dump to a string
# dump to a string
dump_str
=
mmcv
.
dump
(
test_obj
,
file_format
=
file_format
)
dump_str
=
mmcv
.
dump
(
test_obj
,
file_format
=
file_format
)
str_checker
(
dump_str
)
str_checker
(
dump_str
)
...
@@ -49,7 +49,7 @@ def test_json():
...
@@ -49,7 +49,7 @@ def test_json():
'[{"a": "abc", "b": 1}, 2, "c"]'
,
'[{"b": 1, "a": "abc"}, 2, "c"]'
'[{"a": "abc", "b": 1}, 2, "c"]'
,
'[{"b": 1, "a": "abc"}, 2, "c"]'
]
]
_test_
processo
r
(
'json'
,
obj_for_test
,
json_checker
)
_test_
handle
r
(
'json'
,
obj_for_test
,
json_checker
)
def
test_yaml
():
def
test_yaml
():
...
@@ -59,7 +59,7 @@ def test_yaml():
...
@@ -59,7 +59,7 @@ def test_yaml():
'- {a: abc, b: 1}
\n
- 2
\n
- c
\n
'
,
'- {b: 1, a: abc}
\n
- 2
\n
- c
\n
'
'- {a: abc, b: 1}
\n
- 2
\n
- c
\n
'
,
'- {b: 1, a: abc}
\n
- 2
\n
- c
\n
'
]
]
_test_
processo
r
(
'yaml'
,
obj_for_test
,
yaml_checker
)
_test_
handle
r
(
'yaml'
,
obj_for_test
,
yaml_checker
)
def
test_pickle
():
def
test_pickle
():
...
@@ -68,7 +68,7 @@ def test_pickle():
...
@@ -68,7 +68,7 @@ def test_pickle():
import
pickle
import
pickle
assert
pickle
.
loads
(
dump_str
)
==
obj_for_test
assert
pickle
.
loads
(
dump_str
)
==
obj_for_test
_test_
processo
r
(
'pickle'
,
obj_for_test
,
pickle_checker
,
mode
=
'rb+'
)
_test_
handle
r
(
'pickle'
,
obj_for_test
,
pickle_checker
,
mode
=
'rb+'
)
def
test_exception
():
def
test_exception
():
...
...
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