Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
EWOK
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lex gaMe
EWOK
Commits
b8a0d209
Commit
b8a0d209
authored
1 year ago
by
Enzo Simonnet
Browse files
Options
Downloads
Patches
Plain Diff
gestion de l'encodage des caractères utf-8 dans l'url des requêtes curl
parent
4abb783c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app.py
+14
-2
14 additions, 2 deletions
src/app.py
with
14 additions
and
2 deletions
src/app.py
+
14
−
2
View file @
b8a0d209
from
flask
import
Flask
,
Response
,
json
,
jsonify
,
request
from
flask_cors
import
CORS
from
urllib.parse
import
unquote
import
requests
# import sys
# import codecs
# sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
import
config
from
wiktextract_wrapper
import
Wiktextract
...
...
@@ -28,6 +34,9 @@ def index():
@app.route
(
"
/simplesearch/<lang>/<word>
"
,
methods
=
[
"
GET
"
])
def
search
(
lang
,
word
):
word
=
requests
.
utils
.
unquote
(
word
)
word
=
word
.
encode
(
'
latin-1
'
).
decode
(
'
utf-8
'
)
# Decode the word from Latin-1 to UTF-8
# print(word)
if
lang
not
in
config
.
supported_wiktlangs
:
return
jsonify
({
"
error
"
:
f
"
Language
{
lang
}
not supported
"
}),
400
...
...
@@ -55,8 +64,11 @@ def search(lang, word):
if
wiktextractor
.
wxr
.
thesaurus_db_conn
:
wiktextractor
.
wxr
.
thesaurus_db_conn
.
close
()
@app.route
(
"
/search/<wiktlang>/<wordlang>/<word>/<format>
"
,
methods
=
[
"
GET
"
])
@app.route
(
"
/search/<wiktlang>/<wordlang>/<
path:
word>/<format>
"
,
methods
=
[
"
GET
"
])
def
search_and_format
(
wiktlang
,
wordlang
,
word
,
format
):
word
=
requests
.
utils
.
unquote
(
word
)
word
=
word
.
encode
(
'
latin-1
'
).
decode
(
'
utf-8
'
)
# Decode the word from Latin-1 to UTF-8
# print(word)
# app.logger.info('Received a request from /search/<wiktlang>/<wordlang>/<word>/<format>')
if
wiktlang
not
in
config
.
supported_wiktlangs
:
return
jsonify
({
"
error
"
:
f
"
Language
{
wiktlang
}
not supported
"
}),
400
...
...
@@ -64,7 +76,7 @@ def search_and_format(wiktlang, wordlang, word, format):
if
len
(
format
)
>
2
and
format
[
0
:
2
]
in
(
"
a_
"
,
"
A_
"
):
ascii
=
True
format
=
format
[
2
:]
print
(
ascii
,
format
)
#
print(ascii, format)
else
:
ascii
=
False
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment