1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

Replace codecs.open() with open() since codecs.open() deprecated in Python 3.14

This commit is contained in:
Alexander Smorkalov
2026-05-24 16:54:39 +03:00
parent 00d19e1c63
commit 852c3d2fb9
4 changed files with 11 additions and 13 deletions
+3 -3
View File
@@ -489,9 +489,9 @@ class SVG:
f.close() f.close()
else: else:
f = codecs.open(fileName, "w", encoding=encoding) with open(fileName, "w", encoding=encoding) as f:
f.write(self.standalone_xml(encoding=encoding)) f.write(self.standalone_xml(encoding=encoding))
f.close()
def inkview(self, fileName=None, encoding="utf-8"): def inkview(self, fileName=None, encoding="utf-8"):
"""View in "inkview", assuming that program is available on your system. """View in "inkview", assuming that program is available on your system.
+1 -2
View File
@@ -3,7 +3,6 @@
import sys, re, os.path, errno, fnmatch import sys, re, os.path, errno, fnmatch
import json import json
import logging import logging
import codecs
from shutil import copyfile from shutil import copyfile
from pprint import pformat from pprint import pformat
from string import Template from string import Template
@@ -589,7 +588,7 @@ class JavaWrapperGenerator(object):
content = f.read() content = f.read()
if content == buf: if content == buf:
return return
with codecs.open(path, "w", "utf-8") as f: with open(path, "w", encoding="utf-8") as f:
f.write(buf) f.write(buf)
updated_files += 1 updated_files += 1
+2 -3
View File
@@ -4,7 +4,6 @@ from __future__ import print_function, unicode_literals
import sys, re, os.path, errno, fnmatch import sys, re, os.path, errno, fnmatch
import json import json
import logging import logging
import codecs
import io import io
from shutil import copyfile from shutil import copyfile
from pprint import pformat from pprint import pformat
@@ -902,7 +901,7 @@ class ObjectiveCWrapperGenerator(object):
content = f.read() content = f.read()
if content == buf: if content == buf:
return return
with codecs.open(path, "w", "utf-8") as f: with open(path, "w", encoding="utf-8") as f:
f.write(buf) f.write(buf)
updated_files += 1 updated_files += 1
@@ -1530,7 +1529,7 @@ typedef NS_ENUM(int, {1}) {{
body = file.read() body = file.read()
body = body.replace("import OpenCV", "import " + framework_name) body = body.replace("import OpenCV", "import " + framework_name)
body = body.replace("#import <OpenCV/OpenCV.h>", "#import <" + framework_name + "/" + framework_name + ".h>") body = body.replace("#import <OpenCV/OpenCV.h>", "#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) file.write(body)
+5 -5
View File
@@ -32,7 +32,7 @@ Adding --dynamic parameter will build {framework_name}.framework as App Store dy
""" """
from __future__ import print_function, unicode_literals 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 from subprocess import check_call, check_output, CalledProcessError
if sys.version_info >= (3, 8): # Python 3.8+ 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:] body = body[:insert_pos] + "import " + self.framework_name + "\n" + body[insert_pos:]
else: else:
body = "import " + self.framework_name + "\n\n" + body 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) file_out.write(body)
def build(self, outdir): def build(self, outdir):
@@ -380,7 +380,7 @@ class Builder:
framework = self.framework_name, framework = self.framework_name,
hosting_base_path = self.hosting_base_path 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) file.write(howto)
self.docs_built = True 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) 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 dirname, dirs, files in os.walk(os.path.join(dstdir, "Headers")):
for filename in files: for filename in files:
filepath = os.path.join(dirname, filename) 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 = file.read()
body = body.replace("include \"opencv2/", "include \"" + name + "/") body = body.replace("include \"opencv2/", "include \"" + name + "/")
body = body.replace("include <opencv2/", "include <" + name + "/") body = body.replace("include <opencv2/", "include <" + name + "/")
with codecs.open(filepath, "w", "utf-8") as file: with open(filepath, "w", encoding="utf-8") as file:
file.write(body) file.write(body)
if self.build_objc_wrapper: if self.build_objc_wrapper:
copy_tree(os.path.join(builddirs[0], "install", "lib", name + ".framework", "Headers"), os.path.join(dstdir, "Headers")) copy_tree(os.path.join(builddirs[0], "install", "lib", name + ".framework", "Headers"), os.path.join(dstdir, "Headers"))