fix: fail-safe imports for docx/pdfplumber, threaded Flask
Deploy contracts-flask / validate (push) Successful in 0s

This commit is contained in:
2026-06-29 15:44:34 +04:00
parent 425fd50b0d
commit a05e1f4893
3 changed files with 21 additions and 5 deletions
+10 -2
View File
@@ -283,7 +283,11 @@ class TwoPassObfuscator:
ext = os.path.splitext(fname)[1].lower() ext = os.path.splitext(fname)[1].lower()
if ext == '.docx': if ext == '.docx':
from docx import Document try:
from docx import Document
except ImportError:
text = content.decode('utf-8', errors='replace')
return text, None
doc = Document(io.BytesIO(content)) doc = Document(io.BytesIO(content))
text = "\n".join(p.text for p in doc.paragraphs) text = "\n".join(p.text for p in doc.paragraphs)
for table in doc.tables: for table in doc.tables:
@@ -291,7 +295,11 @@ class TwoPassObfuscator:
text += "\n" + " | ".join(cell.text for cell in row.cells) text += "\n" + " | ".join(cell.text for cell in row.cells)
elif ext == '.pdf': elif ext == '.pdf':
import pdfplumber try:
import pdfplumber
except ImportError:
text = content.decode('utf-8', errors='replace')
return text, None
with pdfplumber.open(io.BytesIO(content)) as pdf: with pdfplumber.open(io.BytesIO(content)) as pdf:
for page in pdf.pages: for page in pdf.pages:
t = page.extract_text() t = page.extract_text()
+1 -1
View File
@@ -138,7 +138,7 @@ def health():
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000) app.run(host="0.0.0.0", port=5000, threaded=True)
# ── Совместимость с Lucee-путями ────────────────────────────── # ── Совместимость с Lucee-путями ──────────────────────────────
+10 -2
View File
@@ -283,7 +283,11 @@ class TwoPassObfuscator:
ext = os.path.splitext(fname)[1].lower() ext = os.path.splitext(fname)[1].lower()
if ext == '.docx': if ext == '.docx':
from docx import Document try:
from docx import Document
except ImportError:
text = content.decode('utf-8', errors='replace')
return text, None
doc = Document(io.BytesIO(content)) doc = Document(io.BytesIO(content))
text = "\n".join(p.text for p in doc.paragraphs) text = "\n".join(p.text for p in doc.paragraphs)
for table in doc.tables: for table in doc.tables:
@@ -291,7 +295,11 @@ class TwoPassObfuscator:
text += "\n" + " | ".join(cell.text for cell in row.cells) text += "\n" + " | ".join(cell.text for cell in row.cells)
elif ext == '.pdf': elif ext == '.pdf':
import pdfplumber try:
import pdfplumber
except ImportError:
text = content.decode('utf-8', errors='replace')
return text, None
with pdfplumber.open(io.BytesIO(content)) as pdf: with pdfplumber.open(io.BytesIO(content)) as pdf:
for page in pdf.pages: for page in pdf.pages:
t = page.extract_text() t = page.extract_text()