google-crc32c 1.3.0__tar.gz → 1.6.0.dev2__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 (22) hide show
  1. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/LICENSE +2 -1
  2. {google-crc32c-1.3.0/src/google_crc32c.egg-info → google_crc32c-1.6.0.dev2}/PKG-INFO +65 -66
  3. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/README.md +8 -10
  4. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/setup.cfg +35 -34
  5. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/setup.py +1 -1
  6. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/__config__.py +8 -5
  7. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/__init__.py +1 -1
  8. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/_checksum.py +1 -0
  9. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/cext.py +3 -3
  10. google_crc32c-1.6.0.dev2/src/google_crc32c/py.typed +2 -0
  11. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2/src/google_crc32c.egg-info}/PKG-INFO +65 -66
  12. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c.egg-info/SOURCES.txt +3 -1
  13. google_crc32c-1.6.0.dev2/src/google_crc32c.egg-info/requires.txt +6 -0
  14. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c.egg-info/zip-safe +1 -1
  15. google_crc32c-1.6.0.dev2/tests/test___init__.py +286 -0
  16. google-crc32c-1.3.0/src/google_crc32c.egg-info/requires.txt +0 -3
  17. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/MANIFEST.in +0 -0
  18. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/pyproject.toml +0 -0
  19. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/_crc32c.c +0 -0
  20. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c/python.py +0 -0
  21. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c.egg-info/dependency_links.txt +0 -0
  22. {google-crc32c-1.3.0 → google_crc32c-1.6.0.dev2}/src/google_crc32c.egg-info/top_level.txt +0 -0
@@ -1,3 +1,4 @@
1
+
1
2
  Apache License
2
3
  Version 2.0, January 2004
3
4
  http://www.apache.org/licenses/
@@ -192,7 +193,7 @@
192
193
  you may not use this file except in compliance with the License.
193
194
  You may obtain a copy of the License at
194
195
 
195
- https://www.apache.org/licenses/LICENSE-2.0
196
+ http://www.apache.org/licenses/LICENSE-2.0
196
197
 
197
198
  Unless required by applicable law or agreed to in writing, software
198
199
  distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,66 +1,65 @@
