bug appel process_file

This commit is contained in:
2024-02-14 18:30:40 +01:00
parent 2bf85c52cd
commit e72eb492b3
2 changed files with 94 additions and 3 deletions

View File

@@ -49,13 +49,14 @@ def process_file(request, input_file, input_name):
temp_folder = request.registry.settings['temp_folder'] temp_folder = request.registry.settings['temp_folder']
logfile_name = os.path.join(temp_folder, 'errors_log') logfile_name = os.path.join(temp_folder, 'errors_log')
input_encoding = 'utf-8' input_encoding = 'utf-8'
output_name = ''
# --- check the mime type # --- check the mime type
mime = magic.from_buffer(input_file.read(), mime=True) mime = magic.from_buffer(input_file.read(), mime=True)
if mime not in EXT_ALLOWED: if mime not in EXT_ALLOWED:
message = "Le format du fichier n'est pas valide. Téléchargement refusé." message = "Le format du fichier n'est pas valide. Téléchargement refusé."
add_error2log(logfile_name, input_name, message) add_error2log(logfile_name, input_name, message)
return message, input_encoding return message, input_encoding, output_name
# get input_file size # get input_file size
input_file.seek(0, 2) #seek to end input_file.seek(0, 2) #seek to end
@@ -65,7 +66,7 @@ def process_file(request, input_file, input_name):
if filesize > MAX_SIZE: if filesize > MAX_SIZE:
message = "La taille du fichier dépasse la limite autorisée. Téléchargement refusé." message = "La taille du fichier dépasse la limite autorisée. Téléchargement refusé."
add_error2log(logfile_name, input_name, message) add_error2log(logfile_name, input_name, message)
return message, input_encoding return message, input_encoding, output_name
# Finally write the data to a temporary file # Finally write the data to a temporary file
input_filename = os.path.join(temp_folder, input_name) input_filename = os.path.join(temp_folder, input_name)
@@ -90,7 +91,7 @@ def process_file(request, input_file, input_name):
if input_buffer.find('<body') == -1 or input_buffer.find('</body>') == -1: if input_buffer.find('<body') == -1 or input_buffer.find('</body>') == -1:
message = "Le format du fichier n'est pas valide (absence de tag <body> ou </body>). Téléchargement refusé." message = "Le format du fichier n'est pas valide (absence de tag <body> ou </body>). Téléchargement refusé."
add_error2log(logfile_name, input_name, message) add_error2log(logfile_name, input_name, message)
return message, input_encoding return message, input_encoding, output_name
# --- convert input_file encoding to utf-8 # --- convert input_file encoding to utf-8
with open(input_filename, 'w', encoding='utf-8') as f: with open(input_filename, 'w', encoding='utf-8') as f:

90
tests/test file .html Normal file
View File

