Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
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
ops
jumpserver
Commits
49632241
Commit
49632241
authored
May 31, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 导入解析csv coding
parent
b4f23f97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
2 deletions
+4
-2
csv.py
apps/common/parsers/csv.py
+4
-2
No files found.
apps/common/parsers/csv.py
View file @
49632241
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#
#
import
json
import
json
import
chardet
import
unicodecsv
import
unicodecsv
from
rest_framework.parsers
import
BaseParser
from
rest_framework.parsers
import
BaseParser
...
@@ -73,7 +74,6 @@ class JMSCSVParser(BaseParser):
...
@@ -73,7 +74,6 @@ class JMSCSVParser(BaseParser):
def
parse
(
self
,
stream
,
media_type
=
None
,
parser_context
=
None
):
def
parse
(
self
,
stream
,
media_type
=
None
,
parser_context
=
None
):
parser_context
=
parser_context
or
{}
parser_context
=
parser_context
or
{}
encoding
=
parser_context
.
get
(
'encoding'
,
'utf-8'
)
try
:
try
:
serializer
=
parser_context
[
"view"
]
.
get_serializer
()
serializer
=
parser_context
[
"view"
]
.
get_serializer
()
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -82,6 +82,8 @@ class JMSCSVParser(BaseParser):
...
@@ -82,6 +82,8 @@ class JMSCSVParser(BaseParser):
try
:
try
:
stream_data
=
stream
.
read
()
stream_data
=
stream
.
read
()
detect_result
=
chardet
.
detect
(
stream_data
)
encoding
=
detect_result
.
get
(
"encoding"
,
"utf-8"
)
binary
=
self
.
_universal_newlines
(
stream_data
)
binary
=
self
.
_universal_newlines
(
stream_data
)
rows
=
self
.
_gen_rows
(
binary
,
charset
=
encoding
)
rows
=
self
.
_gen_rows
(
binary
,
charset
=
encoding
)
...
@@ -97,5 +99,5 @@ class JMSCSVParser(BaseParser):
...
@@ -97,5 +99,5 @@ class JMSCSVParser(BaseParser):
data
.
append
(
row_data
)
data
.
append
(
row_data
)
return
data
return
data
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
debug
(
e
,
exc_info
=
True
)
logger
.
error
(
e
,
exc_info
=
True
)
raise
ParseError
(
'CSV parse error!'
)
raise
ParseError
(
'CSV parse error!'
)
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