aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/shibokenmodule
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-02-26 09:44:01 +0100
committerChristian Tismer <tismer@stackless.com>2019-03-20 17:33:21 +0000
commite8786b9cdccb63aa590af50fe5fa5496c6b216c7 (patch)
tree89f30d78603c81937f0c6dd9f768576b6463f9f7 /sources/shiboken2/shibokenmodule
parentc32dacab85b435751db2811e7a88d5c03b1856e1 (diff)
Simplify Python Imports For Embedding
After the project split, shiboken exposed its own modules, and the overall structure with shiboken2.support.signature and PySide2.support.signature was already quite complicated. When introducing embedding, it is necessary to have some support folder that gets unpacked from a zipfile. That means, the shiboken2 root directory would be in the zip file in the embedding case. This does not only increase the complexity, it further means that we must make shiboken2.so available in the shiboken2 containing zipfile! In order to avoid that, we stop the dependency from the two support directories and use shibokensupport, instead. The simplification of the loader and other modules is also significant. Task-number: PYSIDE-510 Change-Id: Ic735a8d36f10f03698378f2ac9685a5955e40b0c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/shibokenmodule')
-rw-r--r--sources/shiboken2/shibokenmodule/CMakeLists.txt46
-rw-r--r--sources/shiboken2/shibokenmodule/__init__.py.in7
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py (renamed from sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt (renamed from sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py (renamed from sources/shiboken2/shibokenmodule/support/signature/__init__.py)11
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py (renamed from sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py (renamed from sources/shiboken2/shibokenmodule/support/signature/errorhandler.py)4
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py (renamed from sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py (renamed from sources/shiboken2/shibokenmodule/support/signature/layout.py)6
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py (renamed from sources/shiboken2/shibokenmodule/support/__init__.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py (renamed from sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py (renamed from sources/shiboken2/shibokenmodule/support/signature/loader.py)94
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py683
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py (renamed from sources/shiboken2/shibokenmodule/support/signature/parser.py)6
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json (renamed from sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py (renamed from sources/shiboken2/shibokenmodule/support/signature/typing27.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/contextlib36.py472
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/mapping.py347
18 files changed, 763 insertions, 921 deletions
diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt
index b37d0c94..612055b3 100644
--- a/sources/shiboken2/shibokenmodule/CMakeLists.txt
+++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt
@@ -51,32 +51,32 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_config.py"
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
"${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/errorhandler.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/errorhandler.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/layout.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/layout.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/loader.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/loader.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/mapping.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/mapping.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/parser.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/parser.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/enum_sig.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/enum_sig.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/errorhandler.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/errorhandler.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/layout.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/layout.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/loader.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/loader.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/mapping.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/mapping.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/parser.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/parser.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py" COPYONLY)
if (PYTHON_VERSION_MAJOR EQUAL 3)
else()
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/backport_inspect.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/backport_inspect.py" COPYONLY)
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/typing27.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/typing27.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/backport_inspect.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/backport_inspect.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/typing27.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/typing27.py" COPYONLY)
endif()
-install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/support"
+install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/files.dir"
DESTINATION "${PYTHON_SITE_PACKAGES}/shiboken2")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py"
diff --git a/sources/shiboken2/shibokenmodule/__init__.py.in b/sources/shiboken2/shibokenmodule/__init__.py.in
index 81ab0063..92e469df 100644
--- a/sources/shiboken2/shibokenmodule/__init__.py.in
+++ b/sources/shiboken2/shibokenmodule/__init__.py.in
@@ -1,4 +1,11 @@
__version__ = "@FINAL_PACKAGE_VERSION@"
__version_info__ = (@shiboken_MAJOR_VERSION@, @shiboken_MINOR_VERSION@, @shiboken_MICRO_VERSION@, "@shiboken_PRE_RELEASE_VERSION_TYPE@", "@shiboken_PRE_RELEASE_VERSION@")
+# PYSIDE-932: Python 2 cannot import 'zipfile' for embedding while being imported, itself.
+# We simply pre-load all imports for the signature extension.
+import sys, zipfile, base64, marshal, io
+
from .shiboken2 import *
+
+# Trigger signature initialization.
+type.__signature__
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py
index 2d640cb8..2d640cb8 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py
diff --git a/sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt
index be42010d..be42010d 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt
diff --git a/sources/shiboken2/shibokenmodule/support/signature/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py
index d0791df0..9447e9c2 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -39,9 +39,6 @@
from __future__ import print_function, absolute_import
-# Trigger initialization phase 2.
-_ = type.__signature__
-
-## from signature_loader import get_signature, inspect, typing
-# This causes a recursion in Python 2!
-# We do everything from signature_loader, instead.
+# from shibokensupport.signature import get_signature, inspect, typing
+# This gives a problem with Python 2. We do it in the loader, instead.
+__all__ = "get_signature inspect typing layout mapping lib".split()
diff --git a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py
index e890dcdc..fbd82cc5 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py
@@ -3,7 +3,7 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
diff --git a/sources/shiboken2/shibokenmodule/support/signature/errorhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py
index df24234e..1443d792 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/errorhandler.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py
@@ -56,8 +56,8 @@ enough to produce a useful ValueError.
This matter will be improved in a later version.
"""
-from signature_loader import get_signature, inspect
-from signature_loader.mapping import update_mapping, namespace
+from shibokensupport.signature import get_signature, inspect
+from shibokensupport.signature.mapping import update_mapping, namespace
from textwrap import dedent
diff --git a/sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py
index cdd84f9b..cdd84f9b 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py
diff --git a/sources/shiboken2/shibokenmodule/support/signature/layout.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
index cd3a5dc8..c43d6d07 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/layout.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -56,8 +56,8 @@ used literally as strings like "signature", "existence", etc.
"""
from textwrap import dedent
-from signature_loader import inspect
-from signature_loader.mapping import ellipsis
+from shibokensupport.signature import inspect
+from shibokensupport.signature.mapping import ellipsis
class SimpleNamespace(object):
diff --git a/sources/shiboken2/shibokenmodule/support/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py
index 760d8957..2d640cb8 100644
--- a/sources/shiboken2/shibokenmodule/support/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2017 The Qt Company Ltd.
+## Copyright (C) 2018 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
index 013ec36c..90affbcf 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
@@ -50,7 +50,7 @@ by producing a lot of clarity.
"""
import sys
-from signature_loader import get_signature, inspect
+from shibokensupport.signature import get_signature, inspect
class ExactEnumerator(object):
diff --git a/sources/shiboken2/shibokenmodule/support/signature/loader.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
index 45875984..3a8d614d 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/loader.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -45,13 +45,8 @@ loader.py
The loader has to lazy-load the signature module and also provides a few
Python modules to support Python 2.7 .
-This file was originally directly embedded into the C source.
-After it grew more and more, I now prefer to have it as Python file.
-The remaining stub loader in the C source is now only a short string.
-
-This version does no longer use an embedded .zip file but is a package.
-The old code without a package but with zip compression can still be found
-at https://codereview.qt-project.org/#/c/203533/ for reference.
+This version uses both a normal directory, but has also an embedded zip file
+as a fallback solution.
"""
import sys
@@ -85,29 +80,28 @@ except NameError:
ModuleNotFoundError = ImportError
@contextmanager
-def ensure_import_support():
- # Make sure that we always have the shiboken containing package first.
- # This is sometimes hidden by the ctest paths.
- # We adjust the path in a way that the support folder comes first.
- # This can be in "shiboken2/support" or in "shibokenmodule/support",
- # so we use the "support" folder as toplevel.
+def ensure_import_shibokensupport():
+ # Make sure that we always have the shibokensupport containing package first.
+ # Also remove any prior loaded module of this name, just in case.
sbk_support_dir = os.path.abspath(os.path.join(__file__, "..", "..", ".."))
+ assert os.path.basename(sbk_support_dir) == "files.dir"
sys.path.insert(0, sbk_support_dir)
- sbk = "shiboken2"
- save_sbk = sys.modules.pop(sbk) if sbk in sys.modules else None
- # make sure that we get at the support folder
+
+ sbk = "shibokensupport"
+ if sbk in sys.modules:
+ del sys.modules[sbk]
+ for key in list(key for key in sys.modules if key.startswith(sbk + ".")):
+ del sys.modules[key]
try:
- import support
+ import shibokensupport
yield
except Exception as e:
- print("Problem importing support:")
+ print("Problem importing shibokensupport:")
print(e)
traceback.print_exc()
sys.stdout.flush()
sys.exit(-1)
- if save_sbk:
- sys.modules[sbk] = save_sbk
- sys.path.pop(0)
+ sys.path.remove(sbk_support_dir)
# patching inspect's formatting to keep the word "typing":
@@ -117,7 +111,7 @@ def formatannotation(annotation, base_module=None):
if isinstance(annotation, type):
if annotation.__module__ in ('builtins', base_module):
return annotation.__qualname__
- return annotation.__module__+'.'+annotation.__qualname__
+ return annotation.__module__ + '.' + annotation.__qualname__
return repr(annotation)
# patching __repr__ to disable the __repr__ of typing.TypeVar:
@@ -149,10 +143,11 @@ def seterror_argument(args, func_name):
def make_helptext(func):
return errorhandler.make_helptext(func)
-with ensure_import_support():
- # We store all needed modules in signature_loader.
- # This way, they are always accessible.
+with ensure_import_shibokensupport():
import signature_loader
+ import shibokensupport.signature
+ shibokensupport.signature.get_signature = signature_loader.get_signature
+ del signature_loader # protect this dir, too?
if sys.version_info >= (3,):
import typing
@@ -161,7 +156,7 @@ with ensure_import_support():
else:
import inspect
namespace = inspect.__dict__
- from support.signature import typing27 as typing
+ from shibokensupport.signature import typing27 as typing
typing.__name__ = "typing"
# Fix the module names in typing if possible. This is important since
# the typing names should be I/O compatible, so that typing.Dict
@@ -172,7 +167,7 @@ with ensure_import_support():
obj.__module__ = "typing"
except (TypeError, AttributeError):
pass
- from support.signature import backport_inspect as inspect
+ from shibokensupport.signature import backport_inspect as inspect
_doc = inspect.__doc__
inspect.__dict__.update(namespace)
inspect.__doc__ += _doc
@@ -180,42 +175,21 @@ with ensure_import_support():
inspect.__all__ = list(x for x in dir(inspect) if not x.startswith("_"))
typing.TypeVar.__repr__ = _typevar__repr__
- def put_into_loader_package(module, loader=signature_loader):
- # Note: the "with" statement hides that we are no longer in a
- # global context, but inside ensure_import_support. Therefore,
- # we need to explicitly pass the signature_loader in.
-
+ def put_into_package(module, package):
# take the last component of the module name
name = module.__name__.rsplit(".", 1)[-1]
- # allow access as signature_loader.typing
- setattr(loader, name, module)
+ # allow access as {package}.typing
+ setattr(package, name, module)
# put into sys.modules as a package to allow all import options
- fullname = "{}.{}".format(loader.__name__, name)
+ fullname = "{}.{}".format(package.__name__, name)
sys.modules[fullname] = module
- put_into_loader_package(typing)
- put_into_loader_package(inspect)
- from support.signature import mapping as sbk_mapping
- sbk_mapping.__name__ = "sbk_mapping"
- put_into_loader_package(sbk_mapping)
- # We may or may not use PySide.
- try:
- from PySide2.support.signature import mapping
- except ModuleNotFoundError:
- mapping = sbk_mapping
- mapping.__name__ = "mapping"
- put_into_loader_package(mapping)
- from support.signature import errorhandler
- put_into_loader_package(errorhandler)
- from support.signature import layout
- put_into_loader_package(layout)
- from support.signature.lib import enum_sig
- put_into_loader_package(enum_sig)
- from support.signature.parser import pyside_type_init
- put_into_loader_package(pyside_type_init)
- put_into_loader_package(create_signature)
- put_into_loader_package(seterror_argument)
- put_into_loader_package(make_helptext)
-
+ put_into_package(typing, shibokensupport.signature)
+ put_into_package(inspect, shibokensupport.signature)
+ from shibokensupport.signature import mapping
+ from shibokensupport.signature import errorhandler
+ from shibokensupport.signature import layout
+ from shibokensupport.signature.lib import enum_sig
+ from shibokensupport.signature.parser import pyside_type_init
# end of file
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
new file mode 100644
index 00000000..470dd676
--- /dev/null
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -0,0 +1,683 @@
+#############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU Lesser General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU Lesser
+## General Public License version 3 as published by the Free Software
+## Foundation and appearing in the file LICENSE.LGPL3 included in the
+## packaging of this file. Please review the following information to
+## ensure the GNU Lesser General Public License version 3 requirements
+## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 2.0 or (at your option) the GNU General
+## Public license version 3 or any later version approved by the KDE Free
+## Qt Foundation. The licenses are as published by the Free Software
+## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-2.0.html and
+## https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+from __future__ import print_function, absolute_import
+
+"""
+mapping.py
+
+This module has the mapping from the pyside C-modules view of signatures
+to the Python representation.
+
+The PySide modules are not loaded in advance, but only after they appear
+in sys.modules. This minimizes the loading overhead.
+"""
+
+import sys
+import struct
+import os
+import pkgutil
+
+from shibokensupport.signature import typing
+from shibokensupport.signature.typing import TypeVar, Generic
+
+class ellipsis(object):
+ def __repr__(self):
+ return "..."
+
+ellipsis = ellipsis()
+StringList = typing.List[str]
+IntList = typing.List[int]
+Point = typing.Tuple[float, float]
+PointList = typing.List[Point]
+IntMatrix = typing.List[IntList]
+Variant = typing.Any
+ModelIndexList = typing.List[int]
+QImageCleanupFunction = typing.Callable
+
+# First time installing our own Pair type into typing.
+T = TypeVar('T')
+S = TypeVar('S')
+
+class Pair(Generic[T, S]):
+ __module__ = "typing"
+
+typing.Pair = Pair
+
+
+# Building our own Char type, which is much nicer than
+# Char = typing.Union[str, int] # how do I model the limitation to 1 char?
+
+# Copied from the six module:
+def with_metaclass(meta, *bases):
+ """Create a base class with a metaclass."""
+ # This requires a bit of explanation: the basic idea is to make a dummy
+ # metaclass for one level of class instantiation that replaces itself with
+ # the actual metaclass.
+ class metaclass(type):
+
+ def __new__(cls, name, this_bases, d):
+ return meta(name, bases, d)
+
+ @classmethod
+ def __prepare__(cls, name, this_bases):
+ return meta.__prepare__(name, bases)
+ return type.__new__(metaclass, 'temporary_class', (), {})
+
+class _CharMeta(type):
+ def __repr__(self):
+ return '%s.%s' % (self.__module__, self.__name__)
+
+
+class Char(with_metaclass(_CharMeta)):
+ """
+ From http://doc.qt.io/qt-5/qchar.html :
+
+ In Qt, Unicode characters are 16-bit entities without any markup or
+ structure. This class represents such an entity. It is lightweight,
+ so it can be used everywhere. Most compilers treat it like an
+ unsigned short.
+
+ Here, we provide a simple implementation just to avoid long aliases.
+ """
+ __module__ = "typing"
+
+ def __init__(self, code):
+ if isinstance(code, int):
+ self.code = code & 0xffff
+ else:
+ self.code = ord(code)
+
+ def __add__(self, other):
+ return chr(self.code) + other
+
+ def __radd__(self, other):
+ return other + chr(self.code)
+
+ def __repr__(self):
+ return "typing.Char({})".format(self.code)
+
+typing.Char = Char
+
+
+MultiMap = typing.DefaultDict[str, typing.List[str]]
+
+# ulong_max is only 32 bit on windows.
+ulong_max = 2*sys.maxsize+1 if len(struct.pack("L", 1)) != 4 else 0xffffffff
+ushort_max = 0xffff
+
+GL_COLOR_BUFFER_BIT = 0x00004000
+GL_NEAREST = 0x2600
+
+WId = int
+
+# from 5.9
+GL_TEXTURE_2D = 0x0DE1
+GL_RGBA = 0x1908
+
+
+class _NotCalled(str):
+ """
+ Wrap some text with semantics
+
+ This class is wrapped around text in order to avoid calling it.
+ There are three reasons for this:
+
+ - some instances cannot be created since they are abstract,
+ - some can only be created after qApp was created,
+ - some have an ugly __repr__ with angle brackets in it.
+
+ By using derived classes, good looking instances can be created
+ which can be used to generate source code or .pyi files. When the
+ real object is needed, the wrapper can simply be called.
+ """
+ def __repr__(self):
+ suppress = "support.signature.typing27."
+ text = self[len(suppress):] if self.startswith(suppress) else self
+ return "{}({})".format(type(self).__name__, text)
+
+ def __call__(self):
+ from shibokensupport.signature.mapping import __dict__ as namespace
+ text = self if self.endswith(")") else self + "()"
+ return eval(text, namespace)
+
+USE_PEP563 = sys.version_info[:2] >= (3, 7)
+
+
+# Some types are abstract. They just show their name.
+class Virtual(_NotCalled):
+ pass
+
+# Other types I simply could not find.
+class Missing(_NotCalled):
+ if not USE_PEP563:
+ # The string must be quoted, because the object does not exist.
+ def __repr__(self):
+ return '{}("{}")'.format(type(self).__name__, self)
+
+
+class Invalid(_NotCalled):
+ pass
+
+# Helper types
+class Default(_NotCalled):
+ pass
+
+
+class Instance(_NotCalled):
+ pass
+
+
+class Reloader(object):
+ """
+ Reloder class
+
+ This is a singleton class which provides the update function for the
+ shiboken and PySide classes.
+ """
+ _uninitialized = "Shiboken minimal sample other smart".split()
+ _prefixes = [""]
+ try:
+ import PySide2
+ _uninitialized += PySide2.__all__ + ["testbinding"]
+ _prefixes += ["PySide2."]
+ except ImportError:
+ pass
+
+ def __init__(self):
+ self.sys_module_count = 0
+ self.uninitialized = self._uninitialized
+
+ def update(self):
+ """
+ update is responsible to import all modules from shiboken and PySide
+ which are already in sys.modules.
+ The purpose is to follow all user imports without introducing new
+ ones.
+ This function is called by pyside_type_init to adapt imports
+ when the number of imported modules has changed.
+ """
+ if self.sys_module_count == len(sys.modules):
+ return
+ self.sys_module_count = len(sys.modules)
+ g = globals()
+ for mod_name in self.uninitialized[:]:
+ for prefix in self._prefixes:
+ import_name = prefix + mod_name
+ if import_name in sys.modules:
+ # check if this is a real module
+ check_module(sys.modules[import_name])
+ # module is real
+ self.uninitialized.remove(mod_name)
+ proc_name = "init_" + mod_name
+ if proc_name in g:
+ # Do the 'import {import_name}' first.
+ # 'top' is PySide2 when we do 'import PySide.QtCore'
+ # or Shiboken if we do 'import Shiboken'.
+ # Convince yourself that these two lines below have the same
+ # global effect as "import Shiboken" or "import PySide2.QtCore".
+ top = __import__(import_name)
+ g[top.__name__] = top
+ # Modules are in place, we can update the type_map.
+ g.update(g[proc_name]())
+
+def check_module(mod):
+ # During a build, there exist the modules already as directories,
+ # although the '*.so' was not yet created. This causes a problem
+ # in Python 3, because it accepts folders as namespace modules
+ # without enforcing an '__init__.py'.
+ if not getattr(mod, "__file__", None) or os.path.isdir(mod.__file__):
+ mod_name = mod.__name__
+ raise ImportError("Module '{mod_name}' is at most a namespace!"
+ .format(**locals()))
+
+
+update_mapping = Reloader().update
+type_map = {}
+namespace = globals() # our module's __dict__
+
+type_map.update({
+ "QList": typing.List,
+ "QVector": typing.List,
+ "QSet": typing.Set,
+ "QPair": Pair,
+ })
+
+
+# The Shiboken Part
+def init_Shiboken():
+ type_map.update({
+ "shiboken2.bool": bool,
+ "size_t": int,
+ "PyType": type,
+ })
+ return locals()
+
+
+def init_minimal():
+ type_map.update({
+ "MinBool": bool,
+ })
+ return locals()
+
+
+def init_sample():
+ import datetime
+ type_map.update({
+ "double": float,
+ "sample.int": int,
+ "Complex": complex,
+ "sample.OddBool": bool,
+ "sample.bool": bool,
+ "sample.PStr": str,
+ "OddBool": bool,
+ "PStr": str,
+ "char": Char,
+ "sample.char": Char,
+ "sample.Point": Point,
+ "sample.ObjectType": object,
+ "std.string": str,
+ "HANDLE": int,
+ "Foo.HANDLE": int,
+ "sample.Photon.TemplateBase": Missing("sample.Photon.TemplateBase"),
+ "ObjectType.Identifier": Missing("sample.ObjectType.Identifier"),
+ "zero(HANDLE)": 0,
+ "Null": None,
+ "zero(sample.ObjectType)": None,
+ "std.size_t": int,
+ 'Str("<unknown>")': "<unknown>",
+ 'Str("<unk")': "<unk",
+ 'Str("nown>")': "nown>",
+ "zero(sample.ObjectModel)": None,
+ "sample.unsigned char": Char,
+ "sample.double": float,
+ "zero(sample.bool)": False,
+ "PyDate": datetime.date,
+ "ZeroIn": 0,
+ })
+ return locals()
+
+
+def init_other():
+ import numbers
+ type_map.update({
+ "other.Number": numbers.Number,
+ "other.ExtendsNoImplicitConversion": Missing("other.ExtendsNoImplicitConversion"),
+ })
+ return locals()
+
+
+def init_smart():
+ type_map.update({
+ "smart.SharedPtr": Missing("smart.SharedPtr"), # bad object "SharedPtr<Obj >"
+ })
+ return locals()
+
+# The PySide Part
+def init_QtCore():
+ from PySide2.QtCore import Qt, QUrl, QDir
+ from PySide2.QtCore import QRect, QSize, QPoint, QLocale, QByteArray
+ from PySide2.QtCore import QMarginsF # 5.9
+ try:
+ # seems to be not generated by 5.9 ATM.
+ from PySide2.QtCore import Connection
+ except ImportError:
+ pass
+ type_map.update({
+ "str": str,
+ "int": int,
+ "QString": str,
+ "bool": bool,
+ "PyObject": object,
+ "void": int, # be more specific?
+ "char": Char,
+ "'%'": "%",
+ "' '": " ",
+ "false": False,
+ "double": float,
+ "'g'": "g",
+ "long long": int,
+ "unsigned int": int, # should we define an unsigned type?
+ "Q_NULLPTR": None,
+ "long": int,
+ "float": float,
+ "short": int,
+ "unsigned long": int,
+ "unsigned long long": int,
+ "unsigned short": int,
+ "QStringList": StringList,
+ "QChar": Char,
+ "signed char": Char,
+ "QVariant": Variant,
+ "QVariant.Type": type, # not so sure here...
+ "QStringRef": str,
+ "QString()": "",
+ "QModelIndexList": ModelIndexList,
+ "unsigned char": Char,
+ "QJsonObject": typing.Dict[str, PySide2.QtCore.QJsonValue],
+ "QStringList()": [],
+ "ULONG_MAX": ulong_max,
+ "quintptr": int,
+ "PyCallable": typing.Callable,
+ "PyTypeObject": type,
+ "PySequence": typing.Iterable, # important for numpy
+ "qptrdiff": int,
+ "true": True,
+ "Qt.HANDLE": int, # be more explicit with some consts?
+ "list of QAbstractState": typing.List[PySide2.QtCore.QAbstractState],
+ "list of QAbstractAnimation": typing.List[PySide2.QtCore.QAbstractAnimation],
+ "QVariant()": Invalid(Variant),
+ "QMap": typing.Dict,
+ "PySide2.QtCore.bool": bool,
+ "QHash": typing.Dict,
+ "PySide2.QtCore.QChar": Char,
+ "PySide2.QtCore.qreal": float,
+ "PySide2.QtCore.float": float,
+ "PySide2.QtCore.qint16": int,
+ "PySide2.QtCore.qint32": int,
+ "PySide2.QtCore.qint64": int,
+ "PySide2.QtCore.qint8": int,
+ "PySide2.QtCore.QString": str,
+ "PySide2.QtCore.QStringList": StringList,
+ "PySide2.QtCore.QVariant": Variant,
+ "PySide2.QtCore.quint16": int,
+ "PySide2.QtCore.quint32": int,
+ "PySide2.QtCore.quint64": int,
+ "PySide2.QtCore.quint8": int,
+ "PySide2.QtCore.uchar": Char,
+ "PySide2.QtCore.unsigned char": Char, # 5.9
+ "PySide2.QtCore.long": int,
+ "PySide2.QtCore.QUrl.ComponentFormattingOptions":
+ PySide2.QtCore.QUrl.ComponentFormattingOption, # mismatch option/enum, why???
+ "QUrl.FormattingOptions(PrettyDecoded)": Instance(
+ "QUrl.FormattingOptions(QUrl.PrettyDecoded)"),
+ # from 5.9
+ "QDir.Filters(AllEntries | NoDotAndDotDot)": Instance(
+ "QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot)"),
+ "NULL": None, # 5.6, MSVC
+ "QDir.SortFlags(Name | IgnoreCase)": Instance(
+ "QDir.SortFlags(QDir.Name | QDir.IgnoreCase)"),
+ "PyBytes": bytes,
+ "PyByteArray": bytearray,
+ "PyUnicode": typing.Text,
+ "signed long": int,
+ "PySide2.QtCore.int": int,
+ "PySide2.QtCore.char": StringList, # A 'char **' is a list of strings.
+ "unsigned long int": int, # 5.6, RHEL 6.6
+ "unsigned short int": int, # 5.6, RHEL 6.6
+ "4294967295UL": 4294967295, # 5.6, RHEL 6.6
+ "PySide2.QtCore.int32_t": int, # 5.9
+ "PySide2.QtCore.int64_t": int, # 5.9
+ "UnsignedShortType": int, # 5.9
+ "nullptr": None, # 5.9
+ "uint64_t": int, # 5.9
+ "PySide2.QtCore.uint32_t": int, # 5.9
+ "PySide2.QtCore.unsigned int": int, # 5.9 Ubuntu
+ "PySide2.QtCore.long long": int, # 5.9, MSVC 15
+ "QGenericArgument(nullptr)": ellipsis, # 5.10
+ "QModelIndex()": Invalid("PySide2.QtCore.QModelIndex"), # repr is btw. very wrong, fix it?!
+ "QGenericArgument((0))": ellipsis, # 5.6, RHEL 6.6. Is that ok?
+ "QGenericArgument()": ellipsis,
+ "QGenericArgument(0)": ellipsis,
+ "QGenericArgument(NULL)": ellipsis, # 5.6, MSVC
+ "QGenericArgument(Q_NULLPTR)": ellipsis,
+ "zero(PySide2.QtCore.QObject)": None,
+ "zero(PySide2.QtCore.QThread)": None,
+ "zero(quintptr)": 0,
+ "zero(str)": "",
+ "zero(int)": 0,
+ "zero(PySide2.QtCore.QState)": None,
+ "zero(PySide2.QtCore.bool)": False,
+ "zero(PySide2.QtCore.int)": 0,
+ "zero(void)": None,
+ "zero(long long)": 0,
+ "zero(PySide2.QtCore.QAbstractItemModel)": None,
+ "zero(PySide2.QtCore.QJsonParseError)": None,
+ "zero(double)": 0.0,
+ "zero(PySide2.QtCore.qint64)": 0,
+ "zero(PySide2.QtCore.QTextCodec.ConverterState)": None,
+ "zero(long long)": 0,
+ "zero(QImageCleanupFunction)": None,
+ "zero(unsigned int)": 0,
+ "zero(PySide2.QtCore.QPoint)": Default("PySide2.QtCore.QPoint"),
+ "zero(unsigned char)": 0,
+ "zero(PySide2.QtCore.QEvent.Type)": None,
+ "CheckIndexOption.NoOption": Instance(
+ "PySide2.QtCore.QAbstractItemModel.CheckIndexOptions.NoOption"), # 5.11
+ "QVariantMap": typing.Dict[str, Variant],
+ "PySide2.QtCore.QCborStreamReader.StringResult": typing.AnyStr,
+ "PySide2.QtCore.double": float,
+ })
+ try:
+ type_map.update({
+ "PySide2.QtCore.QMetaObject.Connection": PySide2.QtCore.Connection, # wrong!
+ })
+ except AttributeError:
+ # this does not exist on 5.9 ATM.
+ pass
+ return locals()
+
+
+def init_QtGui():
+ from PySide2.QtGui import QPageLayout, QPageSize # 5.12 macOS
+ type_map.update({
+ "QVector< QTextLayout.FormatRange >()": [], # do we need more structure?
+ "USHRT_MAX": ushort_max,
+ "0.0f": 0.0,
+ "1.0f": 1.0,
+ "uint32_t": int,
+ "uint8_t": int,
+ "int32_t": int,
+ "GL_COLOR_BUFFER_BIT": GL_COLOR_BUFFER_BIT,
+ "GL_NEAREST": GL_NEAREST,
+ "WId": WId,
+ "PySide2.QtGui.QPlatformSurface": int, # a handle
+ "QList< QTouchEvent.TouchPoint >()": [], # XXX improve?
+ "QPixmap()": Default("PySide2.QtGui.QPixmap"), # can't create without qApp
+ "PySide2.QtCore.uint8_t": int, # macOS 5.9
+ "zero(uint32_t)": 0,
+ "zero(PySide2.QtGui.QWindow)": None,
+ "zero(PySide2.QtGui.QOpenGLContext)": None,
+ "zero(PySide2.QtGui.QRegion)": None,
+ "zero(PySide2.QtGui.QPaintDevice)": None,
+ "zero(PySide2.QtGui.QTextLayout.FormatRange)": None,
+ "zero(PySide2.QtGui.QTouchDevice)": None,
+ "zero(PySide2.QtGui.QScreen)": None,
+ "PySide2.QtGui.QGenericMatrix": Missing("PySide2.QtGui.QGenericMatrix"),
+ })
+ return locals()
+
+
+def init_QtWidgets():
+ from PySide2.QtWidgets import QWidget, QMessageBox, QStyleOption, QStyleHintReturn, QStyleOptionComplex
+ from PySide2.QtWidgets import QGraphicsItem, QStyleOptionGraphicsItem # 5.9
+ type_map.update({
+ "QMessageBox.StandardButtons(Yes | No)": Instance(
+ "QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No)"),
+ "QWidget.RenderFlags(DrawWindowBackground | DrawChildren)": Instance(
+ "QWidget.RenderFlags(QWidget.DrawWindowBackground | QWidget.DrawChildren)"),
+ "static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)": Instance(
+ "Qt.MatchFlags(Qt.MatchExactly | Qt.MatchCaseSensitive)"),
+ "QVector< int >()": [],
+ "WId": WId,
+ # from 5.9
+ "Type": PySide2.QtWidgets.QListWidgetItem.Type,
+ "SO_Default": QStyleOption.SO_Default,
+ "SH_Default": QStyleHintReturn.SH_Default,
+ "SO_Complex": QStyleOptionComplex.SO_Complex,
+ "zero(PySide2.QtWidgets.QWidget)": None,
+ "zero(PySide2.QtWidgets.QGraphicsItem)": None,
+ "zero(PySide2.QtCore.QEvent)": None,
+ "zero(PySide2.QtWidgets.QStyleOption)": None,
+ "zero(PySide2.QtWidgets.QStyleHintReturn)": None,
+ "zero(PySide2.QtWidgets.QGraphicsLayoutItem)": None,
+ "zero(PySide2.QtWidgets.QListWidget)": None,
+ "zero(PySide2.QtGui.QKeySequence)": None,
+ "zero(PySide2.QtWidgets.QAction)": None,
+ "zero(PySide2.QtWidgets.QUndoCommand)": None,
+ "zero(WId)": 0,
+ })
+ return locals()
+
+
+def init_QtSql():
+ from PySide2.QtSql import QSqlDatabase
+ type_map.update({
+ "QLatin1String(defaultConnection)": QSqlDatabase.defaultConnection,
+ "QVariant.Invalid": Invalid("Variant"), # not sure what I should create, here...
+ })
+ return locals()
+
+
+def init_QtNetwork():
+ type_map.update({
+ "QMultiMap": MultiMap,
+ "zero(unsigned short)": 0,
+ "zero(PySide2.QtCore.QIODevice)": None,
+ "zero(QList)": [],
+ })
+ return locals()
+
+
+def init_QtXmlPatterns():
+ from PySide2.QtXmlPatterns import QXmlName
+ type_map.update({
+ "QXmlName.PrefixCode": Missing("PySide2.QtXmlPatterns.QXmlName.PrefixCode"),
+ "QXmlName.NamespaceCode": Missing("PySide2.QtXmlPatterns.QXmlName.NamespaceCode")
+ })
+ return locals()
+
+
+def init_QtMultimedia():
+ import PySide2.QtMultimediaWidgets
+ # Check if foreign import is valid. See mapping.py in shiboken2.
+ check_module(PySide2.QtMultimediaWidgets)
+ type_map.update({
+ "QGraphicsVideoItem": PySide2.QtMultimediaWidgets.QGraphicsVideoItem,
+ "QVideoWidget": PySide2.QtMultimediaWidgets.QVideoWidget,
+ })
+ return locals()
+
+
+def init_QtOpenGL():
+ type_map.update({
+ "GLuint": int,
+ "GLenum": int,
+ "GLint": int,
+ "GLbitfield": int,
+ "PySide2.QtOpenGL.GLint": int,
+ "PySide2.QtOpenGL.GLuint": int,
+ "GLfloat": float, # 5.6, MSVC 15
+ "zero(PySide2.QtOpenGL.QGLContext)": None,
+ "zero(GLenum)": 0,
+ "zero(PySide2.QtOpenGL.QGLWidget)": None,
+ })
+ return locals()
+
+
+def init_QtQml():
+ type_map.update({
+ "QJSValueList()": [],
+ "PySide2.QtQml.bool volatile": bool,
+ # from 5.9
+ "QVariantHash()": typing.Dict[str, Variant], # XXX sorted?
+ "zero(PySide2.QtQml.QQmlContext)": None,
+ "zero(PySide2.QtQml.QQmlEngine)": None,
+ })
+ return locals()
+
+
+def init_QtQuick():
+ type_map.update({
+ "PySide2.QtQuick.QSharedPointer": int,
+ "PySide2.QtCore.uint": int,
+ "T": int,
+ "zero(PySide2.QtQuick.QQuickItem)": None,
+ "zero(GLuint)": 0,
+ })
+ return locals()
+
+
+def init_QtScript():
+ type_map.update({
+ "QScriptValueList()": [],
+ })
+ return locals()
+
+
+def init_QtTest():
+ type_map.update({
+ "PySide2.QtTest.QTouchEventSequence": PySide2.QtTest.QTest.QTouchEventSequence,
+ })
+ return locals()
+
+# from 5.9
+def init_QtWebEngineWidgets():
+ type_map.update({
+ "zero(PySide2.QtWebEngineWidgets.QWebEnginePage.FindFlags)": 0,
+ })
+ return locals()
+
+# from 5.6, MSVC
+def init_QtWinExtras():
+ type_map.update({
+ "QList< QWinJumpListItem* >()": [],
+ })
+ return locals()
+
+# from 5.12, macOS
+def init_QtDataVisualization():
+ from PySide2.QtDataVisualization import QtDataVisualization
+ QtDataVisualization.QBarDataRow = typing.List[QtDataVisualization.QBarDataItem]
+ QtDataVisualization.QBarDataArray = typing.List[QtDataVisualization.QBarDataRow]
+ QtDataVisualization.QSurfaceDataRow = typing.List[QtDataVisualization.QSurfaceDataItem]
+ QtDataVisualization.QSurfaceDataArray = typing.List[QtDataVisualization.QSurfaceDataRow]
+ type_map.update({
+ "100.0f": 100.0,
+ })
+ return locals()
+
+
+def init_testbinding():
+ type_map.update({
+ "testbinding.PySideCPP2.TestObjectWithoutNamespace": testbinding.TestObjectWithoutNamespace,
+ })
+ return locals()
+
+# end of file
diff --git a/sources/shiboken2/shibokenmodule/support/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index 5c9a1e4f..09e78f1b 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -45,8 +45,8 @@ import warnings
import types
import keyword
import functools
-from signature_loader.mapping import (type_map, update_mapping, namespace,
- typing, _NotCalled)
+from shibokensupport.signature.mapping import (type_map, update_mapping,
+ namespace, typing, _NotCalled)
_DEBUG = False
LIST_KEYWORDS = False
diff --git a/sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json
index 491ae805..491ae805 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json
diff --git a/sources/shiboken2/shibokenmodule/support/signature/typing27.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py
index 5d1c6058..dba8f8c7 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/typing27.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py
@@ -3,7 +3,7 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
diff --git a/sources/shiboken2/shibokenmodule/support/signature/contextlib36.py b/sources/shiboken2/shibokenmodule/support/signature/contextlib36.py
deleted file mode 100644
index d416eef2..00000000
--- a/sources/shiboken2/shibokenmodule/support/signature/contextlib36.py
+++ /dev/null
@@ -1,472 +0,0 @@
-# This Python file uses the following encoding: utf-8
-# It has been edited by fix-complaints.py .
-
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-"""
-PSF LICENSE AGREEMENT FOR PYTHON 3.7.0
-
-1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and
- the Individual or Organization ("Licensee") accessing and otherwise using Python
- 3.7.0 software in source or binary form and its associated documentation.
-
-2. Subject to the terms and conditions of this License Agreement, PSF hereby
- grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
- analyze, test, perform and/or display publicly, prepare derivative works,
- distribute, and otherwise use Python 3.7.0 alone or in any derivative
- version, provided, however, that PSF's License Agreement and PSF's notice of
- copyright, i.e., "Copyright © 2001-2018 Python Software Foundation; All Rights
- Reserved" are retained in Python 3.7.0 alone or in any derivative version
- prepared by Licensee.
-
-3. In the event Licensee prepares a derivative work that is based on or
- incorporates Python 3.7.0 or any part thereof, and wants to make the
- derivative work available to others as provided herein, then Licensee hereby
- agrees to include in any such work a brief summary of the changes made to Python
- 3.7.0.
-
-4. PSF is making Python 3.7.0 available to Licensee on an "AS IS" basis.
- PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF
- EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR
- WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE
- USE OF PYTHON 3.7.0 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
-
-5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.7.0
- FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
- MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.7.0, OR ANY DERIVATIVE
- THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
-
-6. This License Agreement will automatically terminate upon a material breach of
- its terms and conditions.
-
-7. Nothing in this License Agreement shall be deemed to create any relationship
- of agency, partnership, or joint venture between PSF and Licensee. This License
- Agreement does not grant permission to use PSF trademarks or trade name in a
- trademark sense to endorse or promote products or services of Licensee, or any
- third party.
-
-8. By copying, installing or otherwise using Python 3.7.0, Licensee agrees
- to be bound by the terms and conditions of this License Agreement.
-"""
-
-"""Utilities for with-statement contexts. See PEP 343."""
-import abc
-import sys
-import _collections_abc
-from collections import deque
-from functools import wraps
-
-__all__ = ["contextmanager", "closing", "AbstractContextManager",
- "ContextDecorator", "ExitStack", "redirect_stdout",
- "redirect_stderr", "suppress"]
-
-
-class AbstractContextManager(abc.ABC):
-
- """An abstract base class for context managers."""
-
- def __enter__(self):
- """Return `self` upon entering the runtime context."""
- return self
-
- @abc.abstractmethod
- def __exit__(self, exc_type, exc_value, traceback):
- """Raise any exception triggered within the runtime context."""
- return None
-
- @classmethod
- def __subclasshook__(cls, C):
- if cls is AbstractContextManager:
- return _collections_abc._check_methods(C, "__enter__", "__exit__")
- return NotImplemented
-
-
-class ContextDecorator(object):
- "A base class or mixin that enables context managers to work as decorators."
-
- def _recreate_cm(self):
- """Return a recreated instance of self.
-
- Allows an otherwise one-shot context manager like
- _GeneratorContextManager to support use as
- a decorator via implicit recreation.
-
- This is a private interface just for _GeneratorContextManager.
- See issue #11647 for details.
- """
- return self
-
- def __call__(self, func):
- @wraps(func)
- def inner(*args, **kwds):
- with self._recreate_cm():
- return func(*args, **kwds)
- return inner
-
-
-class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
- """Helper for @contextmanager decorator."""
-
- def __init__(self, func, args, kwds):
- self.gen = func(*args, **kwds)
- self.func, self.args, self.kwds = func, args, kwds
- # Issue 19330: ensure context manager instances have good docstrings
- doc = getattr(func, "__doc__", None)
- if doc is None:
- doc = type(self).__doc__
- self.__doc__ = doc
- # Unfortunately, this still doesn't provide good help output when
- # inspecting the created context manager instances, since pydoc
- # currently bypasses the instance docstring and shows the docstring
- # for the class instead.
- # See http://bugs.python.org/issue19404 for more details.
-
- def _recreate_cm(self):
- # _GCM instances are one-shot context managers, so the
- # CM must be recreated each time a decorated function is
- # called
- return self.__class__(self.func, self.args, self.kwds)
-
- def __enter__(self):
- try:
- return next(self.gen)
- except StopIteration:
- raise RuntimeError("generator didn't yield") from None
-
- def __exit__(self, type, value, traceback):
- if type is None:
- try:
- next(self.gen)
- except StopIteration:
- return False
- else:
- raise RuntimeError("generator didn't stop")
- else:
- if value is None:
- # Need to force instantiation so we can reliably
- # tell if we get the same exception back
- value = type()
- try:
- self.gen.throw(type, value, traceback)
- except StopIteration as exc:
- # Suppress StopIteration *unless* it's the same exception that
- # was passed to throw(). This prevents a StopIteration
- # raised inside the "with" statement from being suppressed.
- return exc is not value
- except RuntimeError as exc:
- # Don't re-raise the passed in exception. (issue27122)
- if exc is value:
- return False
- # Likewise, avoid suppressing if a StopIteration exception
- # was passed to throw() and later wrapped into a RuntimeError
- # (see PEP 479).
- if type is StopIteration and exc.__cause__ is value:
- return False
- raise
- except:
- # only re-raise if it's *not* the exception that was
- # passed to throw(), because __exit__() must not raise
- # an exception unless __exit__() itself failed. But throw()
- # has to raise the exception to signal propagation, so this
- # fixes the impedance mismatch between the throw() protocol
- # and the __exit__() protocol.
- #
- if sys.exc_info()[1] is value:
- return False
- raise
- raise RuntimeError("generator didn't stop after throw()")
-
-
-def contextmanager(func):
- """@contextmanager decorator.
-
- Typical usage:
-
- @contextmanager
- def some_generator(<arguments>):
- <setup>
- try:
- yield <value>
- finally:
- <cleanup>
-
- This makes this:
-
- with some_generator(<arguments>) as <variable>:
- <body>
-
- equivalent to this:
-
- <setup>
- try:
- <variable> = <value>
- <body>
- finally:
- <cleanup>
-
- """
- @wraps(func)
- def helper(*args, **kwds):
- return _GeneratorContextManager(func, args, kwds)
- return helper
-
-
-class closing(AbstractContextManager):
- """Context to automatically close something at the end of a block.
-
- Code like this:
-
- with closing(<module>.open(<arguments>)) as f:
- <block>
-
- is equivalent to this:
-
- f = <module>.open(<arguments>)
- try:
- <block>
- finally:
- f.close()
-
- """
- def __init__(self, thing):
- self.thing = thing
- def __enter__(self):
- return self.thing
- def __exit__(self, *exc_info):
- self.thing.close()
-
-
-class _RedirectStream(AbstractContextManager):
-
- _stream = None
-
- def __init__(self, new_target):
- self._new_target = new_target
- # We use a list of old targets to make this CM re-entrant
- self._old_targets = []
-
- def __enter__(self):
- self._old_targets.append(getattr(sys, self._stream))
- setattr(sys, self._stream, self._new_target)
- return self._new_target
-
- def __exit__(self, exctype, excinst, exctb):
- setattr(sys, self._stream, self._old_targets.pop())
-
-
-class redirect_stdout(_RedirectStream):
- """Context manager for temporarily redirecting stdout to another file.
-
- # How to send help() to stderr
- with redirect_stdout(sys.stderr):
- help(dir)
-
- # How to write help() to a file
- with open('help.txt', 'w') as f:
- with redirect_stdout(f):
- help(pow)
- """
-
- _stream = "stdout"
-
-
-class redirect_stderr(_RedirectStream):
- """Context manager for temporarily redirecting stderr to another file."""
-
- _stream = "stderr"
-
-
-class suppress(AbstractContextManager):
- """Context manager to suppress specified exceptions
-
- After the exception is suppressed, execution proceeds with the next
- statement following the with statement.
-
- with suppress(FileNotFoundError):
- os.remove(somefile)
- # Execution still resumes here if the file was already removed
- """
-
- def __init__(self, *exceptions):
- self._exceptions = exceptions
-
- def __enter__(self):
- pass
-
- def __exit__(self, exctype, excinst, exctb):
- # Unlike isinstance and issubclass, CPython exception handling
- # currently only looks at the concrete type hierarchy (ignoring
- # the instance and subclass checking hooks). While Guido considers
- # that a bug rather than a feature, it's a fairly hard one to fix
- # due to various internal implementation details. suppress provides
- # the simpler issubclass based semantics, rather than trying to
- # exactly reproduce the limitations of the CPython interpreter.
- #
- # See http://bugs.python.org/issue12029 for more details
- return exctype is not None and issubclass(exctype, self._exceptions)
-
-
-# Inspired by discussions on http://bugs.python.org/issue13585
-class ExitStack(AbstractContextManager):
- """Context manager for dynamic management of a stack of exit callbacks
-
- For example:
-
- with ExitStack() as stack:
- files = [stack.enter_context(open(fname)) for fname in filenames]
- # All opened files will automatically be closed at the end of
- # the with statement, even if attempts to open files later
- # in the list raise an exception
-
- """
- def __init__(self):
- self._exit_callbacks = deque()
-
- def pop_all(self):
- """Preserve the context stack by transferring it to a new instance"""
- new_stack = type(self)()
- new_stack._exit_callbacks = self._exit_callbacks
- self._exit_callbacks = deque()
- return new_stack
-
- def _push_cm_exit(self, cm, cm_exit):
- """Helper to correctly register callbacks to __exit__ methods"""
- def _exit_wrapper(*exc_details):
- return cm_exit(cm, *exc_details)
- _exit_wrapper.__self__ = cm
- self.push(_exit_wrapper)
-
- def push(self, exit):
- """Registers a callback with the standard __exit__ method signature
-
- Can suppress exceptions the same way __exit__ methods can.
-
- Also accepts any object with an __exit__ method (registering a call
- to the method instead of the object itself)
- """
- # We use an unbound method rather than a bound method to follow
- # the standard lookup behavior for special methods
- _cb_type = type(exit)
- try:
- exit_method = _cb_type.__exit__
- except AttributeError:
- # Not a context manager, so assume its a callable
- self._exit_callbacks.append(exit)
- else:
- self._push_cm_exit(exit, exit_method)
- return exit # Allow use as a decorator
-
- def callback(self, callback, *args, **kwds):
- """Registers an arbitrary callback and arguments.
-
- Cannot suppress exceptions.
- """
- def _exit_wrapper(exc_type, exc, tb):
- callback(*args, **kwds)
- # We changed the signature, so using @wraps is not appropriate, but
- # setting __wrapped__ may still help with introspection
- _exit_wrapper.__wrapped__ = callback
- self.push(_exit_wrapper)
- return callback # Allow use as a decorator
-
- def enter_context(self, cm):
- """Enters the supplied context manager
-
- If successful, also pushes its __exit__ method as a callback and
- returns the result of the __enter__ method.
- """
- # We look up the special methods on the type to match the with statement
- _cm_type = type(cm)
- _exit = _cm_type.__exit__
- result = _cm_type.__enter__(cm)
- self._push_cm_exit(cm, _exit)
- return result
-
- def close(self):
- """Immediately unwind the context stack"""
- self.__exit__(None, None, None)
-
- def __exit__(self, *exc_details):
- received_exc = exc_details[0] is not None
-
- # We manipulate the exception state so it behaves as though
- # we were actually nesting multiple with statements
- frame_exc = sys.exc_info()[1]
- def _fix_exception_context(new_exc, old_exc):
- # Context may not be correct, so find the end of the chain
- while 1:
- exc_context = new_exc.__context__
- if exc_context is old_exc:
- # Context is already set correctly (see issue 20317)
- return
- if exc_context is None or exc_context is frame_exc:
- break
- new_exc = exc_context
- # Change the end of the chain to point to the exception
- # we expect it to reference
- new_exc.__context__ = old_exc
-
- # Callbacks are invoked in LIFO order to match the behavior of
- # nested context managers
- suppressed_exc = False
- pending_raise = False
- while self._exit_callbacks:
- cb = self._exit_callbacks.pop()
- try:
- if cb(*exc_details):
- suppressed_exc = True
- pending_raise = False
- exc_details = (None, None, None)
- except:
- new_exc_details = sys.exc_info()
- # simulate the stack of exceptions by setting the context
- _fix_exception_context(new_exc_details[1], exc_details[1])
- pending_raise = True
- exc_details = new_exc_details
- if pending_raise:
- try:
- # bare "raise exc_details[1]" replaces our carefully
- # set-up context
- fixed_ctx = exc_details[1].__context__
- raise exc_details[1]
- except BaseException:
- exc_details[1].__context__ = fixed_ctx
- raise
- return received_exc and suppressed_exc
diff --git a/sources/shiboken2/shibokenmodule/support/signature/mapping.py b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
deleted file mode 100644
index d4c630ac..00000000
--- a/sources/shiboken2/shibokenmodule/support/signature/mapping.py
+++ /dev/null
@@ -1,347 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-"""
-mapping.py
-
-This module has the mapping from the pyside C-modules view of signatures
-to the Python representation.
-
-The PySide modules are not loaded in advance, but only after they appear
-in sys.modules. This minimizes the loading overhead.
-"""
-
-import sys
-import struct
-import os
-import pkgutil
-
-from signature_loader import typing
-from signature_loader.typing import TypeVar, Generic
-
-class ellipsis(object):
- def __repr__(self):
- return "..."
-
-ellipsis = ellipsis()
-StringList = typing.List[str]
-IntList = typing.List[int]
-Point = typing.Tuple[float, float]
-PointList = typing.List[Point]
-IntMatrix = typing.List[IntList]
-Variant = typing.Any
-ModelIndexList = typing.List[int]
-QImageCleanupFunction = typing.Callable
-
-# First time installing our own Pair type into typing.
-T = TypeVar('T')
-S = TypeVar('S')
-
-class Pair(Generic[T, S]):
- __module__ = "typing"
-
-typing.Pair = Pair
-
-
-# Building our own Char type, which is much nicer than
-# Char = typing.Union[str, int] # how do I model the limitation to 1 char?
-
-# Copied from the six module:
-def with_metaclass(meta, *bases):
- """Create a base class with a metaclass."""
- # This requires a bit of explanation: the basic idea is to make a dummy
- # metaclass for one level of class instantiation that replaces itself with
- # the actual metaclass.
- class metaclass(type):
-
- def __new__(cls, name, this_bases, d):
- return meta(name, bases, d)
-
- @classmethod
- def __prepare__(cls, name, this_bases):
- return meta.__prepare__(name, bases)
- return type.__new__(metaclass, 'temporary_class', (), {})
-
-class _CharMeta(type):
- def __repr__(self):
- return '%s.%s' % (self.__module__, self.__name__)
-
-
-class Char(with_metaclass(_CharMeta)):
- """
- From http://doc.qt.io/qt-5/qchar.html :
-
- In Qt, Unicode characters are 16-bit entities without any markup or
- structure. This class represents such an entity. It is lightweight,
- so it can be used everywhere. Most compilers treat it like an
- unsigned short.
-
- Here, we provide a simple implementation just to avoid long aliases.
- """
- __module__ = "typing"
-
- def __init__(self, code):
- if isinstance(code, int):
- self.code = code & 0xffff
- else:
- self.code = ord(code)
-
- def __add__(self, other):
- return chr(self.code) + other
-
- def __radd__(self, other):
- return other + chr(self.code)
-
- def __repr__(self):
- return "typing.Char({})".format(self.code)
-
-typing.Char = Char
-
-
-MultiMap = typing.DefaultDict[str, typing.List[str]]
-
-# ulong_max is only 32 bit on windows.
-ulong_max = 2*sys.maxsize+1 if len(struct.pack("L", 1)) != 4 else 0xffffffff
-ushort_max = 0xffff
-
-GL_COLOR_BUFFER_BIT = 0x00004000
-GL_NEAREST = 0x2600
-
-WId = int
-
-# from 5.9
-GL_TEXTURE_2D = 0x0DE1
-GL_RGBA = 0x1908
-
-
-class _NotCalled(str):
- """
- Wrap some text with semantics
-
- This class is wrapped around text in order to avoid calling it.
- There are three reasons for this:
-
- - some instances cannot be created since they are abstract,
- - some can only be created after qApp was created,
- - some have an ugly __repr__ with angle brackets in it.
-
- By using derived classes, good looking instances can be created
- which can be used to generate source code or .pyi files. When the
- real object is needed, the wrapper can simply be called.
- """
- def __repr__(self):
- suppress = "support.signature.typing27."
- text = self[len(suppress):] if self.startswith(suppress) else self
- return "{}({})".format(type(self).__name__, text)
-
- def __call__(self):
- from signature_loader.mapping import __dict__ as namespace
- text = self if self.endswith(")") else self + "()"
- return eval(text, namespace)
-
-USE_PEP563 = sys.version_info[:2] >= (3, 7)
-
-
-# Some types are abstract. They just show their name.
-class Virtual(_NotCalled):
- pass
-
-# Other types I simply could not find.
-class Missing(_NotCalled):
- if not USE_PEP563:
- # The string must be quoted, because the object does not exist.
- def __repr__(self):
- return '{}("{}")'.format(type(self).__name__, self)
-
-
-class Invalid(_NotCalled):
- pass
-
-# Helper types
-class Default(_NotCalled):
- pass
-
-
-class Instance(_NotCalled):
- pass
-
-
-class Reloader(object):
- """
- Reloder class
-
- This is a singleton class which provides the update function for the
- shiboken and PySide classes.
- """
- ## Note: We needed to rename shiboken2 in order to avoid a name clash.
- _uninitialized = "Shiboken minimal sample other smart".split()
- _prefixes = [""]
-
- def __init__(self):
- self.sys_module_count = 0
- self.uninitialized = self._uninitialized
-
- def update(self, g=None):
- """
- update is responsible to import all modules from shiboken and PySide
- which are already in sys.modules.
- The purpose is to follow all user imports without introducing new
- ones.
- This function is called by pyside_type_init to adapt imports
- when the number of imported modules has changed.
- """
- if self.sys_module_count == len(sys.modules):
- return
- self.sys_module_count = len(sys.modules)
- if g is None:
- g = globals()
- for mod_name in self.uninitialized[:]:
- for prefix in self._prefixes:
- import_name = prefix + mod_name
- if import_name in sys.modules:
- # check if this is a real module
- check_module(sys.modules[import_name])
- # module is real
- self.uninitialized.remove(mod_name)
- proc_name = "init_" + mod_name
- if proc_name in g:
- # Do the 'import {import_name}' first.
- # 'top' is PySide2 when we do 'import PySide.QtCore'
- # or Shiboken if we do 'import Shiboken'.
- # Convince yourself that these two lines below have the same
- # global effect as "import Shiboken" or "import PySide2.QtCore".
- top = __import__(import_name)
- g[top.__name__] = top
- # Modules are in place, we can update the type_map.
- g.update(g[proc_name]())
-
-def check_module(mod):
- # During a build, there exist the modules already as directories,
- # although the '*.so' was not yet created. This causes a problem
- # in Python 3, because it accepts folders as namespace modules
- # without enforcing an '__init__.py'.
- if not getattr(mod, "__file__", None) or os.path.isdir(mod.__file__):
- mod_name = mod.__name__
- raise ImportError("Module '{mod_name}' is at most a namespace!"
- .format(**locals()))
-
-
-update_mapping = Reloader().update
-type_map = {}
-namespace = globals() # our module's __dict__
-
-type_map.update({
- "QList": typing.List,
- "QVector": typing.List,
- "QSet": typing.Set,
- "QPair": Pair,
- })
-
-
-def init_Shiboken():
- type_map.update({
- "shiboken2.bool": bool,
- "size_t": int,
- "PyType": type,
- })
- return locals()
-
-
-def init_minimal():
- type_map.update({
- "MinBool": bool,
- })
- return locals()
-
-
-def init_sample():
- import datetime
- type_map.update({
- "double": float,
- "sample.int": int,
- "Complex": complex,
- "sample.OddBool": bool,
- "sample.bool": bool,
- "sample.PStr": str,
- "OddBool": bool,
- "PStr": str,
- "char": Char,
- "sample.char": Char,
- "sample.Point": Point,
- "sample.ObjectType": object,
- "std.string": str,
- "HANDLE": int,
- "Foo.HANDLE": int,
- "sample.Photon.TemplateBase": Missing("sample.Photon.TemplateBase"),
- "ObjectType.Identifier": Missing("sample.ObjectType.Identifier"),
- "zero(HANDLE)": 0,
- "Null": None,
- "zero(sample.ObjectType)": None,
- "std.size_t": int,
- 'Str("<unknown>")': "<unknown>",
- 'Str("<unk")': "<unk",
- 'Str("nown>")': "nown>",
- "zero(sample.ObjectModel)": None,
- "sample.unsigned char": Char,
- "sample.double": float,
- "zero(sample.bool)": False,
- "PyDate": datetime.date,
- "ZeroIn": 0,
- })
- return locals()
-
-
-def init_other():
- import numbers
- type_map.update({
- "other.Number": numbers.Number,
- "other.ExtendsNoImplicitConversion": Missing("other.ExtendsNoImplicitConversion"),
- })
- return locals()
-
-
-def init_smart():
- type_map.update({
- "smart.SharedPtr": Missing("smart.SharedPtr"), # bad object "SharedPtr<Obj >"
- })
- return locals()
-
-# end of file