@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<meta name="generator" content="LibreOffice 7.5.8.2 (Windows)"/>
<meta name="author" content="GIAO NGUYEN NGOC"/>
<meta name="created" content="2024-02-05T16:22:00"/>
<meta name="changedby" content="GIAO NGUYEN NGOC"/>
<meta name="changed" content="2024-02-05T16:28:00"/>
<meta name="AppVersion" content="14.0000"/>
<style type="text/css">
@page { size: 21cm 29.7cm; margin: 2.5cm }
p { line-height: 115%; text-align: left; orphans: 2; widows: 2; margin-bottom: 0.25cm; direction: ltr; background: transparent }
</style>
</head>
<body lang="fr-FR" link="#000080" vlink="#800000" dir="ltr"><p style="line-height: 100%; margin-bottom: 0.49cm">
<font face="Times, serif"><font size="4" style="font-size: 16pt">
Thiện </font></font>
</p>
<p style="line-height: 100%; margin-top: 0.49cm; margin-bottom: 0.49cm">
&nbsp;</p>
<p style="line-height: 100%; margin-top: 0.49cm; margin-bottom: 0.49cm">
<font face="Times, serif"><font size="4" style="font-size: 16pt">1993,
ở mãi tận Dole, sinh quán của nhà khoa học Louis Pasteur,
vùng Jura cách «&nbsp;kinh đô ánh sáng&nbsp;» đến 360 km,
bố tôi bảo «&nbsp;Cô chú Giao là khách Paris xuống
chơi&nbsp;nhà&nbsp;». Rồi chỉ một vài lần cô chú ghé
nhà khi thì nghỉ lại một đêm lúc thì dùng cơm với gia
đình rồi lại lên đường đi tiếp sang Thụy Sĩ hay
xuống miền Nam, hai vị «&nbsp;khách Paris&nbsp;» ấy đã
trở thành «&nbsp;Chú Giao, Cô Thiện&nbsp;». </font></font>
</p>
<p style="line-height: 100%; margin-top: 0.49cm; margin-bottom: 0.49cm">
<font face="Times, serif"><font size="4" style="font-size: 16pt">Năm
1996 </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>
Thiện</i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">
đưa tôi vào RFI làm việc, kiếm thêm tiền để đi học.
Tôi vẫn thản nhiên với cách xưng hô như ở nhà và gọi
bà phó ban tập Đài Phát Thanh Quốc Tế Pháp là </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>
Thiện</i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">.
Ba năm sau cô nhất quyết đóng vai trò «&nbsp;bà mai&nbsp;»
giới thiệu cho tôi một tấm chồng. Về làm dâu, đúng
theo vai vế họ hàng, tôi phải gọi cô «&nbsp;là bà trẻ&nbsp;»
vì cô là vai cô của mẹ chồng. Nhưng tôi vẫn giữ
nguyên hai chữ </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>
Thiện. </i></font></font>
</p>
<p style="line-height: 100%; margin-top: 0.49cm; margin-bottom: 0.49cm">
<font face="Times, serif"><font size="4" style="font-size: 16pt">
về hưu, hai cô cháu vẫn «&nbsp;hẹn hò&nbsp;» một năm
ba bốn lần. Khi thì đi vào viện bảo tàng xem triển lãm,
hay đi xem phim ; lúc thì đi ăn hay uống cà phê trên
Boulevard Saint Germain. Cô cháu chúng tôi có nhiều chuyện
để nói với nhau lắm. Chuyện mình, chuyện xã hội,
chuyện xưa, chuyện nay … </font></font>
</p>
<p style="line-height: 100%; margin-bottom: 0cm"><font face="Times, serif"><font size="4" style="font-size: 16pt">Giữa
hai cô cháu là cả một chân tình. Tiếng Pháp có một chữ
mà tôi rất trân trọng là «&nbsp;Tình Bạn-Amitié&nbsp;».
Trong tiếng Việt tôi không được phép dùng chữ ấy vì
nói như thế là hỗn&nbsp;: </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i></i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">
là bề trên, là bạn của bố mẹ, là cấp trên trong công
việc, là vai bà trẻ. Ngày 04/02/2024, sau 8 giờ tôi, hay
tin </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>
Thiện</i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">
mất, gọi thế nào liên hệ giữa hai cô cháu chúng tôi
không còn quan trọng nữa. </font></font>
</p>
<p style="line-height: 100%; margin-top: 0.49cm; margin-bottom: 0.49cm">
<font face="Times, serif"><font size="4" style="font-size: 16pt">Không
còn quan trọng vì tôi vừa mất một người đã mang lại
cho tôi rất, rất nhiều. Mất một người mà tôi rất,
rất quý. Mất một người mà lại cũng tiếng Việt,
không cho phép tôi gọi là Mẹ, nhưng </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>Tình</i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">
của </font></font><font face="Times, serif"><font size="4" style="font-size: 16pt"><i>
Thiện</i></font></font><font face="Times, serif"><font size="4" style="font-size: 16pt">
cho tôi nhiều và đẹp hơn tất cả những gì mà cái vốn
liếng tiếng Việt của tôi cho phép viết ra. Nhưng có lẽ
không cách xưng hô nào thân mật và ý nghĩa hơn là hai
chữ «&nbsp;Cô Thiện&nbsp;». &nbsp;</font></font></p>
<p style="line-height: 100%; margin-bottom: 0cm"><a name="_GoBack"></a>
<font face="Times, serif"><font size="4" style="font-size: 16pt">Thanh
</font></font></p>
<p style="line-height: 100%; margin-bottom: 0.35cm"><br/>
<br/>
</p>
</body>
</html>