From 852c3d2fb947574655087a2514f80c66b4ae5954 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Sun, 24 May 2026 16:54:39 +0300 Subject: [PATCH] Replace codecs.open() with open() since codecs.open() deprecated in Python 3.14 --- apps/pattern-tools/svgfig.py | 6 +++--- modules/java/generator/gen_java.py | 3 +-- modules/objc/generator/gen_objc.py | 5 ++--- platforms/ios/build_framework.py | 10 +++++----- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/pattern-tools/svgfig.py b/apps/pattern-tools/svgfig.py index 73a91ce134..323ed420c0 100644 --- a/apps/pattern-tools/svgfig.py +++ b/apps/pattern-tools/svgfig.py @@ -489,9 +489,9 @@ class SVG: f.close() else: - f = codecs.open(fileName, "w", encoding=encoding) - f.write(self.standalone_xml(encoding=encoding)) - f.close() + with open(fileName, "w", encoding=encoding) as f: + f.write(self.standalone_xml(encoding=encoding)) + def inkview(self, fileName=None, encoding="utf-8"): """View in "inkview", assuming that program is available on your system. diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 591eb38ea3..691e2eee00 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -3,7 +3,6 @@ import sys, re, os.path, errno, fnmatch import json import logging -import codecs from shutil import copyfile from pprint import pformat from string import Template @@ -589,7 +588,7 @@ class JavaWrapperGenerator(object): content = f.read() if content == buf: return - with codecs.open(path, "w", "utf-8") as f: + with open(path, "w", encoding="utf-8") as f: f.write(buf) updated_files += 1 diff --git a/modules/objc/generator/gen_objc.py b/modules/objc/generator/gen_objc.py index 10071267e6..5dfabbe65d 100755 --- a/modules/objc/generator/gen_objc.py +++ b/modules/objc/generator/gen_objc.py @@ -4,7 +4,6 @@ from __future__ import print_function, unicode_literals import sys, re, os.path, errno, fnmatch import json import logging -import codecs import io from shutil import copyfile from pprint import pformat @@ -902,7 +901,7 @@ class ObjectiveCWrapperGenerator(object): content = f.read() if content == buf: return - with codecs.open(path, "w", "utf-8") as f: + with open(path, "w", encoding="utf-8") as f: f.write(buf) updated_files += 1 @@ -1530,7 +1529,7 @@ typedef NS_ENUM(int, {1}) {{ body = file.read() body = body.replace("import OpenCV", "import " + framework_name) body = body.replace("#import ", "#import <" + framework_name + "/" + framework_name + ".h>") - with codecs.open(filepath, "w", "utf-8") as file: + with open(filepath, "w", encoding="utf-8") as file: file.write(body) diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index 5bf6764361..bca699bf0c 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -32,7 +32,7 @@ Adding --dynamic parameter will build {framework_name}.framework as App Store dy """ from __future__ import print_function, unicode_literals -import glob, os, os.path, shutil, string, sys, argparse, traceback, multiprocessing, codecs, io +import glob, os, os.path, shutil, string, sys, argparse, traceback, multiprocessing, io from subprocess import check_call, check_output, CalledProcessError if sys.version_info >= (3, 8): # Python 3.8+ @@ -190,7 +190,7 @@ class Builder: body = body[:insert_pos] + "import " + self.framework_name + "\n" + body[insert_pos:] else: body = "import " + self.framework_name + "\n\n" + body - with codecs.open(os.path.join(swift_sources_dir, file), "w", "utf-8") as file_out: + with open(os.path.join(swift_sources_dir, file), "w", encoding="utf-8") as file_out: file_out.write(body) def build(self, outdir): @@ -380,7 +380,7 @@ class Builder: framework = self.framework_name, hosting_base_path = self.hosting_base_path ) - with codecs.open(os.path.join(docs_dir, "HOWTO.md"), "w", "utf-8") as file: + with open(os.path.join(docs_dir, "HOWTO.md"), "w", encoding="utf-8") as file: file.write(howto) self.docs_built = True execute(["cmake", "-DBUILD_TYPE=%s" % self.getConfiguration(), "-DCMAKE_INSTALL_PREFIX=%s" % (builddir + "/install"), "-P", "cmake_install.cmake"], cwd = framework_build_dir) @@ -473,11 +473,11 @@ class Builder: for dirname, dirs, files in os.walk(os.path.join(dstdir, "Headers")): for filename in files: filepath = os.path.join(dirname, filename) - with codecs.open(filepath, "r", "utf-8") as file: + with open(filepath, "r", encoding="utf-8") as file: body = file.read() body = body.replace("include \"opencv2/", "include \"" + name + "/") body = body.replace("include