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
76cfd77b
Unverified
Commit
76cfd77b
authored
Oct 20, 2021
by
Yining Li
Committed by
GitHub
Oct 20, 2021
Browse files
Fix config parsing error caused by non-ascii characters (#1410)
* explicitly set encoding as 'utf-8'
parent
ba334b43
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
mmcv/utils/config.py
mmcv/utils/config.py
+5
-4
No files found.
mmcv/utils/config.py
View file @
76cfd77b
...
@@ -121,7 +121,7 @@ class Config:
...
@@ -121,7 +121,7 @@ class Config:
regexp
=
r
'\{\{\s*'
+
str
(
key
)
+
r
'\s*\}\}'
regexp
=
r
'\{\{\s*'
+
str
(
key
)
+
r
'\s*\}\}'
value
=
value
.
replace
(
'
\\
'
,
'/'
)
value
=
value
.
replace
(
'
\\
'
,
'/'
)
config_file
=
re
.
sub
(
regexp
,
value
,
config_file
)
config_file
=
re
.
sub
(
regexp
,
value
,
config_file
)
with
open
(
temp_config_name
,
'w'
)
as
tmp_config_file
:
with
open
(
temp_config_name
,
'w'
,
encoding
=
'utf-8'
)
as
tmp_config_file
:
tmp_config_file
.
write
(
config_file
)
tmp_config_file
.
write
(
config_file
)
@
staticmethod
@
staticmethod
...
@@ -139,7 +139,7 @@ class Config:
...
@@ -139,7 +139,7 @@ class Config:
base_var_dict
[
randstr
]
=
base_var
base_var_dict
[
randstr
]
=
base_var
regexp
=
r
'\{\{\s*'
+
BASE_KEY
+
r
'\.'
+
base_var
+
r
'\s*\}\}'
regexp
=
r
'\{\{\s*'
+
BASE_KEY
+
r
'\.'
+
base_var
+
r
'\s*\}\}'
config_file
=
re
.
sub
(
regexp
,
f
'"
{
randstr
}
"'
,
config_file
)
config_file
=
re
.
sub
(
regexp
,
f
'"
{
randstr
}
"'
,
config_file
)
with
open
(
temp_config_name
,
'w'
)
as
tmp_config_file
:
with
open
(
temp_config_name
,
'w'
,
encoding
=
'utf-8'
)
as
tmp_config_file
:
tmp_config_file
.
write
(
config_file
)
tmp_config_file
.
write
(
config_file
)
return
base_var_dict
return
base_var_dict
...
@@ -353,7 +353,8 @@ class Config:
...
@@ -353,7 +353,8 @@ class Config:
warnings
.
warn
(
warnings
.
warn
(
'Please check "file_format", the file format may be .py'
)
'Please check "file_format", the file format may be .py'
)
with
tempfile
.
NamedTemporaryFile
(
with
tempfile
.
NamedTemporaryFile
(
'w'
,
suffix
=
file_format
,
delete
=
False
)
as
temp_file
:
'w'
,
encoding
=
'utf-8'
,
suffix
=
file_format
,
delete
=
False
)
as
temp_file
:
temp_file
.
write
(
cfg_str
)
temp_file
.
write
(
cfg_str
)
# on windows, previous implementation cause error
# on windows, previous implementation cause error
# see PR 1077 for details
# see PR 1077 for details
...
@@ -536,7 +537,7 @@ class Config:
...
@@ -536,7 +537,7 @@ class Config:
if
file
is
None
:
if
file
is
None
:
return
self
.
pretty_text
return
self
.
pretty_text
else
:
else
:
with
open
(
file
,
'w'
)
as
f
:
with
open
(
file
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
self
.
pretty_text
)
f
.
write
(
self
.
pretty_text
)
else
:
else
:
import
mmcv
import
mmcv
...
...
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