1
- Metadata-Version: 2.1
2
- Name: google-crc32c
3
- Version: 1.3.0
4
- Summary: A python wrapper of the C library 'Google CRC32C'
5
- Home-page: https://github.com/googleapis/python-crc32c
6
- Author: Google LLC
7
- Author-email: googleapis-packages@google.com
8
- License: Apache 2.0
9
- Platform: Posix
10
- Platform: MacOS X
11
- Platform: Windows
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.6
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Requires-Python: >=3.6
23
- Description-Content-Type: text/markdown
24
- Provides-Extra: testing
25
- License-File: LICENSE
26
-
27
- # `google-crc32c`
28
- ![GA](https://img.shields.io/badge/support-GA-gold.svg) [<img src="https://img.shields.io/pypi/v/google-crc32c.svg">](https://pypi.org/project/google-crc32c) ![Python Versions](https://img.shields.io/pypi/pyversions/google-crc32c)
29
-
30
- This package wraps the [`google/crc32c`](https://github.com/google/crc32c)
31
- hardware-based implementation of the CRC32C hashing algorithm. Multiple wheels
32
- are distributed as well as source. If a wheel is not published for the python
33
- version and platform you are using, you will need to compile crc32c using a
34
- C toolchain.
35
-
36
- # Currently Published Wheels
37
-
38
- Wheels are currently published for Python 3.6, 3.7, 3.8, 3.9, 3.10, and
39
- pypy-3.7 for multiple architectures. For information on building your own,
40
- please view [BUILDING.md](BUILDING.md).
41
-
42
-
43
- ## Linux
44
-
45
- Wheels are published for the following platforms / architectures:
46
-
47
- - `manylinux2010` platform, `x86_64` and `1686` architectures
48
- - `manylinux2014` platform, `aarch64` architecture
49
-
50
- ### Deprecated
51
-
52
- - `manylinux1` platform, `x86_64` architecture wheels will be built until
53
- 2021-12-31, when the PyPA group drops support for the `manylinux1` image.
54
- See: https://github.com/pypa/manylinux/issues/994
55
-
56
-
57
- ## Mac OS
58
-
59
- Wheels are published for `x86_64` and `universal2` architectures.
60
-
61
-
62
- ## Windows
63
-
64
- Wheels are published for `win32` and `win_amd64` architectures.
65
-
66
-
1
+ Metadata-Version: 2.1
2
+ Name: google-crc32c
3
+ Version: 1.6.0.dev2
4
+ Summary: A python wrapper of the C library 'Google CRC32C'
5
+ Home-page: https://github.com/googleapis/python-crc32c
6
+ Author: Google LLC
7
+ Author-email: googleapis-packages@google.com
8
+ License: Apache 2.0
9
+ Platform: Posix
10
+ Platform: MacOS X
11
+ Platform: Windows
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Requires-Python: >=3.7
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: importlib_resources>=1.3; python_version < "3.9" and os_name == "nt"
27
+ Provides-Extra: testing
28
+ Requires-Dist: pytest; extra == "testing"
29
+
30
+ # `google-crc32c`
31
+ ![GA](https://img.shields.io/badge/support-GA-gold.svg) [<img src="https://img.shields.io/pypi/v/google-crc32c.svg">](https://pypi.org/project/google-crc32c) ![Python Versions](https://img.shields.io/pypi/pyversions/google-crc32c)
32
+
33
+ This package wraps the [`google/crc32c`](https://github.com/google/crc32c)
34
+ hardware-based implementation of the CRC32C hashing algorithm. Multiple wheels
35
+ are distributed as well as source. If a wheel is not published for the python
36
+ version and platform you are using, you will need to compile crc32c using a
37
+ C toolchain.
38
+
39
+ # Currently Published Wheels
40
+
41
+ Wheels are currently published for CPython 3.8, 3.9, 3.10, 3.11 and 3.12
42
+ for multiple architectures. PyPy 3.9 and 3.10 are also supported for Linux.
43
+ For information on building your own wheels please view [BUILDING.md](BUILDING.md).
44
+
45
+
46
+ ## Linux
47
+
48
+ Wheels are published for the following platforms / architectures:
49
+
50
+ - `manylinux2010` platform, `x86_64` and `1686` architectures
51
+ - `manylinux2014` platform, `aarch64` architecture
52
+
53
+ ### Unsupported Platforms
54
+
55
+ - `manylinux1` platform, `x86_64` architecture support has ended.
56
+ See https://github.com/pypa/manylinux/issues/994.
57
+
58
+ ## Mac OS
59
+
60
+ Wheels are published for `x86_64` and `arm64` architectures.
61
+
62
+
63
+ ## Windows
64
+
65
+ Wheels are published for the `win_amd64` architecture.
@@ -9,9 +9,9 @@ C toolchain.
9
9
 
10
10
  # Currently Published Wheels
11
11
 
12
- Wheels are currently published for Python 3.6, 3.7, 3.8, 3.9, 3.10, and
13
- pypy-3.7 for multiple architectures. For information on building your own,
14
- please view [BUILDING.md](BUILDING.md).
12
+ Wheels are currently published for CPython 3.8, 3.9, 3.10, 3.11 and 3.12
13
+ for multiple architectures. PyPy 3.9 and 3.10 are also supported for Linux.
14
+ For information on building your own wheels please view [BUILDING.md](BUILDING.md).
15
15
 
16
16
 
17
17
  ## Linux
@@ -21,18 +21,16 @@ Wheels are published for the following platforms / architectures:
21
21
  - `manylinux2010` platform, `x86_64` and `1686` architectures
22
22
  - `manylinux2014` platform, `aarch64` architecture
23
23
 
24
- ### Deprecated
25
-
26
- - `manylinux1` platform, `x86_64` architecture wheels will be built until
27
- 2021-12-31, when the PyPA group drops support for the `manylinux1` image.
28
- See: https://github.com/pypa/manylinux/issues/994
24
+ ### Unsupported Platforms
29
25
 
26
+ - `manylinux1` platform, `x86_64` architecture support has ended.
27
+ See https://github.com/pypa/manylinux/issues/994.
30
28
 
31
29
  ## Mac OS
32
30
 
33
- Wheels are published for `x86_64` and `universal2` architectures.
31
+ Wheels are published for `x86_64` and `arm64` architectures.
34
32
 
35
33
 
36
34
  ## Windows
37
35
 
38
- Wheels are published for `win32` and `win_amd64` architectures.
36
+ Wheels are published for the `win_amd64` architecture.
@@ -1,34 +1,35 @@
1
- [metadata]
2
- name = google-crc32c
3
- version = 1.3.0
4
- description = A python wrapper of the C library 'Google CRC32C'
5
- url = https://github.com/googleapis/python-crc32c
6
- long_description = file: README.md
7
- long_description_content_type = text/markdown
8
- author = Google LLC
9
- author_email = googleapis-packages@google.com
10
- license = Apache 2.0
11
- platforms = Posix, MacOS X, Windows
12
- classifiers =
13
- Development Status :: 4 - Beta
14
- Intended Audience :: Developers
15
- License :: OSI Approved :: Apache Software License
16
- Operating System :: OS Independent
17
- Programming Language :: Python :: 3
18
- Programming Language :: Python :: 3.6
19
- Programming Language :: Python :: 3.7
20
- Programming Language :: Python :: 3.8
21
- Programming Language :: Python :: 3.9
22
- Programming Language :: Python :: 3.10
23
-
24
- [options]
25
- zip_safe = True
26
- python_requires = >=3.6
27
-
28
- [options.extras_require]
29
- testing = pytest
30
-
31
- [egg_info]
32
- tag_build =
33
- tag_date = 0
34
-
1
+ [metadata]
2
+ name = google-crc32c
3
+ version = 1.6.0.dev2
4
+ description = A python wrapper of the C library 'Google CRC32C'
5
+ url = https://github.com/googleapis/python-crc32c
6
+ long_description = file: README.md
7
+ long_description_content_type = text/markdown
8
+ author = Google LLC
9
+ author_email = googleapis-packages@google.com
10
+ license = Apache 2.0
11
+ platforms = Posix, MacOS X, Windows
12
+ classifiers =
13
+ Development Status :: 4 - Beta
14
+ Intended Audience :: Developers
15
+ License :: OSI Approved :: Apache Software License
16
+ Operating System :: OS Independent
17
+ Programming Language :: Python :: 3
18
+ Programming Language :: Python :: 3.7
19
+ Programming Language :: Python :: 3.8
20
+ Programming Language :: Python :: 3.9
21
+ Programming Language :: Python :: 3.10
22
+ Programming Language :: Python :: 3.11
23
+ Programming Language :: Python :: 3.12
24
+
25
+ [options]
26
+ zip_safe = True
27
+ python_requires = >=3.7
28
+
29
+ [options.extras_require]
30
+ testing = pytest
31
+
32
+ [egg_info]
33
+ tag_build =
34
+ tag_date = 0
35
+
@@ -29,7 +29,6 @@ CRC32C_PURE_PYTHON = os.getenv("CRC32C_PURE_PYTHON") not in _FALSE_OPTIONS
29
29
 
30
30
 
31
31
  def copy_dll(build_lib):
32
- return # trying static build of C library.
33
32
  install_prefix = os.environ.get("CRC32C_INSTALL_PREFIX")
34
33
 
35
34
  if os.name == "nt" and install_prefix is not None:
@@ -107,6 +106,7 @@ def build_c_extension():
107
106
  package_dir={"": "src"},
108
107
  ext_modules=[module],
109
108
  cmdclass={"build_ext": BuildExtWithDLL},
109
+ install_requires=["importlib_resources>=1.3 ; python_version < '3.9' and os_name == 'nt'"],
110
110
  )
111
111
 
112
112
 
@@ -15,9 +15,6 @@
15
15
  import os
16
16
  import sys
17
17
 
18
- import pkg_resources
19
-
20
-
21
18
  def modify_path():
22
19
  """Modify the module search path."""
23
20
  # Only modify path on Windows.
@@ -29,9 +26,15 @@ def modify_path():
29
26
  return
30
27
 
31
28
  try:
32
- extra_dll_dir = pkg_resources.resource_filename("google_crc32c", "extra-dll")
29
+ try:
30
+ # Python 3.9+
31
+ from importlib.resources import files as _resources_files
32
+ except ImportError:
33
+ # Python 3.7 & 3.8
34
+ from importlib_resources import files as _resources_files # type: ignore
35
+ extra_dll_dir = str(_resources_files("google_crc32c") / "extra-dll")
33
36
  if os.path.isdir(extra_dll_dir):
34
- # Python 3.6, 3.7 use path
37
+ # Python 3.7 use path
35
38
  os.environ["PATH"] = path + os.pathsep + extra_dll_dir
36
39
  # Python 3.8+ uses add_dll_directory.
37
40
  if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
@@ -25,7 +25,7 @@ try:
25
25
  from google_crc32c import cext as impl
26
26
  implementation = "c"
27
27
  except ImportError as exc:
28
- from google_crc32c import python as impl
28
+ from google_crc32c import python as impl # type: ignore
29
29
  warnings.warn(_SLOW_CRC32C_WARNING, RuntimeWarning)
30
30
  implementation = "python"
31
31
 
@@ -24,6 +24,7 @@ class CommonChecksum(object):
24
24
  initial_value (Optional[bytes]): the initial chunk of data from
25
25
  which the CRC32C checksum is computed. Defaults to b''.
26
26
  """
27
+ __slots__ = ()
27
28
 
28
29
  def __init__(self, initial_value=b""):
29
30
  self._crc = 0
@@ -16,9 +16,9 @@ import struct
16
16
 
17
17
  # NOTE: ``__config__`` **must** be the first import because it (may)
18
18
  # modify the search path used to locate shared libraries.
19
- import google_crc32c.__config__
20
- from google_crc32c._crc32c import extend
21
- from google_crc32c._crc32c import value
19
+ import google_crc32c.__config__ # type: ignore
20
+ from google_crc32c._crc32c import extend # type: ignore
21
+ from google_crc32c._crc32c import value # type: ignore
22
22
  from google_crc32c._checksum import CommonChecksum
23
23
 
24
24
 
@@ -0,0 +1,2 @@
1
+ # Marker file for PEP 561.
2
+ # The google_crc32c package uses inline types.
@@ -1,66 +1,65 @@
1
- Metadata-Version: 2.1
2
- Name: google-crc32c
3
- Version: 1.3.0
4
- Summary: A python wrapper of the C library 'Google CRC32C'
5
- Home-page: https://github.com/googleapis/python-crc32c
6
- Author: Google LLC
7
- Author-email: googleapis-packages@google.com
8
- License: Apache 2.0
9
- Platform: Posix
10
- Platform: MacOS X
11
- Platform: Windows
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.6
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Requires-Python: >=3.6
23
- Description-Content-Type: text/markdown
24
- Provides-Extra: testing
25
- License-File: LICENSE
26
-
27
- # `google-crc32c`
28
- ![GA](https://img.shields.io/badge/support-GA-gold.svg) [<img src="https://img.shields.io/pypi/v/google-crc32c.svg">](https://pypi.org/project/google-crc32c) ![Python Versions](https://img.shields.io/pypi/pyversions/google-crc32c)
29
-
30
- This package wraps the [`google/crc32c`](https://github.com/google/crc32c)
31
- hardware-based implementation of the CRC32C hashing algorithm. Multiple wheels
32
- are distributed as well as source. If a wheel is not published for the python
33
- version and platform you are using, you will need to compile crc32c using a
34
- C toolchain.
35
-
36
- # Currently Published Wheels
37
-
38
- Wheels are currently published for Python 3.6, 3.7, 3.8, 3.9, 3.10, and
39
- pypy-3.7 for multiple architectures. For information on building your own,
40
- please view [BUILDING.md](BUILDING.md).
41
-
42
-
43
- ## Linux
44
-
45
- Wheels are published for the following platforms / architectures:
46
-
47
- - `manylinux2010` platform, `x86_64` and `1686` architectures
48
- - `manylinux2014` platform, `aarch64` architecture
49
-
50
- ### Deprecated
51
-
52
- - `manylinux1` platform, `x86_64` architecture wheels will be built until
53
- 2021-12-31, when the PyPA group drops support for the `manylinux1` image.
54
- See: https://github.com/pypa/manylinux/issues/994
55
-
56
-
57
- ## Mac OS
58
-
59
- Wheels are published for `x86_64` and `universal2` architectures.
60
-
61
-
62
- ## Windows
63
-
64
- Wheels are published for `win32` and `win_amd64` architectures.
65
-
66
-
1
+ Metadata-Version: 2.1
2
+ Name: google-crc32c
3
+ Version: 1.6.0.dev2
4
+ Summary: A python wrapper of the C library 'Google CRC32C'
5
+ Home-page: https://github.com/googleapis/python-crc32c
6
+ Author: Google LLC
7
+ Author-email: googleapis-packages@google.com
8
+ License: Apache 2.0
9
+ Platform: Posix
10
+ Platform: MacOS X
11
+ Platform: Windows
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Requires-Python: >=3.7
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: importlib_resources>=1.3; python_version < "3.9" and os_name == "nt"
27
+ Provides-Extra: testing
28
+ Requires-Dist: pytest; extra == "testing"
29
+
30
+ # `google-crc32c`
31
+ ![GA](https://img.shields.io/badge/support-GA-gold.svg) [<img src="https://img.shields.io/pypi/v/google-crc32c.svg">](https://pypi.org/project/google-crc32c) ![Python Versions](https://img.shields.io/pypi/pyversions/google-crc32c)
32
+
33
+ This package wraps the [`google/crc32c`](https://github.com/google/crc32c)
34
+ hardware-based implementation of the CRC32C hashing algorithm. Multiple wheels
35
+ are distributed as well as source. If a wheel is not published for the python
36
+ version and platform you are using, you will need to compile crc32c using a
37
+ C toolchain.
38
+
39
+ # Currently Published Wheels
40
+
41
+ Wheels are currently published for CPython 3.8, 3.9, 3.10, 3.11 and 3.12
42
+ for multiple architectures. PyPy 3.9 and 3.10 are also supported for Linux.
43
+ For information on building your own wheels please view [BUILDING.md](BUILDING.md).
44
+
45
+
46
+ ## Linux
47
+
48
+ Wheels are published for the following platforms / architectures:
49
+
50
+ - `manylinux2010` platform, `x86_64` and `1686` architectures
51
+ - `manylinux2014` platform, `aarch64` architecture
52
+
53
+ ### Unsupported Platforms
54
+
55
+ - `manylinux1` platform, `x86_64` architecture support has ended.
56
+ See https://github.com/pypa/manylinux/issues/994.
57
+
58
+ ## Mac OS
59
+
60
+ Wheels are published for `x86_64` and `arm64` architectures.
61
+
62
+
63
+ ## Windows
64
+
65
+ Wheels are published for the `win_amd64` architecture.
@@ -9,10 +9,12 @@ src/google_crc32c/__init__.py
9
9
  src/google_crc32c/_checksum.py
10
10
  src/google_crc32c/_crc32c.c
11
11
  src/google_crc32c/cext.py
12
+ src/google_crc32c/py.typed
12
13
  src/google_crc32c/python.py
13
14
  src/google_crc32c.egg-info/PKG-INFO
14
15
  src/google_crc32c.egg-info/SOURCES.txt
15
16
  src/google_crc32c.egg-info/dependency_links.txt
16
17
  src/google_crc32c.egg-info/requires.txt
17
18
  src/google_crc32c.egg-info/top_level.txt
18
- src/google_crc32c.egg-info/zip-safe
19
+ src/google_crc32c.egg-info/zip-safe
20
+ tests/test___init__.py
@@ -0,0 +1,6 @@
1
+
2
+ [:python_version < "3.9" and os_name == "nt"]
3
+ importlib_resources>=1.3
4
+
5
+ [testing]
6
+ pytest
@@ -0,0 +1,286 @@
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import functools
15
+ import itertools
16
+ from unittest import mock
17
+
18
+ import pytest # type: ignore
19
+
20
+ import google_crc32c
21
+
22
+ EMPTY = b""
23
+ EMPTY_CRC = 0x00000000
24
+
25
+ # From: https://tools.ietf.org/html/rfc3720#appendix-B.4
26
+ #
27
+ # 32 bytes of zeroes:
28
+ #
29
+ # Byte: 0 1 2 3
30
+ #
31
+ # 0: 00 00 00 00
32
+ # ...
33
+ # 28: 00 00 00 00
34
+ #
35
+ # CRC: aa 36 91 8a
36
+
37
+ ALL_ZEROS = b"\x00" * 32
38
+ ALL_ZEROS_CRC = 0x8A9136AA
39
+
40
+ # 32 bytes of ones:
41
+ #
42
+ # Byte: 0 1 2 3
43
+ #
44
+ # 0: ff ff ff ff
45
+ # ...
46
+ # 28: ff ff ff ff
47
+ #
48
+ # CRC: 43 ab a8 62
49
+
50
+ ALL_ONES = b"\xff" * 32
51
+ ALL_ONES_CRC = 0x62A8AB43
52
+
53
+ #
54
+ # 32 bytes of incrementing 00..1f:
55
+ #
56
+ # Byte: 0 1 2 3
57
+ #
58
+ # 0: 00 01 02 03
59
+ # ...
60
+ # 28: 1c 1d 1e 1f
61
+ #
62
+ # CRC: 4e 79 dd 46
63
+
64
+ INCREMENTING = bytes(range(32))
65
+ INCREMENTING_CRC = 0x46DD794E
66
+
67
+ #
68
+ # 32 bytes of decrementing 1f..00:
69
+ #
70
+ # Byte: 0 1 2 3
71
+ #
72
+ # 0: 1f 1e 1d 1c
73
+ # ...
74
+ # 28: 03 02 01 00
75
+ #
76
+ # CRC: 5c db 3f 11
77
+
78
+ DECREMENTING = bytes(reversed(range(32)))
79
+ DECREMENTING_CRC = 0x113FDB5C
80
+
81
+ #
82
+ # An iSCSI - SCSI Read (10) Command PDU
83
+ #
84
+ # Byte: 0 1 2 3
85
+ #
86
+ # 0: 01 c0 00 00
87
+ # 4: 00 00 00 00
88
+ # 8: 00 00 00 00
89
+ # 12: 00 00 00 00
90
+ # 16: 14 00 00 00
91
+ # 20: 00 00 04 00
92
+ # 24: 00 00 00 14
93
+ # 28: 00 00 00 18
94
+ # 32: 28 00 00 00
95
+ # 36: 00 00 00 00
96
+ # 40: 02 00 00 00
97
+ # 44: 00 00 00 00
98
+ #
99
+ # CRC: 56 3a 96 d9
100
+
101
+ ISCSI_SCSI_READ_10_COMMAND_PDU = [
102
+ 0x01,
103
+ 0xC0,
104
+ 0x00,
105
+ 0x00,
106
+ 0x00,
107
+ 0x00,
108
+ 0x00,
109
+ 0x00,
110
+ 0x00,
111
+ 0x00,
112
+ 0x00,
113
+ 0x00,
114
+ 0x00,
115
+ 0x00,
116
+ 0x00,
117
+ 0x00,
118
+ 0x14,
119
+ 0x00,
120
+ 0x00,
121
+ 0x00,
122
+ 0x00,
123
+ 0x00,
124
+ 0x04,
125
+ 0x00,
126
+ 0x00,
127
+ 0x00,
128
+ 0x00,
129
+ 0x14,
130
+ 0x00,
131
+ 0x00,
132
+ 0x00,
133
+ 0x18,
134
+ 0x28,
135
+ 0x00,
136
+ 0x00,
137
+ 0x00,
138
+ 0x00,
139
+ 0x00,
140
+ 0x00,
141
+ 0x00,
142
+ 0x02,
143
+ 0x00,
144
+ 0x00,
145
+ 0x00,
146
+ 0x00,
147
+ 0x00,
148
+ 0x00,
149
+ 0x00,
150
+ ]
151
+ ISCSI_LENGTH = len(ISCSI_SCSI_READ_10_COMMAND_PDU)
152
+ ISCSI_BYTES = bytes(ISCSI_SCSI_READ_10_COMMAND_PDU)
153
+ ISCSI_CRC = 0xD9963A56
154
+
155
+
156
+ def iscsi_chunks(chunksize):
157
+ for index in itertools.islice(range(ISCSI_LENGTH), 0, None, chunksize):
158
+ yield ISCSI_SCSI_READ_10_COMMAND_PDU[index : index + chunksize]
159
+
160
+
161
+ _EXPECTED = [
162
+ (EMPTY, EMPTY_CRC),
163
+ (ALL_ZEROS, ALL_ZEROS_CRC),
164
+ (ALL_ONES, ALL_ONES_CRC),
165
+ (INCREMENTING, INCREMENTING_CRC),
166
+ (DECREMENTING, DECREMENTING_CRC),
167
+ (ISCSI_SCSI_READ_10_COMMAND_PDU, ISCSI_CRC),
168
+ (ISCSI_BYTES, ISCSI_CRC),
169
+ ]
170
+
171
+
172
+ def test_extend_w_empty_chunk():
173
+ crc = 123
174
+ assert google_crc32c.extend(crc, b"") == crc
175
+
176
+
177
+ def test_extend_w_multiple_chunks():
178
+ crc = 0
179
+
180
+ for chunk in iscsi_chunks(7):
181
+ chunk_bytes = bytes(chunk)
182
+ crc = google_crc32c.extend(crc, chunk_bytes)
183
+
184
+ assert crc == ISCSI_CRC
185
+
186
+
187
+ def test_extend_w_reduce():
188
+ chunks = [bytes(chunk) for chunk in iscsi_chunks(3)]
189
+ assert functools.reduce(google_crc32c.extend, chunks, 0) == ISCSI_CRC
190
+
191
+
192
+ @pytest.mark.parametrize("chunk, expected", _EXPECTED)
193
+ def test_value(chunk, expected):
194
+ assert google_crc32c.value(bytes(chunk)) == expected
195
+
196
+
197
+ def pytest_generate_tests(metafunc):
198
+ if "_crc32c" in metafunc.fixturenames:
199
+ metafunc.parametrize("_crc32c", ["python", "cext"], indirect=True)
200
+
201
+ @pytest.fixture
202
+ def _crc32c(request):
203
+ if request.param == "python":
204
+ from google_crc32c import python
205
+ return python
206
+ elif request.param == "cext":
207
+ from google_crc32c import cext
208
+ return cext
209
+ else:
210
+ raise ValueError("invalid internal test config")
211
+
212
+
213
+ class TestChecksum(object):
214
+ @staticmethod
215
+ def test_ctor_defaults(_crc32c):
216
+ helper = google_crc32c.Checksum()
217
+ assert helper._crc == 0
218
+
219
+ @staticmethod
220
+ def test_ctor_explicit(_crc32c):
221
+ chunk = b"DEADBEEF"
222
+ helper = google_crc32c.Checksum(chunk)
223
+ assert helper._crc == google_crc32c.value(chunk)
224
+
225
+ @staticmethod
226
+ def test_update(_crc32c):
227
+ chunk = b"DEADBEEF"
228
+ helper = google_crc32c.Checksum()
229
+ helper.update(chunk)
230
+ assert helper._crc == google_crc32c.value(chunk)
231
+
232
+ @staticmethod
233
+ def test_update_w_multiple_chunks(_crc32c):
234
+ helper = google_crc32c.Checksum()
235
+
236
+ for index in itertools.islice(range(ISCSI_LENGTH), 0, None, 7):
237
+ chunk = ISCSI_SCSI_READ_10_COMMAND_PDU[index : index + 7]
238
+ helper.update(bytes(chunk))
239
+
240
+ assert helper._crc == ISCSI_CRC
241
+
242
+ @staticmethod
243
+ def test_digest_zero(_crc32c):
244
+ helper = google_crc32c.Checksum()
245
+ assert helper.digest() == b"\x00" * 4
246
+
247
+ @staticmethod
248
+ def test_digest_nonzero(_crc32c):
249
+ helper = google_crc32c.Checksum()
250
+ helper._crc = 0x01020304
251
+ assert helper.digest() == b"\x01\x02\x03\x04"
252
+
253
+ @staticmethod
254
+ def test_hexdigest_zero(_crc32c):
255
+ helper = google_crc32c.Checksum()
256
+ assert helper.hexdigest() == b"00" * 4
257
+
258
+ @staticmethod
259
+ def test_hexdigest_nonzero(_crc32c):
260
+ helper = google_crc32c.Checksum()
261
+ helper._crc = 0x091A3B2C
262
+ assert helper.hexdigest() == b"091a3b2c"
263
+
264
+ @staticmethod
265
+ def test_copy(_crc32c):
266
+ chunk = b"DEADBEEF"
267
+ helper = google_crc32c.Checksum(chunk)
268
+ clone = helper.copy()
269
+ before = helper._crc
270
+ helper.update(b"FACEDACE")
271
+ assert clone._crc == before
272
+
273
+ @staticmethod
274
+ @pytest.mark.parametrize("chunksize", [1, 3, 5, 7, 11, 13, ISCSI_LENGTH])
275
+ def test_consume_stream(_crc32c, chunksize):
276
+ helper = google_crc32c.Checksum()
277
+ expected = [bytes(chunk) for chunk in iscsi_chunks(chunksize)]
278
+ stream = mock.Mock(spec=["read"])
279
+ stream.read.side_effect = expected + [b""]
280
+
281
+ found = list(helper.consume(stream, chunksize))
282
+
283
+ assert helper._crc == ISCSI_CRC
284
+ assert found == expected
285
+ for call in stream.read.call_args_list:
286
+ assert call == mock.call(chunksize)
@@ -1,3 +0,0 @@
1
-
2
- [testing]
3
- pytest