|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2025, Oracle and/or its affiliates. |
| 3 | +# |
| 4 | +# This software is dual-licensed to you under the Universal Permissive License |
| 5 | +# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License |
| 6 | +# 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose |
| 7 | +# either license. |
| 8 | +# |
| 9 | +# If you elect to accept the software under the Apache License, Version 2.0, |
| 10 | +# the following applies: |
| 11 | +# |
| 12 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 13 | +# you may not use this file except in compliance with the License. |
| 14 | +# You may obtain a copy of the License at |
| 15 | +# |
| 16 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 17 | +# |
| 18 | +# Unless required by applicable law or agreed to in writing, software |
| 19 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 20 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | +# See the License for the specific language governing permissions and |
| 22 | +# limitations under the License. |
| 23 | +# ----------------------------------------------------------------------------- |
| 24 | + |
| 25 | +# ----------------------------------------------------------------------------- |
| 26 | +# base.py |
| 27 | +# |
| 28 | +# Contains base classes and methods that have no internal dependencies. |
| 29 | +# ----------------------------------------------------------------------------- |
| 30 | + |
| 31 | +from . import __name__ as MODULE_NAME |
| 32 | + |
| 33 | + |
| 34 | +# metaclass used by all oracledb classes; currently this only ensures that when |
| 35 | +# the class is displayed it only shows the overall module name instead of any |
| 36 | +# subpackage names |
| 37 | +class BaseMetaClass(type): |
| 38 | + |
| 39 | + def __new__(cls, name, bases, attrs): |
| 40 | + module_name = attrs["__module__"] |
| 41 | + qual_name = attrs["__qualname__"] |
| 42 | + if module_name.startswith(MODULE_NAME): |
| 43 | + module_name = MODULE_NAME |
| 44 | + attrs["_public_name"] = f"{module_name}.{qual_name}" |
| 45 | + return super().__new__(cls, name, bases, attrs) |
| 46 | + |
| 47 | + def __repr__(cls): |
| 48 | + return f"<class '{cls._public_name}'>" |
0 commit comments