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
15import warnings
16
17_SLOW_CRC32C_WARNING = (
18 "As the c extension couldn't be imported, `google-crc32c` is using a "
19 "pure python implementation that is significantly slower. If possible, "
20 "please configure a c build environment and compile the extension"
21)
22
23# Default to C extension implementation, falling back to pure Python.
24try:
25 # Pure-Python unit test sessions test python.py; cext is tested during wheel checks.
26 from google_crc32c import cext as impl # pragma: NO COVER
27
28 implementation = "c" # pragma: NO COVER
29except ImportError:
30 from google_crc32c import python as impl # type: ignore
31
32 warnings.warn(_SLOW_CRC32C_WARNING, RuntimeWarning)
33 implementation = "python"
34
35extend = impl.extend
36value = impl.value
37
38Checksum = impl.Checksum
39
40__all__ = ["extend", "value", "Checksum", "implementation"]