cwrap 1.6.1__tar.gz → 1.6.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. cwrap-1.6.9/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
  2. cwrap-1.6.9/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  3. cwrap-1.6.9/.github/PULL_REQUEST_TEMPLATE.md +6 -0
  4. cwrap-1.6.9/.github/workflows/build.yml +73 -0
  5. {cwrap-1.6.1 → cwrap-1.6.9}/.gitignore +1 -1
  6. cwrap-1.6.9/CODE_OF_CONDUCT.md +76 -0
  7. cwrap-1.6.9/CONTRIBUTING.md +4 -0
  8. cwrap-1.6.9/PKG-INFO +45 -0
  9. cwrap-1.6.9/README.md +20 -0
  10. cwrap-1.6.9/SECURITY.md +18 -0
  11. {cwrap-1.6.1 → cwrap-1.6.9}/examples/map/ex_map.py +16 -14
  12. cwrap-1.6.9/pyproject.toml +64 -0
  13. cwrap-1.6.9/requirements.txt +2 -0
  14. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/__init__.py +25 -15
  15. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/basecclass.py +29 -31
  16. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/basecenum.py +21 -18
  17. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/basecvalue.py +35 -13
  18. cwrap-1.6.9/src/cwrap/cfile.py +109 -0
  19. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/clib.py +27 -25
  20. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/metacwrap.py +19 -12
  21. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap/prototype.py +106 -98
  22. cwrap-1.6.9/src/cwrap/version.py +16 -0
  23. cwrap-1.6.9/src/cwrap.egg-info/PKG-INFO +45 -0
  24. cwrap-1.6.9/src/cwrap.egg-info/SOURCES.txt +46 -0
  25. {cwrap-1.6.1 → cwrap-1.6.9}/tests/test_basecclass.py +4 -6
  26. {cwrap-1.6.1 → cwrap-1.6.9}/tests/test_basecenum.py +39 -11
  27. {cwrap-1.6.1 → cwrap-1.6.9}/tests/test_basecvalue.py +16 -18
  28. {cwrap-1.6.1 → cwrap-1.6.9}/tests/test_cfile.py +15 -14
  29. {cwrap-1.6.1 → cwrap-1.6.9}/tests/test_libc.py +13 -7
  30. cwrap-1.6.9/tests/test_prototype.py +28 -0
  31. cwrap-1.6.1/.travis.yml +0 -25
  32. cwrap-1.6.1/PKG-INFO +0 -31
  33. cwrap-1.6.1/README.md +0 -9
  34. cwrap-1.6.1/cwrap/cfile.py +0 -174
  35. cwrap-1.6.1/cwrap/version.py +0 -4
  36. cwrap-1.6.1/cwrap.egg-info/PKG-INFO +0 -31
  37. cwrap-1.6.1/cwrap.egg-info/SOURCES.txt +0 -41
  38. cwrap-1.6.1/cwrap.egg-info/requires.txt +0 -1
  39. cwrap-1.6.1/requirements.txt +0 -1
  40. cwrap-1.6.1/setup.py +0 -43
  41. cwrap-1.6.1/tests/test_metawrap.py +0 -121
  42. {cwrap-1.6.1 → cwrap-1.6.9}/GPL +0 -0
  43. {cwrap-1.6.1 → cwrap-1.6.9}/LICENSE +0 -0
  44. {cwrap-1.6.1 → cwrap-1.6.9}/debian/README.Debian +0 -0
  45. {cwrap-1.6.1 → cwrap-1.6.9}/debian/changelog +0 -0
  46. {cwrap-1.6.1 → cwrap-1.6.9}/debian/compat +0 -0
  47. {cwrap-1.6.1 → cwrap-1.6.9}/debian/control +0 -0
  48. {cwrap-1.6.1 → cwrap-1.6.9}/debian/copyright +0 -0
  49. {cwrap-1.6.1 → cwrap-1.6.9}/debian/docs +0 -0
  50. {cwrap-1.6.1 → cwrap-1.6.9}/debian/rules +0 -0
  51. {cwrap-1.6.1 → cwrap-1.6.9}/debian/source/format +0 -0
  52. {cwrap-1.6.1 → cwrap-1.6.9}/examples/map/ex_map.c +0 -0
  53. {cwrap-1.6.1 → cwrap-1.6.9}/examples/vecstr/ex_vecstr.c +0 -0
  54. {cwrap-1.6.1 → cwrap-1.6.9}/examples/vecstr/ex_vecstr.py +0 -0
  55. {cwrap-1.6.1 → cwrap-1.6.9}/redhat/cwrap.spec +0 -0
  56. {cwrap-1.6.1 → cwrap-1.6.9}/setup.cfg +0 -0
  57. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap.egg-info/dependency_links.txt +0 -0
  58. {cwrap-1.6.1 → cwrap-1.6.9/src}/cwrap.egg-info/top_level.txt +0 -0
  59. {cwrap-1.6.1 → cwrap-1.6.9}/tests/__init__.py +0 -0
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior
15
+
16
+ **Expected behavior**
17
+ A clear and concise description of what you expected to happen.
18
+
19
+ **Additional context**
20
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,6 @@
1
+ **Issue**
2
+ Resolves #my_issue
3
+
4
+
5
+ **Approach**
6
+ _Short description of the approach_
@@ -0,0 +1,73 @@
1
+ name: Python package
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - 'version-**'
8
+ tags: "*"
9
+ pull_request:
10
+
11
+ jobs:
12
+ build:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version: ['3.10', '3.11', '3.12', '3.13']
17
+ os: [ubuntu-latest, macos-latest, windows-latest]
18
+
19
+ runs-on: ${{ matrix.os }}
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ with:
24
+ fetch-depth: 0
25
+
26
+ - name: Set up Python ${{ matrix.python-version }}
27
+ uses: actions/setup-python@v5
28
+ with:
29
+ python-version: ${{ matrix.python-version }}
30
+
31
+ - name: Install dependencies
32
+ run: |
33
+ pip install .
34
+ pip install -r requirements.txt
35
+
36
+ - name: Test
37
+ run: |
38
+ pytest -sv tests
39
+
40
+ - name: Style
41
+ run: |
42
+ ruff check
43
+ ruff format --check
44
+
45
+
46
+ publish:
47
+ name: Publish to PyPI
48
+ runs-on: ubuntu-latest
49
+ needs: [build]
50
+
51
+ # If this is a tagged release
52
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
53
+
54
+ steps:
55
+ - uses: actions/checkout@v4
56
+ with:
57
+ fetch-depth: 0
58
+
59
+ - name: Set up Python 3.12
60
+ uses: actions/setup-python@v5
61
+ with:
62
+ python-version: 3.12
63
+
64
+ - name: Build wheel
65
+ run: |
66
+ pip install --upgrade pip build
67
+ python -m build
68
+
69
+ - name: Publish to PyPI
70
+ uses: pypa/gh-action-pypi-publish@v1.12.3
71
+ with:
72
+ user: __token__
73
+ password: ${{ secrets.pypi_password }}
@@ -89,4 +89,4 @@ ENV/
89
89
  .ropeproject
90
90
 
91
91
  # don't track setuptools-generated version
92
- cwrap/version.py
92
+ src/cwrap/version.py
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at . All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
@@ -0,0 +1,4 @@
1
+ # Contributing
2
+ _cwrap_ is deprecated and will not see any new features. However, issues and critical bug fixed are accepted still.
3
+
4
+ We require a unit tests for bug fix pull-requests.
cwrap-1.6.9/PKG-INFO ADDED
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.2
2
+ Name: cwrap
3
+ Version: 1.6.9
4
+ Summary: cwrap - ctypes blanket
5
+ Author-email: Equinor ASA <fg_sib-scout@equinor.com>
6
+ License: GPL-3.0
7
+ Project-URL: Repository, https://github.com/equinor/cwrap
8
+ Platform: all
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Other Environment
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
14
+ Classifier: Natural Language :: English
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+
26
+ # cwrap
27
+
28
+ cwrap is a Python wrapper around C code, building upon ctypes.
29
+
30
+ # Examples
31
+
32
+ See `examples/`
33
+
34
+ # Installing
35
+ ```
36
+ pip install cwrap
37
+ ```
38
+
39
+ # Running tests
40
+ Clone this repo and cd into it, then:
41
+
42
+ ```
43
+ pip install -r requirements.txt
44
+ python -m pytest -sv tests
45
+ ```
cwrap-1.6.9/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # cwrap
2
+
3
+ cwrap is a Python wrapper around C code, building upon ctypes.
4
+
5
+ # Examples
6
+
7
+ See `examples/`
8
+
9
+ # Installing
10
+ ```
11
+ pip install cwrap
12
+ ```
13
+
14
+ # Running tests
15
+ Clone this repo and cd into it, then:
16
+
17
+ ```
18
+ pip install -r requirements.txt
19
+ python -m pytest -sv tests
20
+ ```
@@ -0,0 +1,18 @@
1
+ # Security Policy
2
+
3
+ If you discover a security vulnerability in this project, please follow these steps to responsibly disclose it:
4
+
5
+ 1. **Do not** create a public GitHub issue for the vulnerability.
6
+ 2. Follow our guideline for Responsible Disclosure Policy at [https://www.equinor.com/about-us/csirt](https://www.equinor.com/about-us/csirt) to report the issue
7
+
8
+ The following information will help us triage your report more quickly:
9
+
10
+ - Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
11
+ - Full paths of source file(s) related to the manifestation of the issue
12
+ - The location of the affected source code (tag/branch/commit or direct URL)
13
+ - Any special configuration required to reproduce the issue
14
+ - Step-by-step instructions to reproduce the issue
15
+ - Proof-of-concept or exploit code (if possible)
16
+ - Impact of the issue, including how an attacker might exploit the issue
17
+
18
+ We prefer all communications to be in English.
@@ -6,28 +6,29 @@ from cwrap.clib import lib_name
6
6
  class ExMapPrototype(Prototype):
7
7
  _LIB_NAME = "ex_map"
8
8
 
9
- lib_file = lib_name( _LIB_NAME )
9
+ lib_file = lib_name(_LIB_NAME)
10
10
  if not lib_file:
11
- raise ImportError("Cannot find library " + _LIB_NAME )
12
- lib = ctypes.CDLL( lib_file , ctypes.RTLD_GLOBAL )
11
+ raise ImportError("Cannot find library " + _LIB_NAME)
12
+ lib = ctypes.CDLL(lib_file, ctypes.RTLD_GLOBAL)
13
13
 
14
- def __init__(self , prototype , bind = True):
15
- super(ExMapPrototype , self).__init__( ExMapPrototype.lib , prototype , bind = bind)
14
+ def __init__(self, prototype, bind=True):
15
+ super(ExMapPrototype, self).__init__(ExMapPrototype.lib, prototype, bind=bind)
16
16
 
17
17
 
18
18
  class ExMap(BaseCClass):
19
19
  """
20
20
  Super thin wrapper around a std::map<char*, int>.
21
21
  """
22
+
22
23
  TYPE_NAME = "ex_map"
23
24
 
24
- _alloc = ExMapPrototype("void* ex_map_alloc()", bind=False)
25
- _free = ExMapPrototype("void ex_map_free(ex_map)")
26
- _size = ExMapPrototype("int ex_map_size(ex_map)")
25
+ _alloc = ExMapPrototype("void* ex_map_alloc()", bind=False)
26
+ _free = ExMapPrototype("void ex_map_free(ex_map)")
27
+ _size = ExMapPrototype("int ex_map_size(ex_map)")
27
28
  _insert = ExMapPrototype("void ex_map_insert(ex_map, char*, int)")
28
- _find = ExMapPrototype("int ex_map_find(ex_map, char*)")
29
- _count = ExMapPrototype("int ex_map_count(ex_map, char*)")
30
- _at = ExMapPrototype("char* ex_map_get_key_at(ex_map, int)")
29
+ _find = ExMapPrototype("int ex_map_find(ex_map, char*)")
30
+ _count = ExMapPrototype("int ex_map_count(ex_map, char*)")
31
+ _at = ExMapPrototype("char* ex_map_get_key_at(ex_map, int)")
31
32
 
32
33
  def __init__(self):
33
34
  c_ptr = self._alloc()
@@ -49,20 +50,21 @@ class ExMap(BaseCClass):
49
50
  if key in self:
50
51
  return self._find(key)
51
52
  else:
52
- raise KeyError('Key %s not found in map' % key)
53
+ raise KeyError("Key %s not found in map" % key)
53
54
 
54
55
  def __str__(self):
55
56
  ks = self.keys()
56
57
  kv = ["'%s': %s" % (k, self[k]) for k in ks]
57
- return '{%s}' % (', '.join(kv))
58
+ return "{%s}" % (", ".join(kv))
58
59
 
59
60
  def free(self):
60
61
  self._free()
61
62
 
63
+
62
64
  em = ExMap()
63
65
  em["Abc"] = 42
64
66
  em["Jean-Paul"] = 3
65
- em["cwrap"] = 2
67
+ em["cwrap"] = 2
66
68
  em["jokva"] = 17
67
69
 
68
70
  if em["Abc"] != 42:
@@ -0,0 +1,64 @@
1
+ [build-system]
2
+ requires = ["setuptools", "setuptools_scm"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cwrap"
7
+ description = "cwrap - ctypes blanket"
8
+ authors = [
9
+ { name = "Equinor ASA", email = "fg_sib-scout@equinor.com" },
10
+ ]
11
+ requires-python = ">=3.10"
12
+ readme = "README.md"
13
+ license = { text = "GPL-3.0" }
14
+ classifiers=[
15
+ "Development Status :: 5 - Production/Stable",
16
+ "Environment :: Other Environment",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
20
+ "Natural Language :: English",
21
+ "Programming Language :: Python",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Software Development :: Libraries",
27
+ "Topic :: Utilities",
28
+ ]
29
+ dynamic = ["version"]
30
+ dependencies = []
31
+
32
+ [project.urls]
33
+ Repository = "https://github.com/equinor/cwrap"
34
+
35
+ [tool.setuptools]
36
+ package-dir = {"" = "src"}
37
+ platforms = ["all"]
38
+
39
+ [tool.setuptools_scm]
40
+ write_to = "src/cwrap/version.py"
41
+
42
+ [tool.ruff]
43
+ src = ["src"]
44
+ line-length = 88
45
+ exclude = ["examples"]
46
+
47
+ [tool.ruff.lint]
48
+ select = [
49
+ "W", # pycodestyle
50
+ "I", # isort
51
+ "B", # flake-8-bugbear
52
+ "SIM", # flake-8-simplify
53
+ "F", # pyflakes
54
+ "UP", # pyupgrade
55
+ "PL", # pylint
56
+ ]
57
+
58
+ ignore = ["PLW2901", # redefined-loop-name
59
+ "PLR2004", # magic-value-comparison
60
+ "PLR0915", # too-many-statements
61
+ "PLR0912", # too-many-branches
62
+ "PLR5501", # collapsible-else-if
63
+ "PLR0911", # too-many-return-statements
64
+ ]
@@ -0,0 +1,2 @@
1
+ pytest
2
+ ruff==0.9.2
@@ -28,26 +28,36 @@ the process of interacting with a C library:
28
28
  FILE pointer.
29
29
  """
30
30
 
31
- try: from .version import version as __version__
32
- except ImportError: __version__ = '0.0.0'
31
+ try:
32
+ from .version import version as __version__
33
+ except ImportError:
34
+ __version__ = "0.0.0"
33
35
 
34
- __author__ = 'Statoil ASA'
35
- __copyright__ = 'Copyright 2016, Statoil ASA'
36
+ __author__ = "Statoil ASA"
37
+ __copyright__ = "Copyright 2016, Statoil ASA"
36
38
  __credits__ = __author__
37
- __license__ = 'GPL'
39
+ __license__ = "GPL"
38
40
  __maintainer__ = __author__
39
- __email__ = 'fg_gpl@statoil.com'
40
- __status__ = 'Prototype'
41
+ __email__ = "fg_gpl@statoil.com"
42
+ __status__ = "Prototype"
41
43
 
42
44
  from .basecclass import BaseCClass
43
45
  from .basecenum import BaseCEnum
44
46
  from .basecvalue import BaseCValue
45
-
46
- from .cfile import CFILE, copen as open
47
- from .clib import load, lib_name
48
-
47
+ from .cfile import CFILE
48
+ from .cfile import copen as open
49
+ from .clib import lib_name, load
49
50
  from .metacwrap import MetaCWrap
50
- from .prototype import REGISTERED_TYPES, Prototype, PrototypeError
51
-
52
- __all__ = ['BaseCClass', 'BaseCEnum', 'BaseCValue', 'CFILE', 'open',
53
- 'MetaCWrap', 'Prototype', 'load', 'lib_name']
51
+ from .prototype import REGISTERED_TYPES, Prototype, PrototypeError # noqa
52
+
53
+ __all__ = [
54
+ "BaseCClass",
55
+ "BaseCEnum",
56
+ "BaseCValue",
57
+ "CFILE",
58
+ "open",
59
+ "MetaCWrap",
60
+ "Prototype",
61
+ "load",
62
+ "lib_name",
63
+ ]
@@ -14,16 +14,12 @@
14
14
  # See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
15
15
  # for more details.
16
16
 
17
- from __future__ import (absolute_import, division,
18
- print_function, unicode_literals)
19
-
20
- import six
21
-
22
17
  import ctypes
18
+
23
19
  from .metacwrap import MetaCWrap
24
20
 
25
- @six.add_metaclass(MetaCWrap)
26
- class BaseCClass(object):
21
+
22
+ class BaseCClass(metaclass=MetaCWrap):
27
23
  namespaces = {}
28
24
 
29
25
  def __init__(self, c_pointer, parent=None, is_reference=False):
@@ -31,25 +27,30 @@ class BaseCClass(object):
31
27
  raise ValueError("Must have a valid (not null) pointer value!")
32
28
 
33
29
  if c_pointer < 0:
34
- raise ValueError("The pointer value is negative! This may be correct, but usually is not!")
30
+ raise ValueError(
31
+ "The pointer value is negative! This may be correct, but usually is not!"
32
+ )
35
33
 
36
34
  self.__c_pointer = c_pointer
37
35
  self.__parent = parent
38
36
  self.__is_reference = is_reference
39
37
 
40
38
  def __new__(cls, *more, **kwargs):
41
- obj = super(BaseCClass, cls).__new__(cls)
39
+ obj = super().__new__(cls)
42
40
  obj.__c_pointer = None
43
41
  obj.__parent = None
44
42
  obj.__is_reference = False
45
43
 
46
44
  return obj
47
45
 
46
+ def is_initialized(self):
47
+ return self._address() is not None
48
+
48
49
  def _address(self):
49
50
  return self.__c_pointer
50
51
 
51
52
  def _ad_str(self):
52
- return 'at 0x%x' % self._address()
53
+ return f"at 0x{self._address():x}"
53
54
 
54
55
  @classmethod
55
56
  def from_param(cls, c_class_object):
@@ -58,14 +59,16 @@ class BaseCClass(object):
58
59
 
59
60
  if c_class_object is None:
60
61
  return ctypes.c_void_p()
61
- else:
62
- return ctypes.c_void_p(c_class_object.__c_pointer)
62
+
63
+ return ctypes.c_void_p(c_class_object.__c_pointer)
63
64
 
64
65
  @classmethod
65
66
  def createPythonObject(cls, c_pointer):
66
67
  if c_pointer is not None:
67
68
  new_obj = cls.__new__(cls)
68
- BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=None, is_reference=False)
69
+ BaseCClass.__init__(
70
+ new_obj, c_pointer=c_pointer, parent=None, is_reference=False
71
+ )
69
72
  return new_obj
70
73
  else:
71
74
  return None
@@ -74,7 +77,9 @@ class BaseCClass(object):
74
77
  def createCReference(cls, c_pointer, parent=None):
75
78
  if c_pointer is not None:
76
79
  new_obj = cls.__new__(cls)
77
- BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=parent, is_reference=True)
80
+ BaseCClass.__init__(
81
+ new_obj, c_pointer=c_pointer, parent=parent, is_reference=True
82
+ )
78
83
  return new_obj
79
84
  else:
80
85
  return None
@@ -87,7 +92,6 @@ class BaseCClass(object):
87
92
  self.__is_reference = True
88
93
  self.__parent = parent
89
94
 
90
-
91
95
  def setParent(self, parent=None):
92
96
  if self.__is_reference:
93
97
  self.__parent = parent
@@ -97,7 +101,7 @@ class BaseCClass(object):
97
101
  return self
98
102
 
99
103
  def isReference(self):
100
- """ @rtype: bool """
104
+ """@rtype: bool"""
101
105
  return self.__is_reference
102
106
 
103
107
  def parent(self):
@@ -110,7 +114,7 @@ class BaseCClass(object):
110
114
  if isinstance(other, BaseCClass):
111
115
  return self.__c_pointer == other.__c_pointer
112
116
  else:
113
- return super(BaseCClass , self) == other
117
+ return super() == other
114
118
 
115
119
  def __hash__(self):
116
120
  # Similar to last resort comparison; this returns the hash of the
@@ -120,37 +124,31 @@ class BaseCClass(object):
120
124
  def free(self):
121
125
  raise NotImplementedError("A BaseCClass requires a free method implementation!")
122
126
 
123
- def _create_repr(self, args = ''):
127
+ def _create_repr(self, args=""):
124
128
  """Representation on the form (e.g.) 'EclFile(...) at 0x1729'."""
125
- return "{0}({1}) {2}".format(self.__class__.__name__, args, self._ad_str())
129
+ return f"{self.__class__.__name__}({args}) {self._ad_str()}"
126
130
 
127
131
  def __repr__(self):
128
132
  """Representation on the form (e.g.) 'EclFile(...) at 0x1729'."""
129
133
  return self._create_repr()
130
134
 
131
135
  def __del__(self):
132
- if self.free is not None:
133
- if not self.__is_reference:
134
- # Important to check the c_pointer; in the case of failed object creation
135
- # we can have a Python object with c_pointer == None.
136
- if self.__c_pointer:
137
- self.free()
136
+ if self.free is not None and not self.__is_reference and self.__c_pointer:
137
+ # Important to check the c_pointer; in the case of failed object creation
138
+ # we can have a Python object with c_pointer == None.
139
+ self.free()
138
140
 
139
141
  def _invalidateCPointer(self):
140
142
  self.__c_pointer = None
141
143
 
142
-
143
144
  def __bool__(self):
144
145
  """The BaseCClass instance will evaluate to true if it is bound to an
145
146
  underlying C object, otherwise it will evaluate to False. More
146
147
  elaborate bool tests should be implemented in the derived
147
148
  class.
148
149
  """
149
- if self.__c_pointer:
150
- return True
151
- else:
152
- return False
153
150
 
151
+ return bool(self.__c_pointer)
154
152
 
155
153
  def __nonzero__(self):
156
- return self.__bool__( )
154
+ return self.__bool__()