Codebase list python-clickhouse-driver / 16ce94c
New upstream version 0.2.2 Federico Ceratto 2 years ago
80 changed file(s) with 8644 addition(s) and 688 deletion(s). Raw diff Collapse all Expand all
0 [run]
1 plugins = Cython.Coverage
2 source = clickhouse_driver
00 [flake8]
11 filename = *.py, *.pyx
22 per-file-ignores =
3 clickhouse_driver/columns/stringcolumn.pyx: E225, E226, E227, E999
3 clickhouse_driver/columns/largeint.pyx: E225, E226, E227, E999
44 clickhouse_driver/bufferedreader.pyx: E225, E226, E227, E999
55 clickhouse_driver/bufferedwriter.pyx: E225, E226, E227, E999
66 clickhouse_driver/varint.pyx: E225, E226, E227, E999
1818 **Versions**
1919
2020 - Version of package with the problem.
21 - ClickHouse server version. Version can be obtained by running `SELECT version()` query.
2122 - Python version.
00 env:
1 - VERSION=21.9.3.30
2 - VERSION=21.4.6.55
3 - VERSION=21.3.10.1
4 - VERSION=21.2.10.48
5 - VERSION=21.1.9.41
6 - VERSION=20.11.2.1
17 - VERSION=20.10.2.20
28 - VERSION=20.9.3.45
39 - VERSION=20.8.4.11
1319 - VERSION=19.8.3.8 # SimpleAggregateFunction
1420 - VERSION=19.3.3
1521 - VERSION=18.12.17
16 - VERSION=18.10.3
17 - VERSION=18.6.0
18 - VERSION=18.5.1
19 - VERSION=18.4.0
20 - VERSION=18.1.0
22 # - VERSION=18.10.3
23 # - VERSION=18.6.0
24 # - VERSION=18.5.1
25 # - VERSION=18.4.0
26 # - VERSION=18.1.0
2127 # - VERSION=1.1.54394
2228 # - VERSION=1.1.54390
2329 # - VERSION=1.1.54388
3945
4046 language: python
4147 python:
42 - "2.7"
4348 - "3.4"
4449 - "3.5"
4550 - "3.6"
4651 - "3.7"
4752 - "3.8"
48 - "3.9-dev"
49 - "pypy2.7-5.10.0"
53 - "3.9"
5054 - "pypy3.5"
5155 cache: pip
5256 services:
5357 - docker
5458 install:
59 - pip install --upgrade pip setuptools
60 # Check flake8 first
61 - pip install flake8 flake8-print
62 - flake8
63 - if [ ! -z $DOCKER_PASSWORD ] ; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin ; fi
5564 - docker run -e "TZ=Europe/Moscow" -d -p 127.0.0.1:9000:9000 --name test-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:$VERSION
5665 - docker run -d --entrypoint "/bin/sh" --name test-clickhouse-client --link test-clickhouse-server:clickhouse-server yandex/clickhouse-client:$VERSION -c 'while :; do sleep 1; done'
5766 - docker ps -a
6271 - sed -i 's/^host=localhost$/host=clickhouse-server/' setup.cfg
6372 # Make host think that clickhouse-server is localhost
6473 - echo '127.0.0.1 clickhouse-server' | sudo tee /etc/hosts > /dev/null
65 - pip install --upgrade pip setuptools
66 - pip install flake8 flake8-print coveralls cython
74 - pip install coveralls cython 'cryptography<3.3'
75 - if [ -z ${USE_NUMPY+x} ]; then pip uninstall -y numpy pandas; fi
6776 script:
68 - if [ -z ${USE_NUMPY+x} ]; then pip uninstall -y numpy pandas; fi
69 - flake8 && coverage run --source=clickhouse_driver setup.py test
77 # Enable cython tracing only for cpython
78 - if [ "$TRAVIS_PYTHON_VERSION" != "pypy3.5" ]; then CYTHON_TRACE=1 python setup.py build_ext --define CYTHON_TRACE ; fi
79 - coverage run setup.py test
7080 after_success:
7181 coveralls
7282
7686 - python: 3.4
7787 env: VERSION=20.3.20.6 USE_NUMPY=1
7888 - python: 3.9-dev
79 env: VERSION=20.3.20.6 USE_NUMPY=1
80 - python: pypy2.7-5.10.0
8189 env: VERSION=20.3.20.6 USE_NUMPY=1
8290 - python: pypy3.5
8391 env: VERSION=20.3.20.6 USE_NUMPY=1
94102 packages:
95103 - valgrind
96104 install:
105 - if [ ! -z $DOCKER_PASSWORD ] ; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin ; fi
97106 - docker run -e "TZ=Europe/Moscow" -d -p 127.0.0.1:9000:9000 --name test-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:$VERSION
98107 - docker run -d --entrypoint "/bin/sh" --name test-clickhouse-client --link test-clickhouse-server:clickhouse-server yandex/clickhouse-client:$VERSION -c 'while :; do sleep 1; done'
99108 - docker ps -a
124133
125134 install:
126135 - pip install --upgrade pip setuptools
127 - pip install cython cibuildwheel==1.6.4
136 - pip install cython cibuildwheel==1.11.0
128137
129138 script:
130139 - cibuildwheel --output-dir wheelhouse
131140
132141 env:
142 - CIBW_BUILD='*p3*'
133143 - CIBW_BEFORE_BUILD='pip install cython'
134144 deploy:
135145 name: Linux
145155 tags: true
146156
147157 - stage: wheels
148 name: Wheels for OS X Python 2
158 name: Wheels for Linux aarch64
159 arch: arm64
160 os: linux
161 language: python
162 python:
163 - "3.6"
164 install:
165 - pip install --upgrade pip setuptools
166 - pip install cython cibuildwheel==1.11.0
167
168 script:
169 - cibuildwheel --output-dir wheelhouse
170
171 env:
172 - CIBW_BUILD='*p3*'
173 - CIBW_BEFORE_BUILD='pip install cython'
174 deploy:
175 name: Linux aarch64
176 provider: releases
177 api_key: $GITHUB_TOKEN
178 file_glob: true
179 file: wheelhouse/*
180 skip_cleanup: true
181 draft: true
182 prerelease: true
183 overwrite: true
184 on:
185 tags: true
186
187 - stage: wheels
188 name: Wheels for OS X
149189 os: osx
150190 language: generic
151191
152192 install:
153193 - pip3 install --upgrade pip setuptools
154 - pip3 install cython cibuildwheel==1.4.0
155
156 script:
157 - cibuildwheel --output-dir wheelhouse
158
159 env:
160 - CIBW_BUILD='*p2*'
161 - CIBW_BEFORE_BUILD='pip install cython'
162 deploy:
163 name: Mac OS X
164 provider: releases
165 api_key: $GITHUB_TOKEN
166 file_glob: true
167 file: wheelhouse/*
168 skip_cleanup: true
169 draft: true
170 prerelease: true
171 overwrite: true
172 on:
173 tags: true
174
175 - stage: wheels
176 name: Wheels for OS X Python 3
177 os: osx
178 language: generic
179
180 install:
181 - pip3 install --upgrade pip setuptools
182 - pip3 install cython cibuildwheel==1.6.4
194 - pip3 install cython cibuildwheel==1.11.0
183195
184196 script:
185197 - cibuildwheel --output-dir wheelhouse
201213 tags: true
202214
203215 - stage: wheels
204 name: Wheels for Windows Python 2.7
216 name: Wheels for Windows
205217 os: windows
206218 language: shell
207219
208220 install:
209 - choco install python2 --version 2.7.16 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python27"
210 - choco install --ignore-dependencies vcpython27
211
212 script:
213 - C:/Python27/python -m pip install cibuildwheel==1.1.0 certifi
214 - export SSL_CERT_FILE=`C:/Python27/python -c "import certifi;print(certifi.where())"`
215 - echo $SSL_CERT_FILE
216 - C:/Python27/python -m cibuildwheel --platform windows --output-dir wheelhouse
217
218 env:
219 - CIBW_BUILD='cp27-win32'
220 - CIBW_BEFORE_BUILD='python -m pip install cython'
221 deploy:
222 name: Windows Python 2.7
223 provider: releases
224 api_key: $GITHUB_TOKEN
225 file_glob: true
226 file: wheelhouse/*
227 skip_cleanup: true
228 draft: true
229 prerelease: true
230 overwrite: true
231 on:
232 tags: true
233
234 - stage: wheels
235 name: Wheels for Windows Python 2.7 x64
236 os: windows
237 language: shell
238
239 install:
240 - choco install python2 --version 2.7.16 --sidebyside -y --force --params "/InstallDir:C:\Python27-x64"
241 - choco install --ignore-dependencies vcpython27
242
243 - export PATH="C:\\Program Files (x86)\\common files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\bin\\amd64;$PATH"
244 - export INCLUDE="C:\\Program Files (x86)\\common files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Include;C:\\Program Files (x86)\\common files\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Include"
245 - export LIB="C:\\Program Files (x86)\\common files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Lib\\amd64;C:\\Program Files (x86)\\common files\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Lib\\x64"
246
247 script:
248 - C:/Python27-x64/python -m pip install cibuildwheel==1.1.0 certifi
249 - export SSL_CERT_FILE=`C:/Python27-x64/python -c "import certifi;print(certifi.where())"`
250 - echo $SSL_CERT_FILE
251 - C:/Python27-x64/python -m cibuildwheel --platform windows --output-dir wheelhouse
252
253 env:
254 - CIBW_BUILD='cp27-win_amd64'
255 - CIBW_BEFORE_BUILD='python -m pip install cython'
256 deploy:
257 name: Windows Python 2.7 x64
258 provider: releases
259 api_key: $GITHUB_TOKEN
260 file_glob: true
261 file: wheelhouse/*
262 skip_cleanup: true
263 draft: true
264 prerelease: true
265 overwrite: true
266 on:
267 tags: true
268
269 # - stage: wheels
270 # name: Wheels for Windows Python 3.4
271 # os: windows
272 # language: shell
273 #
274 # install:
275 # - choco install python3 --version 3.4.4.20180111 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python34"
276 # - export VS100COMNTOOLS="$VS140COMNTOOLS"
277 #
278 # script:
279 # - C:/Python34/python -m pip install cibuildwheel==1.1.0
280 # - C:/Python34/python -m cibuildwheel --platform windows --output-dir wheelhouse
281 #
282 # env:
283 # - CIBW_BUILD='cp34-win32'
284 # - CIBW_BEFORE_BUILD='python -m pip install cython'
285 # deploy:
286 # name: Windows Python 3.4
287 # provider: releases
288 # api_key: $GITHUB_TOKEN
289 # file_glob: true
290 # file: wheelhouse/*
291 # skip_cleanup: true
292 # draft: true
293 # prerelease: true
294 # overwrite: true
295 # on:
296 # tags: true
297 #
298 # - stage: wheels
299 # name: Wheels for Windows Python 3.4 x64
300 # os: windows
301 # language: shell
302 #
303 # install:
304 # - choco install python3 --version 3.4.4.20180111 --sidebyside -y --force --params "/InstallDir:C:\Python34-x64"
305 # - export VS100COMNTOOLS="$VS140COMNTOOLS"
306 # - export PATH="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64;$PATH"
307 # - export INCLUDE="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\Include;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\ucrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\shared"
308 # - export LIB="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\LIB\\amd64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\ucrt\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\um\\x64"
309 #
310 # script:
311 # - C:/Python34-x64/python -m pip install cibuildwheel==1.1.0
312 # - C:/Python34-x64/python -m cibuildwheel --platform windows --output-dir wheelhouse
313 #
314 # env:
315 # - CIBW_BUILD='cp34-win_amd64'
316 # - CIBW_BEFORE_BUILD='python -m pip install cython'
317 # deploy:
318 # name: Windows Python 3.4 x64
319 # provider: releases
320 # api_key: $GITHUB_TOKEN
321 # file_glob: true
322 # file: wheelhouse/*
323 # skip_cleanup: true
324 # draft: true
325 # prerelease: true
326 # overwrite: true
327 # on:
328 # tags: true
329
330 - stage: wheels
331 name: Wheels for Windows Python 3
332 os: windows
333 language: shell
334
335 install:
336221 - choco install python3 --version 3.9.0 --params "/InstallDir:C:\Python39"
337222 script:
338 - C:/Python39/python -m pip install cibuildwheel==1.6.4
223 - C:/Python39/python -m pip install cibuildwheel==1.11.0
339224 - C:/Python39/python -m cibuildwheel --platform windows --output-dir wheelhouse
340225
341226 env:
362247 install:
363248 - choco install python3 --version 3.9.0 --params "/InstallDir:C:\Python39"
364249 script:
365 - C:/Python39/python -m pip install cibuildwheel==1.6.4
250 - C:/Python39/python -m pip install cibuildwheel==1.11.0
366251 - C:/Python39/python -m cibuildwheel --platform windows --output-dir wheelhouse
367252
368253 env:
00 # Changelog
1
2 ## Unreleased
3
4 ## [0.2.2] - 2021-10-24
5 ### Added
6 - DateTime64 extended range. Pull request [#222](https://github.com/mymarilyn/clickhouse-driver/pull/222) by [0x4ec7](https://github.com/0x4ec7).
7 - Support for using `Client` as context manager closing connection on exit. Solves issue [#237](https://github.com/mymarilyn/clickhouse-driver/issues/237). Pull request [#206](https://github.com/mymarilyn/clickhouse-driver/pull/238) by [wlhjason](https://github.com/wlhjason).
8 - OpenTelemetry support. Solves issue [#230](https://github.com/mymarilyn/clickhouse-driver/issues/230).
9 - `tzlocal`>=3.0 support.
10 - Date32 type.
11 - NumPy Nullable(T) support.
12
13 ### Fixed
14 - Boxing on DataFrames INSERT.
15 - Empty external tables sending. Solves issue [#240](https://github.com/mymarilyn/clickhouse-driver/issues/240).
16 - Create error message before disconnect. Pull request [#247](https://github.com/mymarilyn/clickhouse-driver/pull/247) by [NikiforovG](https://github.com/NikiforovG).
17 - Writing explicit NumPy `NaN` values. Solves issue [#249](https://github.com/mymarilyn/clickhouse-driver/issues/249).
18 - UInt128 INSERTing. Solves issue [#251](https://github.com/mymarilyn/clickhouse-driver/issues/251).
19 - Large DataFrames chunking. Solves issue [#243](https://github.com/mymarilyn/clickhouse-driver/issues/243).
20 - Allow arbitrary DataFrame columns order on INSERT. Solves issue [#245](https://github.com/mymarilyn/clickhouse-driver/issues/245).
21
22 ### Changed
23 - Protocol version bumped to 54442.
24 - Unpin `lz4` for CPython. Pin `lz4`<=3.0.1 only for PyPy.
25
26 ### Removed
27 - `transpose` parameter from `insert_dataframe`.
28
29 ## [0.2.1] - 2021-06-02
30 ### Added
31 - Linux wheels for AArch64. Pull request [#197](https://github.com/mymarilyn/clickhouse-driver/pull/197) by [odidev](https://github.com/odidev).
32 - [U]Int28/256 types.
33 - Decimal256 type.
34 - Code coverage for cython code.
35 - Map type.
36 - Support for private key/certificate file. Pull request [#219](https://github.com/mymarilyn/clickhouse-driver/pull/219) by [alexole](https://github.com/alexole).
37
38 ### Fixed
39 - Empty Array(Tuple(T)) writing. Solves issue [#177](https://github.com/mymarilyn/clickhouse-driver/issues/177).
40 - Preserve Decimal precision on INSERT. Solves issue [#192](https://github.com/mymarilyn/clickhouse-driver/issues/192).
41 - Remove closed cursors from connection. Solves issue [#194](https://github.com/mymarilyn/clickhouse-driver/issues/194).
42 - DB API connect with default params.
43 - Fix log blocks handling. Solves issue [#203](https://github.com/mymarilyn/clickhouse-driver/issues/203).
44 - Multidimensional Array decoding. Solves issue [#204](https://github.com/mymarilyn/clickhouse-driver/issues/204). Pull request [#206](https://github.com/mymarilyn/clickhouse-driver/pull/206) by [smagellan](https://github.com/smagellan).
45 - Use last database after reconnect. Solves issue [#205](https://github.com/mymarilyn/clickhouse-driver/issues/205).
46 - Decimal(N, 1) handling. Pull request [#210](https://github.com/mymarilyn/clickhouse-driver/pull/210) by [raw0w](https://github.com/raw0w).
47
48 ### Changed
49 - Decimal128 performance increased (up to 25% compared to 0.2.0 release).
50
51 ### Removed
52 - Python 2.7 support.
153
254 ## [0.2.0] - 2020-12-14
355 ### Added
3284 - `Client.from_url` credentials unquoting. Issue [#146](https://github.com/mymarilyn/clickhouse-driver/issues/146).
3385 - Empty nested array handling. Pull request [#161](https://github.com/mymarilyn/clickhouse-driver/pull/161) by [dourvaris](https://github.com/dourvaris).
3486 - `read_varint` overflow. Issue [#163](https://github.com/mymarilyn/clickhouse-driver/issues/163).
35 - Malformed reads/writes in `BufferedReader`.
87 - Malformed reads/writes in `BufferedReader`. This addresses [CVE-2020-26759](https://nvd.nist.gov/vuln/detail/CVE-2020-26759).
3688
3789 ### Changed
3890 - Use deque for ~4x speedup when reading Array columns. Pull request [#164](https://github.com/mymarilyn/clickhouse-driver/pull/164) by [dourvaris](https://github.com/dourvaris).
306358 - Date/DateTime types.
307359 - String types.
308360
309 [Unreleased]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.0...HEAD
361 [Unreleased]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.2...HEAD
362 [0.2.2]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.1...0.2.2
363 [0.2.1]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.0...0.2.1
310364 [0.2.0]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.5...0.2.0
311365 [0.1.5]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.4...0.1.5
312366 [0.1.4]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.3...0.1.4
3131
3232 - Compression support.
3333
34 - TLS support (since server version 1.1.54304).
34 - TLS support.
3535
3636 - Types support:
3737
3838 * Float32/64
39 * [U]Int8/16/32/64
40 * Date/DateTime('timezone')/DateTime64('timezone')
39 * [U]Int8/16/32/64/128/256
40 * Date/Date32/DateTime('timezone')/DateTime64('timezone')
4141 * String/FixedString(N)
4242 * Enum8/16
4343 * Array(T)
4949 * SimpleAggregateFunction(F, T)
5050 * Tuple(T1, T2, ...)
5151 * Nested
52 * Map(key, value)
5253
5354 - Query progress information.
5455
6162 - Multiple hosts support.
6263
6364 - Python DB API 2.0 specification support.
65
66 - Optional NumPy arrays support.
6467
6568 Documentation
6669 =============
22 from .dbapi import connect
33
44
5 VERSION = (0, 2, 0)
5 VERSION = (0, 2, 2)
66 __version__ = '.'.join(str(x) for x in VERSION)
77
88 __all__ = ['Client', 'connect']
131131
132132 @property
133133 def num_columns(self):
134 if self.columns_with_types is not None:
135 return len(self.columns_with_types)
136
134137 return len(self.data[0]) if self.num_rows else 0
135138
136139 @property
00 import re
11 import ssl
2 from contextlib import contextmanager
23 from time import time
34 import types
5 from urllib.parse import urlparse, parse_qs, unquote
46
57 from . import errors, defines
68 from .block import ColumnOrientedBlock, RowOrientedBlock
1012 from .result import (
1113 IterQueryResult, ProgressQueryResult, QueryResult, QueryInfo
1214 )
13 from .util.compat import urlparse, parse_qs, asbool, unquote
1415 from .util.escape import escape_params
15 from .util.helpers import column_chunks, chunks
16 from .util.helpers import column_chunks, chunks, asbool
1617
1718
1819 class Client(object):
2021 Client for communication with the ClickHouse server.
2122 Single connection is established per each connected instance of the client.
2223
23 :param settings: Dictionary of settings that passed to every query.
24 Defaults to ``None`` (no additional settings). See all
25 available settings in `ClickHouse docs
26 <https://clickhouse.yandex/docs/en/single/#settings>`_.
27
28 Driver's settings:
29
30 * insert_block_size -- chunk size to split rows for ``INSERT``.
24 :param settings: Dictionary of settings that passed to every query (except
25 for the client settings, see below). Defaults to ``None``
26 (no additional settings). See all available settings in
27 `ClickHouse docs
28 <https://clickhouse.tech/docs/en/operations/settings/settings/>`_.
29 :param \\**kwargs: All other args are passed to the
30 :py:class:`~clickhouse_driver.connection.Connection`
31 constructor.
32
33 The following keys when passed in ``settings`` are used for configuring the
34 client itself:
35
36 * ``insert_block_size`` -- chunk size to split rows for ``INSERT``.
3137 Defaults to ``1048576``.
32
33 * strings_as_bytes -- turns off string column encoding/decoding.
34
35 * strings_encoding -- specifies string encoding. UTF-8 by default.
36
37 * use_numpy -- Use numpy for columns reading. New in version *0.2.0*.
38
38 * ``strings_as_bytes`` -- turns off string column encoding/decoding.
39 * ``strings_encoding`` -- specifies string encoding. UTF-8 by default.
40 * ``use_numpy`` -- Use numpy for columns reading. New in version
41 *0.2.0*.
42 * ``opentelemetry_traceparent`` -- OpenTelemetry traceparent header as
43 described by W3C Trace Context recommendation.
44 New in version *0.2.2*.
45 * ``opentelemetry_tracestate`` -- OpenTelemetry tracestate header as
46 described by W3C Trace Context recommendation.
47 New in version *0.2.2*.
3948 """
4049
4150 available_client_settings = (
4251 'insert_block_size', # TODO: rename to max_insert_block_size
4352 'strings_as_bytes',
4453 'strings_encoding',
45 'use_numpy'
54 'use_numpy',
55 'opentelemetry_traceparent',
56 'opentelemetry_tracestate'
4657 )
4758
4859 def __init__(self, *args, **kwargs):
6071 ),
6172 'use_numpy': self.settings.pop(
6273 'use_numpy', False
74 ),
75 'opentelemetry_traceparent': self.settings.pop(
76 'opentelemetry_traceparent', None
77 ),
78 'opentelemetry_tracestate': self.settings.pop(
79 'opentelemetry_tracestate', ''
6380 )
6481 }
6582
85102 self.reset_last_query()
86103 super(Client, self).__init__()
87104
105 def __enter__(self):
106 return self
107
108 def __exit__(self, exc_type, exc_val, exc_tb):
109 self.disconnect()
110
88111 def disconnect(self):
89112 """
90113 Disconnects from the server.
182205 query_settings = self.settings.copy()
183206 query_settings.update(settings)
184207 self.connection.context.settings = query_settings
208
209 def track_current_database(self, query):
210 query = query.strip('; ')
211 if query.lower().startswith('use '):
212 self.connection.database = query[4:].strip()
213
214 @contextmanager
215 def disconnect_on_error(self, query):
216 try:
217 yield
218 self.track_current_database(query)
219
220 except (Exception, KeyboardInterrupt):
221 self.disconnect()
222 raise
185223
186224 def execute(self, query, params=None, with_column_types=False,
187225 external_tables=None, query_id=None, settings=None,
232270 self.connection.force_connect()
233271 self.last_query = QueryInfo()
234272
235 try:
273 with self.disconnect_on_error(query):
236274 # INSERT queries can use list/tuple/generator of list/tuples/dicts.
237275 # For SELECT parameters can be passed in only in dict right now.
238276 is_insert = isinstance(params, (list, tuple, types.GeneratorType))
252290 )
253291 self.last_query.store_elapsed(time() - start_time)
254292 return rv
255
256 except (Exception, KeyboardInterrupt):
257 self.disconnect()
258 raise
259293
260294 def execute_with_progress(
261295 self, query, params=None, with_column_types=False,
291325 self.connection.force_connect()
292326 self.last_query = QueryInfo()
293327
294 try:
328 with self.disconnect_on_error(query):
295329 return self.process_ordinary_query_with_progress(
296330 query, params=params, with_column_types=with_column_types,
297331 external_tables=external_tables, query_id=query_id,
298332 types_check=types_check, columnar=columnar
299333 )
300
301 except (Exception, KeyboardInterrupt):
302 self.disconnect()
303 raise
304334
305335 def execute_iter(
306336 self, query, params=None, with_column_types=False,
334364 self.connection.force_connect()
335365 self.last_query = QueryInfo()
336366
337 try:
367 with self.disconnect_on_error(query):
338368 return self.iter_process_ordinary_query(
339369 query, params=params, with_column_types=with_column_types,
340370 external_tables=external_tables,
341371 query_id=query_id, types_check=types_check
342372 )
343
344 except (Exception, KeyboardInterrupt):
345 self.disconnect()
346 raise
347373
348374 def query_dataframe(
349375 self, query, params=None, external_tables=None, query_id=None,
381407 )
382408
383409 def insert_dataframe(
384 self, query, dataframe, transpose=True, external_tables=None,
385 query_id=None, settings=None):
410 self, query, dataframe, external_tables=None, query_id=None,
411 settings=None):
386412 """
387413 *New in version 0.2.0.*
388414
390416
391417 :param query: query that will be send to server.
392418 :param dataframe: pandas DataFrame.
393 :param transpose: whether or not transpose DataFrame before sending.
394 This is necessary action as DataFrame can be sent in
395 columnar form. If DataFrame is already in columnar
396 form set this parameter to ``False``.
397 Defaults to ``True``.
398419 :param external_tables: external tables to send.
399420 Defaults to ``None`` (no external tables).
400421 :param query_id: the query identifier. If no query id specified
409430 except ImportError:
410431 raise RuntimeError('Extras for NumPy must be installed')
411432
412 frame = dataframe.transpose() if transpose else dataframe
413 columns = list(frame.values)
414
415 return self.execute(
416 query, columns, columnar=True, external_tables=external_tables,
417 query_id=query_id, settings=settings
418 )
433 start_time = time()
434 self.make_query_settings(settings)
435 self.connection.force_connect()
436 self.last_query = QueryInfo()
437
438 with self.disconnect_on_error(query):
439 self.connection.send_query(query, query_id=query_id)
440 self.connection.send_external_tables(external_tables)
441
442 sample_block = self.receive_sample_block()
443 rv = None
444 if sample_block:
445 columns = [x[0] for x in sample_block.columns_with_types]
446 data = [dataframe[column].values for column in columns]
447 rv = self.send_data(sample_block, data, columnar=True)
448 self.receive_end_of_query()
449
450 self.last_query.store_elapsed(time() - start_time)
451 return rv
419452
420453 def process_ordinary_query_with_progress(
421454 self, query, params=None, with_column_types=False,
645678 kwargs[name] = asbool(value)
646679 elif name == 'ssl_version':
647680 kwargs[name] = getattr(ssl, value)
648 elif name in ['ca_certs', 'ciphers']:
681 elif name in ['ca_certs', 'ciphers', 'keyfile', 'certfile']:
649682 kwargs[name] = value
650683 elif name == 'alt_hosts':
651684 kwargs['alt_hosts'] = value
22
33 from . import defines
44 from . import errors
5 from .opentelemetry import OpenTelemetryTraceContext
56 from .varint import write_varint
6 from .writer import write_binary_str, write_binary_uint8
7 from .writer import write_binary_str, write_binary_uint8, \
8 write_binary_uint64, write_binary_uint128
79
810
911 class ClientInfo(object):
3335
3436 quota_key = ''
3537
36 def __init__(self, client_name):
38 def __init__(self, client_name, context):
3739 self.query_kind = ClientInfo.QueryKind.NO_QUERY
3840
3941 try:
4244 self.os_user = ''
4345 self.client_hostname = socket.gethostname()
4446 self.client_name = client_name
47
48 self.client_trace_context = OpenTelemetryTraceContext(
49 context.client_settings['opentelemetry_traceparent'],
50 context.client_settings['opentelemetry_tracestate']
51 )
4552
4653 super(ClientInfo, self).__init__()
4754
7784
7885 if revision >= defines.DBMS_MIN_REVISION_WITH_VERSION_PATCH:
7986 write_varint(self.client_version_patch, fout)
87
88 if revision >= defines.DBMS_MIN_REVISION_WITH_OPENTELEMETRY:
89 if self.client_trace_context.trace_id is not None:
90 # Have OpenTelemetry header.
91 write_binary_uint8(1, fout)
92 write_binary_uint128(self.client_trace_context.trace_id, fout)
93 write_binary_uint64(self.client_trace_context.span_id, fout)
94 write_binary_str(self.client_trace_context.tracestate, fout)
95 write_binary_uint8(self.client_trace_context.trace_flags, fout)
96 else:
97 # Don't have OpenTelemetry header.
98 write_binary_uint8(0, fout)
0 from collections import deque
10 from itertools import chain
21 from struct import Struct
32
4645 self.nested_column = ArrayColumn(self.nested_column)
4746 self.nested_column.nullable = self.nullable
4847 self.nullable = False
49 return self._read(rows, buf)
48 return self._read(rows, buf)[0]
5049
5150 def _write_sizes(self, value, buf):
5251 nulls_map = []
8483 if isinstance(self.nested_column, ArrayColumn):
8584 value = list(chain.from_iterable(value))
8685
87 self.nested_column._write_data(value, buf)
86 if value:
87 self.nested_column._write_data(value, buf)
8888
8989 def _write_nulls_data(self, value, buf):
9090 if self.nullable:
109109 self.nested_column.write_state_prefix(buf)
110110
111111 def _read(self, size, buf):
112 q = deque()
113 q.appendleft((self, [size], 0))
112 slices_series = [[0, size]]
113 nested_column = self.nested_column
114114
115 slices_series = []
116 slices = []
115 cur_level_slice_size = size
116 cur_level_slice = None
117 while (isinstance(nested_column, ArrayColumn)):
118 if cur_level_slice is None:
119 cur_level_slice = [0]
120 ns = Struct('<{}Q'.format(cur_level_slice_size))
121 nested_sizes = ns.unpack(buf.read(ns.size))
122 cur_level_slice.extend(nested_sizes)
123 slices_series.append(cur_level_slice)
124 cur_level_slice = None
125 cur_level_slice_size = nested_sizes[-1] if len(nested_sizes) > 0 \
126 else 0
127 nested_column = nested_column.nested_column
117128
118 cur_depth = 0
119
129 n_items = cur_level_slice_size if size > 0 else 0
120130 nulls_map = None
121 nested_column = self.nested_column
122 n_items = 0
123
124 # Read and store info about slices.
125 while q:
126 column, sizes, depth = q.pop()
127
128 nested_column = column.nested_column
129
130 if cur_depth != depth:
131 cur_depth = depth
132
133 slices_series.append(slices)
134
135 # The last element in slice is index(number) of the last
136 # element in current level. On the last iteration this
137 # represents number of elements in fully flatten array.
138 n_items = slices[-1]
139 if nested_column.nullable:
140 nulls_map = self._read_nulls_map(n_items, buf)
141
142 slices = []
143
144 if isinstance(nested_column, ArrayColumn):
145 slices.append(0)
146 prev = 0
147 for size in sizes:
148 ns = Struct('<{}Q'.format(size - prev))
149 nested_sizes = ns.unpack(buf.read(ns.size))
150 slices.extend(nested_sizes)
151 prev = size
152
153 q.appendleft((nested_column, nested_sizes, cur_depth + 1))
131 if nested_column.nullable:
132 nulls_map = self._read_nulls_map(n_items, buf)
154133
155134 data = []
156135 if n_items:
33
44
55 epoch_start = date(1970, 1, 1)
6 epoch_end = date(2149, 6, 6)
7
8 epoch_start_date32 = date(1925, 1, 1)
9 epoch_end_date32 = date(2283, 11, 11)
610
711
812 class DateColumn(FormatColumn):
1014 py_types = (date, )
1115 format = 'H'
1216
13 epoch_start = epoch_start
14 epoch_end = date(2105, 12, 31)
17 min_value = epoch_start
18 max_value = epoch_end
1519
16 date_lut = {x: epoch_start + timedelta(x) for x in range(65535)}
20 date_lut_days = (epoch_end - epoch_start).days + 1
21 date_lut = {x: epoch_start + timedelta(x) for x in range(date_lut_days)}
1722 date_lut_reverse = {value: key for key, value in date_lut.items()}
1823
1924 def before_write_items(self, items, nulls_map=None):
2025 null_value = self.null_value
2126
2227 date_lut_reverse = self.date_lut_reverse
23 epoch_start = self.epoch_start
24 epoch_end = self.epoch_end
28 min_value = self.min_value
29 max_value = self.max_value
2530
2631 for i, item in enumerate(items):
2732 if nulls_map and nulls_map[i]:
3136 if type(item) != date:
3237 item = date(item.year, item.month, item.day)
3338
34 if item > epoch_end or item < epoch_start:
39 if min_value <= item <= max_value:
40 items[i] = date_lut_reverse[item]
41 else:
3542 items[i] = 0
36 else:
37 items[i] = date_lut_reverse[item]
3843
3944 def after_read_items(self, items, nulls_map=None):
4045 date_lut = self.date_lut
4651 (None if is_null else date_lut[items[i]])
4752 for i, is_null in enumerate(nulls_map)
4853 )
54
55
56 class Date32Column(DateColumn):
57 ch_type = 'Date32'
58 format = 'i'
59
60 min_value = epoch_start_date32
61 max_value = epoch_end_date32
62
63 date_lut_days = (epoch_end_date32 - epoch_start).days + 1
64 date_lut = {
65 x: epoch_start + timedelta(x)
66 for x in range((epoch_start_date32 - epoch_start).days, date_lut_days)
67 }
68 date_lut_reverse = {value: key for key, value in date_lut.items()}
00 from datetime import datetime
1 from time import mktime
21
32 from pytz import timezone as get_timezone, utc
43 from tzlocal import get_localzone
54
6 from ..util import compat
75 from .base import FormatColumn
8
96
107 EPOCH = datetime(1970, 1, 1, tzinfo=utc)
118
2017 self.offset_naive = offset_naive
2118 super(DateTimeColumn, self).__init__(**kwargs)
2219
23 def timestamp_py2(self, dt):
24 """Return POSIX timestamp as float"""
25 if dt.tzinfo is None:
26 return mktime((dt.year, dt.month, dt.day,
27 dt.hour, dt.minute, dt.second,
28 -1, -1, -1))
29 else:
30 return (dt - EPOCH).total_seconds()
31
3220 def after_read_items(self, items, nulls_map=None):
3321 tz = self.timezone
3422 fromts = datetime.fromtimestamp
6957 def before_write_items(self, items, nulls_map=None):
7058 timezone = self.timezone
7159 null_value = self.null_value
72 to_timestamp = datetime.timestamp if compat.PY3 else self.timestamp_py2
60 to_timestamp = datetime.timestamp
7361
7462 for i, item in enumerate(items):
7563 if nulls_map and nulls_map[i]:
9886
9987 class DateTime64Column(DateTimeColumn):
10088 ch_type = 'DateTime64'
101 format = 'Q'
89 format = 'q'
10290
10391 max_scale = 6
10492
10593 def __init__(self, scale=0, **kwargs):
10694 self.scale = scale
10795 super(DateTime64Column, self).__init__(**kwargs)
108
109 def timestamp_py2(self, dt):
110 """Return POSIX timestamp as float"""
111 if dt.tzinfo is None:
112 return mktime((dt.year, dt.month, dt.day,
113 dt.hour, dt.minute, dt.second,
114 -1, -1, -1)) + dt.microsecond / 1e6
115 else:
116 return (dt - EPOCH).total_seconds()
11796
11897 def after_read_items(self, items, nulls_map=None):
11998 scale = float(10 ** self.scale)
160139
161140 timezone = self.timezone
162141 null_value = self.null_value
163 to_timestamp = datetime.timestamp if compat.PY3 else self.timestamp_py2
142 to_timestamp = datetime.timestamp
164143
165144 for i, item in enumerate(items):
166145 if nulls_map and nulls_map[i]:
214193 else:
215194 if not context.settings.get('use_client_time_zone', False):
216195 try:
196 local_timezone = get_localzone().key
197 except AttributeError:
217198 local_timezone = get_localzone().zone
218199 except Exception:
219200 local_timezone = None
00 from decimal import Decimal, localcontext
11
2 from ..writer import MAX_UINT64, MAX_INT64
3 from ..util import compat
42 from .base import FormatColumn
53 from .exceptions import ColumnTypeMismatchException
4 from .intcolumn import Int128Column, Int256Column
65
76
87 class DecimalColumn(FormatColumn):
9 py_types = (Decimal, float) + compat.integer_types
8 py_types = (Decimal, float, int)
109 max_precision = None
1110 int_size = None
1211
2524 self.check_item = check_item
2625
2726 def after_read_items(self, items, nulls_map=None):
28 if self.scale > 1:
27 if self.scale >= 1:
2928 scale = 10 ** self.scale
3029
3130 if nulls_map is None:
4746 def before_write_items(self, items, nulls_map=None):
4847 null_value = self.null_value
4948
50 if self.scale > 1:
49 if self.scale >= 1:
5150 scale = 10 ** self.scale
5251
5352 for i, item in enumerate(items):
5453 if nulls_map and nulls_map[i]:
5554 items[i] = null_value
5655 else:
57 items[i] = int(Decimal(item) * scale)
56 items[i] = int(Decimal(str(item)) * scale)
5857
5958 else:
6059 for i, item in enumerate(items):
6160 if nulls_map and nulls_map[i]:
6261 items[i] = null_value
6362 else:
64 items[i] = int(Decimal(item))
63 items[i] = int(Decimal(str(item)))
6564
6665 # Override default precision to the maximum supported by underlying type.
6766 def _write_data(self, items, buf):
8988 int_size = 8
9089
9190
92 class Decimal128Column(DecimalColumn):
93 format = 'Q' # We manually deal with sign in read/write.
91 class Decimal128Column(DecimalColumn, Int128Column):
9492 max_precision = 38
95 int_size = 16
9693
97 def write_items(self, items, buf):
98 n_items = len(items)
9994
100 uint_64_pairs = [None] * 2 * n_items
101 for i, x in enumerate(items):
102 i2 = 2 * i
103
104 # Differs from write_binary_uint128.
105 # Lower 64 bits are written first.
106 if x >= 0:
107 uint_64_pairs[i2] = x & MAX_UINT64
108 uint_64_pairs[i2 + 1] = (x >> 64) & MAX_UINT64
109 else:
110 x = -x
111 uint_64_pairs[i2] = MAX_UINT64 - (x & MAX_UINT64) + 1
112 uint_64_pairs[i2 + 1] = MAX_UINT64 - ((x >> 64) & MAX_UINT64)
113
114 s = self.make_struct(2 * n_items)
115 buf.write(s.pack(*uint_64_pairs))
116
117 def read_items(self, n_items, buf):
118 # TODO: cythonize
119 s = self.make_struct(2 * n_items)
120 items = s.unpack(buf.read(s.size))
121
122 int_128_items = [None] * n_items
123 for i in range(n_items):
124 i2 = 2 * i
125 # Differs from read_binary_uint128.
126 # Lower 64 bits are read first.
127 if items[i2 + 1] > MAX_INT64:
128 int_128_items[i] = (
129 -((MAX_UINT64 - items[i2 + 1]) << 64) -
130 (MAX_UINT64 - items[i2]) - 1
131 )
132
133 else:
134 int_128_items[i] = (items[i2 + 1] << 64) + items[i2]
135
136 return tuple(int_128_items)
95 class Decimal256Column(DecimalColumn, Int256Column):
96 max_precision = 76
13797
13898
13999 def create_decimal_column(spec, column_options):
141101 precision, scale = int(precision), int(scale)
142102
143103 # Maximum precisions for underlying types are:
144 # Int32 9
145 # Int64 18
146 # Int128 38
104 # Int32 10**9
105 # Int64 10**18
106 # Int128 10**38
107 # Int256 10**76
147108 if precision <= 9:
148109 cls = Decimal32Column
149110 elif precision <= 18:
150111 cls = Decimal64Column
112 elif precision <= 38:
113 cls = Decimal128Column
151114 else:
152 cls = Decimal128Column
115 cls = Decimal256Column
153116
154117 return cls(precision, scale, **column_options)
00 from enum import Enum
11
22 from .. import errors
3 from ..util import compat
43 from .intcolumn import IntColumn
54
65
76 class EnumColumn(IntColumn):
8 py_types = (Enum, ) + compat.integer_types + compat.string_types
7 py_types = (Enum, int, str)
98
109 def __init__(self, enum_cls, **kwargs):
1110 self.enum_cls = enum_cls
2524
2625 # Check real enum value
2726 try:
28 if isinstance(source_value, compat.string_types):
27 if isinstance(source_value, str):
2928 items[i] = enum_cls[source_value].value
3029 else:
3130 items[i] = enum_cls(source_value).value
00 from ctypes import c_float
11
2 from ..util import compat
32 from .base import FormatColumn
43
54
65 class FloatColumn(FormatColumn):
7 py_types = (float, ) + compat.integer_types
6 py_types = (float, int)
87
98
109 class Float32Column(FloatColumn):
00
1 from ..util import compat
21 from .exceptions import ColumnTypeMismatchException
32 from .base import FormatColumn
3 from .largeint import (
4 int128_from_quads, int128_to_quads, uint128_from_quads, uint128_to_quads,
5 int256_from_quads, int256_to_quads, uint256_from_quads, uint256_to_quads
6 )
47
58
69 class IntColumn(FormatColumn):
7 py_types = compat.integer_types
10 py_types = (int, )
811 int_size = None
912
1013 def __init__(self, types_check=False, **kwargs):
9396 ch_type = 'UInt64'
9497 format = 'Q'
9598 int_size = 8
99
100
101 class LargeIntColumn(IntColumn):
102 format = 'Q' # We manually deal with sign in read/write.
103 factor = None
104
105 to_quads = None
106 from_quads = None
107
108 def write_items(self, items, buf):
109 n_items = len(items)
110
111 s = self.make_struct(self.factor * n_items)
112 uint_64_pairs = self.to_quads(items, n_items)
113
114 buf.write(s.pack(*uint_64_pairs))
115
116 def read_items(self, n_items, buf):
117 s = self.make_struct(self.factor * n_items)
118 items = s.unpack(buf.read(s.size))
119
120 return self.from_quads(items, n_items)
121
122
123 class Int128Column(LargeIntColumn):
124 ch_type = 'Int128'
125 int_size = 16
126 factor = 2
127
128 to_quads = int128_to_quads
129 from_quads = int128_from_quads
130
131
132 class UInt128Column(LargeIntColumn):
133 ch_type = 'UInt128'
134 int_size = 16
135 factor = 2
136
137 to_quads = uint128_to_quads
138 from_quads = uint128_from_quads
139
140
141 class Int256Column(LargeIntColumn):
142 ch_type = 'Int256'
143 int_size = 32
144 factor = 4
145
146 to_quads = int256_to_quads
147 from_quads = int256_from_quads
148
149
150 class UInt256Column(LargeIntColumn):
151 ch_type = 'UInt256'
152 int_size = 32
153 factor = 4
154
155 to_quads = uint256_to_quads
156 from_quads = uint256_from_quads
00 from ipaddress import IPv4Address, IPv6Address, AddressValueError
11
22 from .. import errors
3 from ..util import compat
43 from .exceptions import ColumnTypeMismatchException
54 from .stringcolumn import ByteFixedString
65 from .intcolumn import UInt32Column
87
98 class IPv4Column(UInt32Column):
109 ch_type = "IPv4"
11 py_types = compat.string_types + (IPv4Address, int)
10 py_types = (str, IPv4Address, int)
1211
1312 def __init__(self, types_check=False, **kwargs):
1413 # UIntColumn overrides before_write_item and check_item
6665
6766 class IPv6Column(ByteFixedString):
6867 ch_type = "IPv6"
69 py_types = compat.string_types + (IPv6Address, bytes)
68 py_types = (str, IPv6Address, bytes)
7069
7170 def __init__(self, types_check=False, **kwargs):
7271 super(IPv6Column, self).__init__(16, types_check=types_check, **kwargs)
0 /* Generated by Cython 0.29.21 */
1
2 /* BEGIN: Cython Metadata
3 {
4 "distutils": {
5 "depends": [],
6 "name": "clickhouse_driver.columns.largeint",
7 "sources": [
8 "clickhouse_driver/columns/largeint.pyx"
9 ]
10 },
11 "module_name": "clickhouse_driver.columns.largeint"
12 }
13 END: Cython Metadata */
14
15 #define PY_SSIZE_T_CLEAN
16 #include "Python.h"
17 #ifndef Py_PYTHON_H
18 #error Python headers needed to compile C extensions, please install development version of Python.
19 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
20 #error Cython requires Python 2.6+ or Python 3.3+.
21 #else
22 #define CYTHON_ABI "0_29_21"
23 #define CYTHON_HEX_VERSION 0x001D15F0
24 #define CYTHON_FUTURE_DIVISION 1
25 #include <stddef.h>
26 #ifndef offsetof
27 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
28 #endif
29 #if !defined(WIN32) && !defined(MS_WINDOWS)
30 #ifndef __stdcall
31 #define __stdcall
32 #endif
33 #ifndef __cdecl
34 #define __cdecl
35 #endif
36 #ifndef __fastcall
37 #define __fastcall
38 #endif
39 #endif
40 #ifndef DL_IMPORT
41 #define DL_IMPORT(t) t
42 #endif
43 #ifndef DL_EXPORT
44 #define DL_EXPORT(t) t
45 #endif
46 #define __PYX_COMMA ,
47 #ifndef HAVE_LONG_LONG
48 #if PY_VERSION_HEX >= 0x02070000
49 #define HAVE_LONG_LONG
50 #endif
51 #endif
52 #ifndef PY_LONG_LONG
53 #define PY_LONG_LONG LONG_LONG
54 #endif
55 #ifndef Py_HUGE_VAL
56 #define Py_HUGE_VAL HUGE_VAL
57 #endif
58 #ifdef PYPY_VERSION
59 #define CYTHON_COMPILING_IN_PYPY 1
60 #define CYTHON_COMPILING_IN_PYSTON 0
61 #define CYTHON_COMPILING_IN_CPYTHON 0
62 #undef CYTHON_USE_TYPE_SLOTS
63 #define CYTHON_USE_TYPE_SLOTS 0
64 #undef CYTHON_USE_PYTYPE_LOOKUP
65 #define CYTHON_USE_PYTYPE_LOOKUP 0
66 #if PY_VERSION_HEX < 0x03050000
67 #undef CYTHON_USE_ASYNC_SLOTS
68 #define CYTHON_USE_ASYNC_SLOTS 0
69 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
70 #define CYTHON_USE_ASYNC_SLOTS 1
71 #endif
72 #undef CYTHON_USE_PYLIST_INTERNALS
73 #define CYTHON_USE_PYLIST_INTERNALS 0
74 #undef CYTHON_USE_UNICODE_INTERNALS
75 #define CYTHON_USE_UNICODE_INTERNALS 0
76 #undef CYTHON_USE_UNICODE_WRITER
77 #define CYTHON_USE_UNICODE_WRITER 0
78 #undef CYTHON_USE_PYLONG_INTERNALS
79 #define CYTHON_USE_PYLONG_INTERNALS 0
80 #undef CYTHON_AVOID_BORROWED_REFS
81 #define CYTHON_AVOID_BORROWED_REFS 1
82 #undef CYTHON_ASSUME_SAFE_MACROS
83 #define CYTHON_ASSUME_SAFE_MACROS 0
84 #undef CYTHON_UNPACK_METHODS
85 #define CYTHON_UNPACK_METHODS 0
86 #undef CYTHON_FAST_THREAD_STATE
87 #define CYTHON_FAST_THREAD_STATE 0
88 #undef CYTHON_FAST_PYCALL
89 #define CYTHON_FAST_PYCALL 0
90 #undef CYTHON_PEP489_MULTI_PHASE_INIT
91 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
92 #undef CYTHON_USE_TP_FINALIZE
93 #define CYTHON_USE_TP_FINALIZE 0
94 #undef CYTHON_USE_DICT_VERSIONS
95 #define CYTHON_USE_DICT_VERSIONS 0
96 #undef CYTHON_USE_EXC_INFO_STACK
97 #define CYTHON_USE_EXC_INFO_STACK 0
98 #elif defined(PYSTON_VERSION)
99 #define CYTHON_COMPILING_IN_PYPY 0
100 #define CYTHON_COMPILING_IN_PYSTON 1
101 #define CYTHON_COMPILING_IN_CPYTHON 0
102 #ifndef CYTHON_USE_TYPE_SLOTS
103 #define CYTHON_USE_TYPE_SLOTS 1
104 #endif
105 #undef CYTHON_USE_PYTYPE_LOOKUP
106 #define CYTHON_USE_PYTYPE_LOOKUP 0
107 #undef CYTHON_USE_ASYNC_SLOTS
108 #define CYTHON_USE_ASYNC_SLOTS 0
109 #undef CYTHON_USE_PYLIST_INTERNALS
110 #define CYTHON_USE_PYLIST_INTERNALS 0
111 #ifndef CYTHON_USE_UNICODE_INTERNALS
112 #define CYTHON_USE_UNICODE_INTERNALS 1
113 #endif
114 #undef CYTHON_USE_UNICODE_WRITER
115 #define CYTHON_USE_UNICODE_WRITER 0
116 #undef CYTHON_USE_PYLONG_INTERNALS
117 #define CYTHON_USE_PYLONG_INTERNALS 0
118 #ifndef CYTHON_AVOID_BORROWED_REFS
119 #define CYTHON_AVOID_BORROWED_REFS 0
120 #endif
121 #ifndef CYTHON_ASSUME_SAFE_MACROS
122 #define CYTHON_ASSUME_SAFE_MACROS 1
123 #endif
124 #ifndef CYTHON_UNPACK_METHODS
125 #define CYTHON_UNPACK_METHODS 1
126 #endif
127 #undef CYTHON_FAST_THREAD_STATE
128 #define CYTHON_FAST_THREAD_STATE 0
129 #undef CYTHON_FAST_PYCALL
130 #define CYTHON_FAST_PYCALL 0
131 #undef CYTHON_PEP489_MULTI_PHASE_INIT
132 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
133 #undef CYTHON_USE_TP_FINALIZE
134 #define CYTHON_USE_TP_FINALIZE 0
135 #undef CYTHON_USE_DICT_VERSIONS
136 #define CYTHON_USE_DICT_VERSIONS 0
137 #undef CYTHON_USE_EXC_INFO_STACK
138 #define CYTHON_USE_EXC_INFO_STACK 0
139 #else
140 #define CYTHON_COMPILING_IN_PYPY 0
141 #define CYTHON_COMPILING_IN_PYSTON 0
142 #define CYTHON_COMPILING_IN_CPYTHON 1
143 #ifndef CYTHON_USE_TYPE_SLOTS
144 #define CYTHON_USE_TYPE_SLOTS 1
145 #endif
146 #if PY_VERSION_HEX < 0x02070000
147 #undef CYTHON_USE_PYTYPE_LOOKUP
148 #define CYTHON_USE_PYTYPE_LOOKUP 0
149 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
150 #define CYTHON_USE_PYTYPE_LOOKUP 1
151 #endif
152 #if PY_MAJOR_VERSION < 3
153 #undef CYTHON_USE_ASYNC_SLOTS
154 #define CYTHON_USE_ASYNC_SLOTS 0
155 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
156 #define CYTHON_USE_ASYNC_SLOTS 1
157 #endif
158 #if PY_VERSION_HEX < 0x02070000
159 #undef CYTHON_USE_PYLONG_INTERNALS
160 #define CYTHON_USE_PYLONG_INTERNALS 0
161 #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
162 #define CYTHON_USE_PYLONG_INTERNALS 1
163 #endif
164 #ifndef CYTHON_USE_PYLIST_INTERNALS
165 #define CYTHON_USE_PYLIST_INTERNALS 1
166 #endif
167 #ifndef CYTHON_USE_UNICODE_INTERNALS
168 #define CYTHON_USE_UNICODE_INTERNALS 1
169 #endif
170 #if PY_VERSION_HEX < 0x030300F0
171 #undef CYTHON_USE_UNICODE_WRITER
172 #define CYTHON_USE_UNICODE_WRITER 0
173 #elif !defined(CYTHON_USE_UNICODE_WRITER)
174 #define CYTHON_USE_UNICODE_WRITER 1
175 #endif
176 #ifndef CYTHON_AVOID_BORROWED_REFS
177 #define CYTHON_AVOID_BORROWED_REFS 0
178 #endif
179 #ifndef CYTHON_ASSUME_SAFE_MACROS
180 #define CYTHON_ASSUME_SAFE_MACROS 1
181 #endif
182 #ifndef CYTHON_UNPACK_METHODS
183 #define CYTHON_UNPACK_METHODS 1
184 #endif
185 #ifndef CYTHON_FAST_THREAD_STATE
186 #define CYTHON_FAST_THREAD_STATE 1
187 #endif
188 #ifndef CYTHON_FAST_PYCALL
189 #define CYTHON_FAST_PYCALL 1
190 #endif
191 #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
192 #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
193 #endif
194 #ifndef CYTHON_USE_TP_FINALIZE
195 #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
196 #endif
197 #ifndef CYTHON_USE_DICT_VERSIONS
198 #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
199 #endif
200 #ifndef CYTHON_USE_EXC_INFO_STACK
201 #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
202 #endif
203 #endif
204 #if !defined(CYTHON_FAST_PYCCALL)
205 #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
206 #endif
207 #if CYTHON_USE_PYLONG_INTERNALS
208 #include "longintrepr.h"
209 #undef SHIFT
210 #undef BASE
211 #undef MASK
212 #ifdef SIZEOF_VOID_P
213 enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
214 #endif
215 #endif
216 #ifndef __has_attribute
217 #define __has_attribute(x) 0
218 #endif
219 #ifndef __has_cpp_attribute
220 #define __has_cpp_attribute(x) 0
221 #endif
222 #ifndef CYTHON_RESTRICT
223 #if defined(__GNUC__)
224 #define CYTHON_RESTRICT __restrict__
225 #elif defined(_MSC_VER) && _MSC_VER >= 1400
226 #define CYTHON_RESTRICT __restrict
227 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
228 #define CYTHON_RESTRICT restrict
229 #else
230 #define CYTHON_RESTRICT
231 #endif
232 #endif
233 #ifndef CYTHON_UNUSED
234 # if defined(__GNUC__)
235 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
236 # define CYTHON_UNUSED __attribute__ ((__unused__))
237 # else
238 # define CYTHON_UNUSED
239 # endif
240 # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
241 # define CYTHON_UNUSED __attribute__ ((__unused__))
242 # else
243 # define CYTHON_UNUSED
244 # endif
245 #endif
246 #ifndef CYTHON_MAYBE_UNUSED_VAR
247 # if defined(__cplusplus)
248 template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
249 # else
250 # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
251 # endif
252 #endif
253 #ifndef CYTHON_NCP_UNUSED
254 # if CYTHON_COMPILING_IN_CPYTHON
255 # define CYTHON_NCP_UNUSED
256 # else
257 # define CYTHON_NCP_UNUSED CYTHON_UNUSED
258 # endif
259 #endif
260 #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
261 #ifdef _MSC_VER
262 #ifndef _MSC_STDINT_H_
263 #if _MSC_VER < 1300
264 typedef unsigned char uint8_t;
265 typedef unsigned int uint32_t;
266 #else
267 typedef unsigned __int8 uint8_t;
268 typedef unsigned __int32 uint32_t;
269 #endif
270 #endif
271 #else
272 #include <stdint.h>
273 #endif
274 #ifndef CYTHON_FALLTHROUGH
275 #if defined(__cplusplus) && __cplusplus >= 201103L
276 #if __has_cpp_attribute(fallthrough)
277 #define CYTHON_FALLTHROUGH [[fallthrough]]
278 #elif __has_cpp_attribute(clang::fallthrough)
279 #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
280 #elif __has_cpp_attribute(gnu::fallthrough)
281 #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
282 #endif
283 #endif
284 #ifndef CYTHON_FALLTHROUGH
285 #if __has_attribute(fallthrough)
286 #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
287 #else
288 #define CYTHON_FALLTHROUGH
289 #endif
290 #endif
291 #if defined(__clang__ ) && defined(__apple_build_version__)
292 #if __apple_build_version__ < 7000000
293 #undef CYTHON_FALLTHROUGH
294 #define CYTHON_FALLTHROUGH
295 #endif
296 #endif
297 #endif
298
299 #ifndef CYTHON_INLINE
300 #if defined(__clang__)
301 #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
302 #elif defined(__GNUC__)
303 #define CYTHON_INLINE __inline__
304 #elif defined(_MSC_VER)
305 #define CYTHON_INLINE __inline
306 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
307 #define CYTHON_INLINE inline
308 #else
309 #define CYTHON_INLINE
310 #endif
311 #endif
312
313 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
314 #define Py_OptimizeFlag 0
315 #endif
316 #define __PYX_BUILD_PY_SSIZE_T "n"
317 #define CYTHON_FORMAT_SSIZE_T "z"
318 #if PY_MAJOR_VERSION < 3
319 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
320 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
321 PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
322 #define __Pyx_DefaultClassType PyClass_Type
323 #else
324 #define __Pyx_BUILTIN_MODULE_NAME "builtins"
325 #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2
326 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
327 PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
328 #else
329 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
330 PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
331 #endif
332 #define __Pyx_DefaultClassType PyType_Type
333 #endif
334 #ifndef Py_TPFLAGS_CHECKTYPES
335 #define Py_TPFLAGS_CHECKTYPES 0
336 #endif
337 #ifndef Py_TPFLAGS_HAVE_INDEX
338 #define Py_TPFLAGS_HAVE_INDEX 0
339 #endif
340 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
341 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
342 #endif
343 #ifndef Py_TPFLAGS_HAVE_FINALIZE
344 #define Py_TPFLAGS_HAVE_FINALIZE 0
345 #endif
346 #ifndef METH_STACKLESS
347 #define METH_STACKLESS 0
348 #endif
349 #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
350 #ifndef METH_FASTCALL
351 #define METH_FASTCALL 0x80
352 #endif
353 typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
354 typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
355 Py_ssize_t nargs, PyObject *kwnames);
356 #else
357 #define __Pyx_PyCFunctionFast _PyCFunctionFast
358 #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
359 #endif
360 #if CYTHON_FAST_PYCCALL
361 #define __Pyx_PyFastCFunction_Check(func)\
362 ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
363 #else
364 #define __Pyx_PyFastCFunction_Check(func) 0
365 #endif
366 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
367 #define PyObject_Malloc(s) PyMem_Malloc(s)
368 #define PyObject_Free(p) PyMem_Free(p)
369 #define PyObject_Realloc(p) PyMem_Realloc(p)
370 #endif
371 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
372 #define PyMem_RawMalloc(n) PyMem_Malloc(n)
373 #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
374 #define PyMem_RawFree(p) PyMem_Free(p)
375 #endif
376 #if CYTHON_COMPILING_IN_PYSTON
377 #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
378 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
379 #else
380 #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
381 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
382 #endif
383 #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
384 #define __Pyx_PyThreadState_Current PyThreadState_GET()
385 #elif PY_VERSION_HEX >= 0x03060000
386 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
387 #elif PY_VERSION_HEX >= 0x03000000
388 #define __Pyx_PyThreadState_Current PyThreadState_GET()
389 #else
390 #define __Pyx_PyThreadState_Current _PyThreadState_Current
391 #endif
392 #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
393 #include "pythread.h"
394 #define Py_tss_NEEDS_INIT 0
395 typedef int Py_tss_t;
396 static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
397 *key = PyThread_create_key();
398 return 0;
399 }
400 static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
401 Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
402 *key = Py_tss_NEEDS_INIT;
403 return key;
404 }
405 static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
406 PyObject_Free(key);
407 }
408 static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
409 return *key != Py_tss_NEEDS_INIT;
410 }
411 static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
412 PyThread_delete_key(*key);
413 *key = Py_tss_NEEDS_INIT;
414 }
415 static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
416 return PyThread_set_key_value(*key, value);
417 }
418 static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
419 return PyThread_get_key_value(*key);
420 }
421 #endif
422 #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
423 #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
424 #else
425 #define __Pyx_PyDict_NewPresized(n) PyDict_New()
426 #endif
427 #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
428 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
429 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
430 #else
431 #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
432 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
433 #endif
434 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
435 #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
436 #else
437 #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
438 #endif
439 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
440 #define CYTHON_PEP393_ENABLED 1
441 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
442 0 : _PyUnicode_Ready((PyObject *)(op)))
443 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
444 #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
445 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
446 #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
447 #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
448 #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
449 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
450 #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
451 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
452 #else
453 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u))
454 #endif
455 #else
456 #define CYTHON_PEP393_ENABLED 0
457 #define PyUnicode_1BYTE_KIND 1
458 #define PyUnicode_2BYTE_KIND 2
459 #define PyUnicode_4BYTE_KIND 4
460 #define __Pyx_PyUnicode_READY(op) (0)
461 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
462 #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
463 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
464 #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
465 #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
466 #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
467 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
468 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
469 #endif
470 #if CYTHON_COMPILING_IN_PYPY
471 #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
472 #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
473 #else
474 #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
475 #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
476 PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
477 #endif
478 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
479 #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
480 #endif
481 #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
482 #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
483 #endif
484 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
485 #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
486 #endif
487 #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
488 #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
489 #if PY_MAJOR_VERSION >= 3
490 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
491 #else
492 #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
493 #endif
494 #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
495 #define PyObject_ASCII(o) PyObject_Repr(o)
496 #endif
497 #if PY_MAJOR_VERSION >= 3
498 #define PyBaseString_Type PyUnicode_Type
499 #define PyStringObject PyUnicodeObject
500 #define PyString_Type PyUnicode_Type
501 #define PyString_Check PyUnicode_Check
502 #define PyString_CheckExact PyUnicode_CheckExact
503 #ifndef PyObject_Unicode
504 #define PyObject_Unicode PyObject_Str
505 #endif
506 #endif
507 #if PY_MAJOR_VERSION >= 3
508 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
509 #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
510 #else
511 #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
512 #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
513 #endif
514 #ifndef PySet_CheckExact
515 #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
516 #endif
517 #if PY_VERSION_HEX >= 0x030900A4
518 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
519 #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
520 #else
521 #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
522 #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
523 #endif
524 #if CYTHON_ASSUME_SAFE_MACROS
525 #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
526 #else
527 #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
528 #endif
529 #if PY_MAJOR_VERSION >= 3
530 #define PyIntObject PyLongObject
531 #define PyInt_Type PyLong_Type
532 #define PyInt_Check(op) PyLong_Check(op)
533 #define PyInt_CheckExact(op) PyLong_CheckExact(op)
534 #define PyInt_FromString PyLong_FromString
535 #define PyInt_FromUnicode PyLong_FromUnicode
536 #define PyInt_FromLong PyLong_FromLong
537 #define PyInt_FromSize_t PyLong_FromSize_t
538 #define PyInt_FromSsize_t PyLong_FromSsize_t
539 #define PyInt_AsLong PyLong_AsLong
540 #define PyInt_AS_LONG PyLong_AS_LONG
541 #define PyInt_AsSsize_t PyLong_AsSsize_t
542 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
543 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
544 #define PyNumber_Int PyNumber_Long
545 #endif
546 #if PY_MAJOR_VERSION >= 3
547 #define PyBoolObject PyLongObject
548 #endif
549 #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
550 #ifndef PyUnicode_InternFromString
551 #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
552 #endif
553 #endif
554 #if PY_VERSION_HEX < 0x030200A4
555 typedef long Py_hash_t;
556 #define __Pyx_PyInt_FromHash_t PyInt_FromLong
557 #define __Pyx_PyInt_AsHash_t PyInt_AsLong
558 #else
559 #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
560 #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
561 #endif
562 #if PY_MAJOR_VERSION >= 3
563 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
564 #else
565 #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
566 #endif
567 #if CYTHON_USE_ASYNC_SLOTS
568 #if PY_VERSION_HEX >= 0x030500B1
569 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
570 #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
571 #else
572 #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
573 #endif
574 #else
575 #define __Pyx_PyType_AsAsync(obj) NULL
576 #endif
577 #ifndef __Pyx_PyAsyncMethodsStruct
578 typedef struct {
579 unaryfunc am_await;
580 unaryfunc am_aiter;
581 unaryfunc am_anext;
582 } __Pyx_PyAsyncMethodsStruct;
583 #endif
584
585 #if defined(WIN32) || defined(MS_WINDOWS)
586 #define _USE_MATH_DEFINES
587 #endif
588 #include <math.h>
589 #ifdef NAN
590 #define __PYX_NAN() ((float) NAN)
591 #else
592 static CYTHON_INLINE float __PYX_NAN() {
593 float value;
594 memset(&value, 0xFF, sizeof(value));
595 return value;
596 }
597 #endif
598 #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
599 #define __Pyx_truncl trunc
600 #else
601 #define __Pyx_truncl truncl
602 #endif
603
604 #define __PYX_MARK_ERR_POS(f_index, lineno) \
605 { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
606 #define __PYX_ERR(f_index, lineno, Ln_error) \
607 { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
608
609 #ifndef __PYX_EXTERN_C
610 #ifdef __cplusplus
611 #define __PYX_EXTERN_C extern "C"
612 #else
613 #define __PYX_EXTERN_C extern
614 #endif
615 #endif
616
617 #define __PYX_HAVE__clickhouse_driver__columns__largeint
618 #define __PYX_HAVE_API__clickhouse_driver__columns__largeint
619 /* Early includes */
620 #include <string.h>
621 #include <stdio.h>
622 #include "pythread.h"
623 #ifdef _OPENMP
624 #include <omp.h>
625 #endif /* _OPENMP */
626
627 #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
628 #define CYTHON_WITHOUT_ASSERTIONS
629 #endif
630
631 typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
632 const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
633
634 #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
635 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
636 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
637 #define __PYX_DEFAULT_STRING_ENCODING ""
638 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
639 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
640 #define __Pyx_uchar_cast(c) ((unsigned char)c)
641 #define __Pyx_long_cast(x) ((long)x)
642 #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
643 (sizeof(type) < sizeof(Py_ssize_t)) ||\
644 (sizeof(type) > sizeof(Py_ssize_t) &&\
645 likely(v < (type)PY_SSIZE_T_MAX ||\
646 v == (type)PY_SSIZE_T_MAX) &&\
647 (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
648 v == (type)PY_SSIZE_T_MIN))) ||\
649 (sizeof(type) == sizeof(Py_ssize_t) &&\
650 (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
651 v == (type)PY_SSIZE_T_MAX))) )
652 static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
653 return (size_t) i < (size_t) limit;
654 }
655 #if defined (__cplusplus) && __cplusplus >= 201103L
656 #include <cstdlib>
657 #define __Pyx_sst_abs(value) std::abs(value)
658 #elif SIZEOF_INT >= SIZEOF_SIZE_T
659 #define __Pyx_sst_abs(value) abs(value)
660 #elif SIZEOF_LONG >= SIZEOF_SIZE_T
661 #define __Pyx_sst_abs(value) labs(value)
662 #elif defined (_MSC_VER)
663 #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
664 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
665 #define __Pyx_sst_abs(value) llabs(value)
666 #elif defined (__GNUC__)
667 #define __Pyx_sst_abs(value) __builtin_llabs(value)
668 #else
669 #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
670 #endif
671 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
672 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
673 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
674 #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
675 #define __Pyx_PyBytes_FromString PyBytes_FromString
676 #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
677 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
678 #if PY_MAJOR_VERSION < 3
679 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
680 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
681 #else
682 #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
683 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
684 #endif
685 #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
686 #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
687 #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
688 #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
689 #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
690 #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
691 #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
692 #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
693 #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
694 #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
695 #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
696 #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
697 #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
698 #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
699 #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
700 #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
701 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
702 const Py_UNICODE *u_end = u;
703 while (*u_end++) ;
704 return (size_t)(u_end - u - 1);
705 }
706 #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
707 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
708 #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
709 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
710 #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
711 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
712 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
713 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
714 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
715 #define __Pyx_PySequence_Tuple(obj)\
716 (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
717 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
718 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
719 #if CYTHON_ASSUME_SAFE_MACROS
720 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
721 #else
722 #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
723 #endif
724 #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
725 #if PY_MAJOR_VERSION >= 3
726 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
727 #else
728 #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
729 #endif
730 #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
731 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
732 static int __Pyx_sys_getdefaultencoding_not_ascii;
733 static int __Pyx_init_sys_getdefaultencoding_params(void) {
734 PyObject* sys;
735 PyObject* default_encoding = NULL;
736 PyObject* ascii_chars_u = NULL;
737 PyObject* ascii_chars_b = NULL;
738 const char* default_encoding_c;
739 sys = PyImport_ImportModule("sys");
740 if (!sys) goto bad;
741 default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
742 Py_DECREF(sys);
743 if (!default_encoding) goto bad;
744 default_encoding_c = PyBytes_AsString(default_encoding);
745 if (!default_encoding_c) goto bad;
746 if (strcmp(default_encoding_c, "ascii") == 0) {
747 __Pyx_sys_getdefaultencoding_not_ascii = 0;
748 } else {
749 char ascii_chars[128];
750 int c;
751 for (c = 0; c < 128; c++) {
752 ascii_chars[c] = c;
753 }
754 __Pyx_sys_getdefaultencoding_not_ascii = 1;
755 ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
756 if (!ascii_chars_u) goto bad;
757 ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
758 if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
759 PyErr_Format(
760 PyExc_ValueError,
761 "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
762 default_encoding_c);
763 goto bad;
764 }
765 Py_DECREF(ascii_chars_u);
766 Py_DECREF(ascii_chars_b);
767 }
768 Py_DECREF(default_encoding);
769 return 0;
770 bad:
771 Py_XDECREF(default_encoding);
772 Py_XDECREF(ascii_chars_u);
773 Py_XDECREF(ascii_chars_b);
774 return -1;
775 }
776 #endif
777 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
778 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
779 #else
780 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
781 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
782 static char* __PYX_DEFAULT_STRING_ENCODING;
783 static int __Pyx_init_sys_getdefaultencoding_params(void) {
784 PyObject* sys;
785 PyObject* default_encoding = NULL;
786 char* default_encoding_c;
787 sys = PyImport_ImportModule("sys");
788 if (!sys) goto bad;
789 default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
790 Py_DECREF(sys);
791 if (!default_encoding) goto bad;
792 default_encoding_c = PyBytes_AsString(default_encoding);
793 if (!default_encoding_c) goto bad;
794 __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
795 if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
796 strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
797 Py_DECREF(default_encoding);
798 return 0;
799 bad:
800 Py_XDECREF(default_encoding);
801 return -1;
802 }
803 #endif
804 #endif
805
806
807 /* Test for GCC > 2.95 */
808 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
809 #define likely(x) __builtin_expect(!!(x), 1)
810 #define unlikely(x) __builtin_expect(!!(x), 0)
811 #else /* !__GNUC__ or GCC < 2.95 */
812 #define likely(x) (x)
813 #define unlikely(x) (x)
814 #endif /* __GNUC__ */
815 static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
816
817 static PyObject *__pyx_m = NULL;
818 static PyObject *__pyx_d;
819 static PyObject *__pyx_b;
820 static PyObject *__pyx_cython_runtime = NULL;
821 static PyObject *__pyx_empty_tuple;
822 static PyObject *__pyx_empty_bytes;
823 static PyObject *__pyx_empty_unicode;
824 static int __pyx_lineno;
825 static int __pyx_clineno = 0;
826 static const char * __pyx_cfilenm= __FILE__;
827 static const char *__pyx_filename;
828
829
830 static const char *__pyx_f[] = {
831 "clickhouse_driver/columns/largeint.pyx",
832 "type.pxd",
833 "bool.pxd",
834 "complex.pxd",
835 };
836
837 /*--- Type declarations ---*/
838
839 /* --- Runtime support code (head) --- */
840 /* Refnanny.proto */
841 #ifndef CYTHON_REFNANNY
842 #define CYTHON_REFNANNY 0
843 #endif
844 #if CYTHON_REFNANNY
845 typedef struct {
846 void (*INCREF)(void*, PyObject*, int);
847 void (*DECREF)(void*, PyObject*, int);
848 void (*GOTREF)(void*, PyObject*, int);
849 void (*GIVEREF)(void*, PyObject*, int);
850 void* (*SetupContext)(const char*, int, const char*);
851 void (*FinishContext)(void**);
852 } __Pyx_RefNannyAPIStruct;
853 static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
854 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
855 #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
856 #ifdef WITH_THREAD
857 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
858 if (acquire_gil) {\
859 PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
860 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
861 PyGILState_Release(__pyx_gilstate_save);\
862 } else {\
863 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
864 }
865 #else
866 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
867 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
868 #endif
869 #define __Pyx_RefNannyFinishContext()\
870 __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
871 #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
872 #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
873 #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
874 #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
875 #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
876 #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
877 #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
878 #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
879 #else
880 #define __Pyx_RefNannyDeclarations
881 #define __Pyx_RefNannySetupContext(name, acquire_gil)
882 #define __Pyx_RefNannyFinishContext()
883 #define __Pyx_INCREF(r) Py_INCREF(r)
884 #define __Pyx_DECREF(r) Py_DECREF(r)
885 #define __Pyx_GOTREF(r)
886 #define __Pyx_GIVEREF(r)
887 #define __Pyx_XINCREF(r) Py_XINCREF(r)
888 #define __Pyx_XDECREF(r) Py_XDECREF(r)
889 #define __Pyx_XGOTREF(r)
890 #define __Pyx_XGIVEREF(r)
891 #endif
892 #define __Pyx_XDECREF_SET(r, v) do {\
893 PyObject *tmp = (PyObject *) r;\
894 r = v; __Pyx_XDECREF(tmp);\
895 } while (0)
896 #define __Pyx_DECREF_SET(r, v) do {\
897 PyObject *tmp = (PyObject *) r;\
898 r = v; __Pyx_DECREF(tmp);\
899 } while (0)
900 #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
901 #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
902
903 /* PyObjectGetAttrStr.proto */
904 #if CYTHON_USE_TYPE_SLOTS
905 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
906 #else
907 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
908 #endif
909
910 /* GetBuiltinName.proto */
911 static PyObject *__Pyx_GetBuiltinName(PyObject *name);
912
913 /* RaiseArgTupleInvalid.proto */
914 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
915 Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
916
917 /* RaiseDoubleKeywords.proto */
918 static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
919
920 /* ParseKeywords.proto */
921 static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
922 PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
923 const char* function_name);
924
925 /* GetItemInt.proto */
926 #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
927 (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
928 __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
929 (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
930 __Pyx_GetItemInt_Generic(o, to_py_func(i))))
931 #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
932 (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
933 __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
934 (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
935 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
936 int wraparound, int boundscheck);
937 #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
938 (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
939 __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
940 (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
941 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
942 int wraparound, int boundscheck);
943 static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
944 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
945 int is_list, int wraparound, int boundscheck);
946
947 /* PyIntBinop.proto */
948 #if !CYTHON_COMPILING_IN_PYPY
949 static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
950 #else
951 #define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\
952 (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
953 #endif
954
955 /* TypeImport.proto */
956 #ifndef __PYX_HAVE_RT_ImportType_proto
957 #define __PYX_HAVE_RT_ImportType_proto
958 enum __Pyx_ImportType_CheckSize {
959 __Pyx_ImportType_CheckSize_Error = 0,
960 __Pyx_ImportType_CheckSize_Warn = 1,
961 __Pyx_ImportType_CheckSize_Ignore = 2
962 };
963 static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
964 #endif
965
966 /* Import.proto */
967 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
968
969 /* ImportFrom.proto */
970 static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
971
972 /* PyDictVersioning.proto */
973 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
974 #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
975 #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
976 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
977 (version_var) = __PYX_GET_DICT_VERSION(dict);\
978 (cache_var) = (value);
979 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
980 static PY_UINT64_T __pyx_dict_version = 0;\
981 static PyObject *__pyx_dict_cached_value = NULL;\
982 if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
983 (VAR) = __pyx_dict_cached_value;\
984 } else {\
985 (VAR) = __pyx_dict_cached_value = (LOOKUP);\
986 __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
987 }\
988 }
989 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
990 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
991 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
992 #else
993 #define __PYX_GET_DICT_VERSION(dict) (0)
994 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
995 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
996 #endif
997
998 /* GetModuleGlobalName.proto */
999 #if CYTHON_USE_DICT_VERSIONS
1000 #define __Pyx_GetModuleGlobalName(var, name) {\
1001 static PY_UINT64_T __pyx_dict_version = 0;\
1002 static PyObject *__pyx_dict_cached_value = NULL;\
1003 (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
1004 (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
1005 __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
1006 }
1007 #define __Pyx_GetModuleGlobalNameUncached(var, name) {\
1008 PY_UINT64_T __pyx_dict_version;\
1009 PyObject *__pyx_dict_cached_value;\
1010 (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
1011 }
1012 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
1013 #else
1014 #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1015 #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1016 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
1017 #endif
1018
1019 /* PyThreadStateGet.proto */
1020 #if CYTHON_FAST_THREAD_STATE
1021 #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
1022 #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
1023 #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
1024 #else
1025 #define __Pyx_PyThreadState_declare
1026 #define __Pyx_PyThreadState_assign
1027 #define __Pyx_PyErr_Occurred() PyErr_Occurred()
1028 #endif
1029
1030 /* PyErrFetchRestore.proto */
1031 #if CYTHON_FAST_THREAD_STATE
1032 #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
1033 #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
1034 #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
1035 #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
1036 #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
1037 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
1038 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
1039 #if CYTHON_COMPILING_IN_CPYTHON
1040 #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
1041 #else
1042 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1043 #endif
1044 #else
1045 #define __Pyx_PyErr_Clear() PyErr_Clear()
1046 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1047 #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
1048 #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
1049 #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
1050 #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
1051 #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
1052 #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
1053 #endif
1054
1055 /* CLineInTraceback.proto */
1056 #ifdef CYTHON_CLINE_IN_TRACEBACK
1057 #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
1058 #else
1059 static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
1060 #endif
1061
1062 /* CodeObjectCache.proto */
1063 typedef struct {
1064 PyCodeObject* code_object;
1065 int code_line;
1066 } __Pyx_CodeObjectCacheEntry;
1067 struct __Pyx_CodeObjectCache {
1068 int count;
1069 int max_count;
1070 __Pyx_CodeObjectCacheEntry* entries;
1071 };
1072 static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1073 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1074 static PyCodeObject *__pyx_find_code_object(int code_line);
1075 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1076
1077 /* AddTraceback.proto */
1078 static void __Pyx_AddTraceback(const char *funcname, int c_line,
1079 int py_line, const char *filename);
1080
1081 /* CIntToPy.proto */
1082 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value);
1083
1084 /* CIntFromPy.proto */
1085 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *);
1086
1087 /* CIntToPy.proto */
1088 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
1089
1090 /* CIntFromPy.proto */
1091 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
1092
1093 /* CIntFromPy.proto */
1094 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
1095
1096 /* FastTypeChecks.proto */
1097 #if CYTHON_COMPILING_IN_CPYTHON
1098 #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
1099 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
1100 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
1101 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
1102 #else
1103 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
1104 #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
1105 #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
1106 #endif
1107 #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
1108
1109 /* CheckBinaryVersion.proto */
1110 static int __Pyx_check_binary_version(void);
1111
1112 /* InitStrings.proto */
1113 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
1114
1115
1116 /* Module declarations from 'cpython.version' */
1117
1118 /* Module declarations from '__builtin__' */
1119
1120 /* Module declarations from 'cpython.type' */
1121 static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
1122
1123 /* Module declarations from 'libc.string' */
1124
1125 /* Module declarations from 'libc.stdio' */
1126
1127 /* Module declarations from 'cpython.object' */
1128
1129 /* Module declarations from 'cpython.ref' */
1130
1131 /* Module declarations from 'cpython.exc' */
1132
1133 /* Module declarations from 'cpython.module' */
1134
1135 /* Module declarations from 'cpython.mem' */
1136
1137 /* Module declarations from 'cpython.tuple' */
1138
1139 /* Module declarations from 'cpython.list' */
1140
1141 /* Module declarations from 'cpython.sequence' */
1142
1143 /* Module declarations from 'cpython.mapping' */
1144
1145 /* Module declarations from 'cpython.iterator' */
1146
1147 /* Module declarations from 'cpython.number' */
1148
1149 /* Module declarations from 'cpython.int' */
1150
1151 /* Module declarations from '__builtin__' */
1152
1153 /* Module declarations from 'cpython.bool' */
1154 static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
1155
1156 /* Module declarations from 'cpython.long' */
1157
1158 /* Module declarations from 'cpython.float' */
1159
1160 /* Module declarations from '__builtin__' */
1161
1162 /* Module declarations from 'cpython.complex' */
1163 static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
1164
1165 /* Module declarations from 'cpython.string' */
1166
1167 /* Module declarations from 'cpython.unicode' */
1168
1169 /* Module declarations from 'cpython.dict' */
1170
1171 /* Module declarations from 'cpython.instance' */
1172
1173 /* Module declarations from 'cpython.function' */
1174
1175 /* Module declarations from 'cpython.method' */
1176
1177 /* Module declarations from 'cpython.weakref' */
1178
1179 /* Module declarations from 'cpython.getargs' */
1180
1181 /* Module declarations from 'cpython.pythread' */
1182
1183 /* Module declarations from 'cpython.pystate' */
1184
1185 /* Module declarations from 'cpython.cobject' */
1186
1187 /* Module declarations from 'cpython.oldbuffer' */
1188
1189 /* Module declarations from 'cpython.set' */
1190
1191 /* Module declarations from 'cpython.buffer' */
1192
1193 /* Module declarations from 'cpython.bytes' */
1194
1195 /* Module declarations from 'cpython.pycapsule' */
1196
1197 /* Module declarations from 'cpython' */
1198
1199 /* Module declarations from 'clickhouse_driver.columns.largeint' */
1200 static PyObject *__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64 = 0;
1201 static PyObject *__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64 = 0;
1202 #define __Pyx_MODULE_NAME "clickhouse_driver.columns.largeint"
1203 extern int __pyx_module_is_main_clickhouse_driver__columns__largeint;
1204 int __pyx_module_is_main_clickhouse_driver__columns__largeint = 0;
1205
1206 /* Implementation of 'clickhouse_driver.columns.largeint' */
1207 static PyObject *__pyx_builtin_range;
1208 static const char __pyx_k_[] = "";
1209 static const char __pyx_k_i[] = "i";
1210 static const char __pyx_k_x[] = "x";
1211 static const char __pyx_k_ix[] = "ix";
1212 static const char __pyx_k_item[] = "item";
1213 static const char __pyx_k_main[] = "__main__";
1214 static const char __pyx_k_name[] = "__name__";
1215 static const char __pyx_k_test[] = "__test__";
1216 static const char __pyx_k_items[] = "items";
1217 static const char __pyx_k_range[] = "range";
1218 static const char __pyx_k_factor[] = "factor";
1219 static const char __pyx_k_import[] = "__import__";
1220 static const char __pyx_k_writer[] = "writer";
1221 static const char __pyx_k_n_items[] = "n_items";
1222 static const char __pyx_k_MAX_INT64[] = "MAX_INT64";
1223 static const char __pyx_k_MAX_UINT64[] = "MAX_UINT64";
1224 static const char __pyx_k_quad_items[] = "quad_items";
1225 static const char __pyx_k_int128_to_quads[] = "int128_to_quads";
1226 static const char __pyx_k_int256_to_quads[] = "int256_to_quads";
1227 static const char __pyx_k_uint128_to_quads[] = "uint128_to_quads";
1228 static const char __pyx_k_uint256_to_quads[] = "uint256_to_quads";
1229 static const char __pyx_k_int128_from_quads[] = "int128_from_quads";
1230 static const char __pyx_k_int256_from_quads[] = "int256_from_quads";
1231 static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
1232 static const char __pyx_k_uint128_from_quads[] = "uint128_from_quads";
1233 static const char __pyx_k_uint256_from_quads[] = "uint256_from_quads";
1234 static const char __pyx_k_clickhouse_driver_columns_largei[] = "clickhouse_driver/columns/largeint.pyx";
1235 static const char __pyx_k_clickhouse_driver_columns_largei_2[] = "clickhouse_driver.columns.largeint";
1236 static PyObject *__pyx_n_s_;
1237 static PyObject *__pyx_n_s_MAX_INT64;
1238 static PyObject *__pyx_n_s_MAX_UINT64;
1239 static PyObject *__pyx_kp_s_clickhouse_driver_columns_largei;
1240 static PyObject *__pyx_n_s_clickhouse_driver_columns_largei_2;
1241 static PyObject *__pyx_n_s_cline_in_traceback;
1242 static PyObject *__pyx_n_s_factor;
1243 static PyObject *__pyx_n_s_i;
1244 static PyObject *__pyx_n_s_import;
1245 static PyObject *__pyx_n_s_int128_from_quads;
1246 static PyObject *__pyx_n_s_int128_to_quads;
1247 static PyObject *__pyx_n_s_int256_from_quads;
1248 static PyObject *__pyx_n_s_int256_to_quads;
1249 static PyObject *__pyx_n_s_item;
1250 static PyObject *__pyx_n_s_items;
1251 static PyObject *__pyx_n_s_ix;
1252 static PyObject *__pyx_n_s_main;
1253 static PyObject *__pyx_n_s_n_items;
1254 static PyObject *__pyx_n_s_name;
1255 static PyObject *__pyx_n_s_quad_items;
1256 static PyObject *__pyx_n_s_range;
1257 static PyObject *__pyx_n_s_test;
1258 static PyObject *__pyx_n_s_uint128_from_quads;
1259 static PyObject *__pyx_n_s_uint128_to_quads;
1260 static PyObject *__pyx_n_s_uint256_from_quads;
1261 static PyObject *__pyx_n_s_uint256_to_quads;
1262 static PyObject *__pyx_n_s_writer;
1263 static PyObject *__pyx_n_s_x;
1264 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_int128_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1265 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_2int128_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1266 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_4uint128_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1267 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_6uint128_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1268 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_8int256_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1269 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_10int256_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1270 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_12uint256_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1271 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_14uint256_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items); /* proto */
1272 static PyObject *__pyx_int_0;
1273 static PyObject *__pyx_int_1;
1274 static PyObject *__pyx_int_64;
1275 static PyObject *__pyx_int_128;
1276 static PyObject *__pyx_int_192;
1277 static PyObject *__pyx_tuple__2;
1278 static PyObject *__pyx_tuple__4;
1279 static PyObject *__pyx_tuple__6;
1280 static PyObject *__pyx_tuple__8;
1281 static PyObject *__pyx_tuple__10;
1282 static PyObject *__pyx_tuple__12;
1283 static PyObject *__pyx_tuple__14;
1284 static PyObject *__pyx_tuple__16;
1285 static PyObject *__pyx_codeobj__3;
1286 static PyObject *__pyx_codeobj__5;
1287 static PyObject *__pyx_codeobj__7;
1288 static PyObject *__pyx_codeobj__9;
1289 static PyObject *__pyx_codeobj__11;
1290 static PyObject *__pyx_codeobj__13;
1291 static PyObject *__pyx_codeobj__15;
1292 static PyObject *__pyx_codeobj__17;
1293 /* Late includes */
1294
1295 /* "clickhouse_driver/columns/largeint.pyx":10
1296 *
1297 *
1298 * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
1299 * cdef unsigned int factor = 2
1300 * items = PyTuple_New(n_items)
1301 */
1302
1303 /* Python wrapper */
1304 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_1int128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1305 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_1int128_from_quads = {"int128_from_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_1int128_from_quads, METH_VARARGS|METH_KEYWORDS, 0};
1306 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_1int128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1307 PyObject *__pyx_v_quad_items = 0;
1308 unsigned PY_LONG_LONG __pyx_v_n_items;
1309 int __pyx_lineno = 0;
1310 const char *__pyx_filename = NULL;
1311 int __pyx_clineno = 0;
1312 PyObject *__pyx_r = 0;
1313 __Pyx_RefNannyDeclarations
1314 __Pyx_RefNannySetupContext("int128_from_quads (wrapper)", 0);
1315 {
1316 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0};
1317 PyObject* values[2] = {0,0};
1318 if (unlikely(__pyx_kwds)) {
1319 Py_ssize_t kw_args;
1320 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1321 switch (pos_args) {
1322 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1323 CYTHON_FALLTHROUGH;
1324 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1325 CYTHON_FALLTHROUGH;
1326 case 0: break;
1327 default: goto __pyx_L5_argtuple_error;
1328 }
1329 kw_args = PyDict_Size(__pyx_kwds);
1330 switch (pos_args) {
1331 case 0:
1332 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--;
1333 else goto __pyx_L5_argtuple_error;
1334 CYTHON_FALLTHROUGH;
1335 case 1:
1336 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
1337 else {
1338 __Pyx_RaiseArgtupleInvalid("int128_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 10, __pyx_L3_error)
1339 }
1340 }
1341 if (unlikely(kw_args > 0)) {
1342 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int128_from_quads") < 0)) __PYX_ERR(0, 10, __pyx_L3_error)
1343 }
1344 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
1345 goto __pyx_L5_argtuple_error;
1346 } else {
1347 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1348 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1349 }
1350 __pyx_v_quad_items = values[0];
1351 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L3_error)
1352 }
1353 goto __pyx_L4_argument_unpacking_done;
1354 __pyx_L5_argtuple_error:;
1355 __Pyx_RaiseArgtupleInvalid("int128_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 10, __pyx_L3_error)
1356 __pyx_L3_error:;
1357 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1358 __Pyx_RefNannyFinishContext();
1359 return NULL;
1360 __pyx_L4_argument_unpacking_done:;
1361 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_int128_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items);
1362
1363 /* function exit code */
1364 __Pyx_RefNannyFinishContext();
1365 return __pyx_r;
1366 }
1367
1368 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_int128_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
1369 unsigned int __pyx_v_factor;
1370 PyObject *__pyx_v_items = NULL;
1371 unsigned PY_LONG_LONG __pyx_v_i;
1372 unsigned PY_LONG_LONG __pyx_v_ix;
1373 PyObject *__pyx_v_item = 0;
1374 PyObject *__pyx_r = NULL;
1375 __Pyx_RefNannyDeclarations
1376 PyObject *__pyx_t_1 = NULL;
1377 unsigned PY_LONG_LONG __pyx_t_2;
1378 unsigned PY_LONG_LONG __pyx_t_3;
1379 unsigned PY_LONG_LONG __pyx_t_4;
1380 unsigned PY_LONG_LONG __pyx_t_5;
1381 PyObject *__pyx_t_6 = NULL;
1382 int __pyx_t_7;
1383 PyObject *__pyx_t_8 = NULL;
1384 int __pyx_lineno = 0;
1385 const char *__pyx_filename = NULL;
1386 int __pyx_clineno = 0;
1387 __Pyx_RefNannySetupContext("int128_from_quads", 0);
1388
1389 /* "clickhouse_driver/columns/largeint.pyx":11
1390 *
1391 * def int128_from_quads(quad_items, unsigned long long n_items):
1392 * cdef unsigned int factor = 2 # <<<<<<<<<<<<<<
1393 * items = PyTuple_New(n_items)
1394 *
1395 */
1396 __pyx_v_factor = 2;
1397
1398 /* "clickhouse_driver/columns/largeint.pyx":12
1399 * def int128_from_quads(quad_items, unsigned long long n_items):
1400 * cdef unsigned int factor = 2
1401 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<<
1402 *
1403 * cdef unsigned long long i, ix
1404 */
1405 __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error)
1406 __Pyx_GOTREF(__pyx_t_1);
1407 __pyx_v_items = ((PyObject*)__pyx_t_1);
1408 __pyx_t_1 = 0;
1409
1410 /* "clickhouse_driver/columns/largeint.pyx":17
1411 * cdef object item
1412 *
1413 * for i in range(n_items): # <<<<<<<<<<<<<<
1414 * ix = factor * i
1415 *
1416 */
1417 __pyx_t_2 = __pyx_v_n_items;
1418 __pyx_t_3 = __pyx_t_2;
1419 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
1420 __pyx_v_i = __pyx_t_4;
1421
1422 /* "clickhouse_driver/columns/largeint.pyx":18
1423 *
1424 * for i in range(n_items):
1425 * ix = factor * i # <<<<<<<<<<<<<<
1426 *
1427 * if quad_items[ix + 1] > MAX_INT64:
1428 */
1429 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
1430
1431 /* "clickhouse_driver/columns/largeint.pyx":20
1432 * ix = factor * i
1433 *
1434 * if quad_items[ix + 1] > MAX_INT64: # <<<<<<<<<<<<<<
1435 * item = (
1436 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
1437 */
1438 __pyx_t_5 = (__pyx_v_ix + 1);
1439 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
1440 __Pyx_GOTREF(__pyx_t_1);
1441 __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 20, __pyx_L1_error)
1442 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1443 __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 20, __pyx_L1_error)
1444 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1445 if (__pyx_t_7) {
1446
1447 /* "clickhouse_driver/columns/largeint.pyx":22
1448 * if quad_items[ix + 1] > MAX_INT64:
1449 * item = (
1450 * -((MAX_UINT64 - quad_items[ix + 1]) << 64) # <<<<<<<<<<<<<<
1451 * - (MAX_UINT64 - quad_items[ix])
1452 * - 1
1453 */
1454 __pyx_t_5 = (__pyx_v_ix + 1);
1455 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 22, __pyx_L1_error)
1456 __Pyx_GOTREF(__pyx_t_6);
1457 __pyx_t_1 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
1458 __Pyx_GOTREF(__pyx_t_1);
1459 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1460 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 22, __pyx_L1_error)
1461 __Pyx_GOTREF(__pyx_t_6);
1462 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1463 __pyx_t_1 = PyNumber_Negative(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
1464 __Pyx_GOTREF(__pyx_t_1);
1465 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1466
1467 /* "clickhouse_driver/columns/largeint.pyx":23
1468 * item = (
1469 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
1470 * - (MAX_UINT64 - quad_items[ix]) # <<<<<<<<<<<<<<
1471 * - 1
1472 * )
1473 */
1474 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L1_error)
1475 __Pyx_GOTREF(__pyx_t_6);
1476 __pyx_t_8 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 23, __pyx_L1_error)
1477 __Pyx_GOTREF(__pyx_t_8);
1478 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1479 __pyx_t_6 = PyNumber_Subtract(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L1_error)
1480 __Pyx_GOTREF(__pyx_t_6);
1481 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1482 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
1483
1484 /* "clickhouse_driver/columns/largeint.pyx":24
1485 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
1486 * - (MAX_UINT64 - quad_items[ix])
1487 * - 1 # <<<<<<<<<<<<<<
1488 * )
1489 *
1490 */
1491 __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_6, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 24, __pyx_L1_error)
1492 __Pyx_GOTREF(__pyx_t_8);
1493 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1494 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8);
1495 __pyx_t_8 = 0;
1496
1497 /* "clickhouse_driver/columns/largeint.pyx":20
1498 * ix = factor * i
1499 *
1500 * if quad_items[ix + 1] > MAX_INT64: # <<<<<<<<<<<<<<
1501 * item = (
1502 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
1503 */
1504 goto __pyx_L5;
1505 }
1506
1507 /* "clickhouse_driver/columns/largeint.pyx":28
1508 *
1509 * else:
1510 * item = (quad_items[ix + 1] << 64) + quad_items[ix] # <<<<<<<<<<<<<<
1511 *
1512 * Py_INCREF(item)
1513 */
1514 /*else*/ {
1515 __pyx_t_5 = (__pyx_v_ix + 1);
1516 __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 28, __pyx_L1_error)
1517 __Pyx_GOTREF(__pyx_t_8);
1518 __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 28, __pyx_L1_error)
1519 __Pyx_GOTREF(__pyx_t_6);
1520 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
1521 __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 28, __pyx_L1_error)
1522 __Pyx_GOTREF(__pyx_t_8);
1523 __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
1524 __Pyx_GOTREF(__pyx_t_1);
1525 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1526 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
1527 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
1528 __pyx_t_1 = 0;
1529 }
1530 __pyx_L5:;
1531
1532 /* "clickhouse_driver/columns/largeint.pyx":30
1533 * item = (quad_items[ix + 1] << 64) + quad_items[ix]
1534 *
1535 * Py_INCREF(item) # <<<<<<<<<<<<<<
1536 * PyTuple_SET_ITEM(items, i, item)
1537 *
1538 */
1539 Py_INCREF(__pyx_v_item);
1540
1541 /* "clickhouse_driver/columns/largeint.pyx":31
1542 *
1543 * Py_INCREF(item)
1544 * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<<
1545 *
1546 * return items
1547 */
1548 PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item);
1549 }
1550
1551 /* "clickhouse_driver/columns/largeint.pyx":33
1552 * PyTuple_SET_ITEM(items, i, item)
1553 *
1554 * return items # <<<<<<<<<<<<<<
1555 *
1556 *
1557 */
1558 __Pyx_XDECREF(__pyx_r);
1559 __Pyx_INCREF(__pyx_v_items);
1560 __pyx_r = __pyx_v_items;
1561 goto __pyx_L0;
1562
1563 /* "clickhouse_driver/columns/largeint.pyx":10
1564 *
1565 *
1566 * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
1567 * cdef unsigned int factor = 2
1568 * items = PyTuple_New(n_items)
1569 */
1570
1571 /* function exit code */
1572 __pyx_L1_error:;
1573 __Pyx_XDECREF(__pyx_t_1);
1574 __Pyx_XDECREF(__pyx_t_6);
1575 __Pyx_XDECREF(__pyx_t_8);
1576 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1577 __pyx_r = NULL;
1578 __pyx_L0:;
1579 __Pyx_XDECREF(__pyx_v_items);
1580 __Pyx_XDECREF(__pyx_v_item);
1581 __Pyx_XGIVEREF(__pyx_r);
1582 __Pyx_RefNannyFinishContext();
1583 return __pyx_r;
1584 }
1585
1586 /* "clickhouse_driver/columns/largeint.pyx":36
1587 *
1588 *
1589 * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
1590 * cdef unsigned int factor = 2
1591 * quad_items = PyTuple_New(n_items * factor)
1592 */
1593
1594 /* Python wrapper */
1595 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_3int128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1596 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_3int128_to_quads = {"int128_to_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_3int128_to_quads, METH_VARARGS|METH_KEYWORDS, 0};
1597 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_3int128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1598 PyObject *__pyx_v_items = 0;
1599 unsigned PY_LONG_LONG __pyx_v_n_items;
1600 int __pyx_lineno = 0;
1601 const char *__pyx_filename = NULL;
1602 int __pyx_clineno = 0;
1603 PyObject *__pyx_r = 0;
1604 __Pyx_RefNannyDeclarations
1605 __Pyx_RefNannySetupContext("int128_to_quads (wrapper)", 0);
1606 {
1607 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0};
1608 PyObject* values[2] = {0,0};
1609 if (unlikely(__pyx_kwds)) {
1610 Py_ssize_t kw_args;
1611 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1612 switch (pos_args) {
1613 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1614 CYTHON_FALLTHROUGH;
1615 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1616 CYTHON_FALLTHROUGH;
1617 case 0: break;
1618 default: goto __pyx_L5_argtuple_error;
1619 }
1620 kw_args = PyDict_Size(__pyx_kwds);
1621 switch (pos_args) {
1622 case 0:
1623 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--;
1624 else goto __pyx_L5_argtuple_error;
1625 CYTHON_FALLTHROUGH;
1626 case 1:
1627 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
1628 else {
1629 __Pyx_RaiseArgtupleInvalid("int128_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 36, __pyx_L3_error)
1630 }
1631 }
1632 if (unlikely(kw_args > 0)) {
1633 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int128_to_quads") < 0)) __PYX_ERR(0, 36, __pyx_L3_error)
1634 }
1635 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
1636 goto __pyx_L5_argtuple_error;
1637 } else {
1638 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1639 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1640 }
1641 __pyx_v_items = values[0];
1642 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 36, __pyx_L3_error)
1643 }
1644 goto __pyx_L4_argument_unpacking_done;
1645 __pyx_L5_argtuple_error:;
1646 __Pyx_RaiseArgtupleInvalid("int128_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 36, __pyx_L3_error)
1647 __pyx_L3_error:;
1648 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1649 __Pyx_RefNannyFinishContext();
1650 return NULL;
1651 __pyx_L4_argument_unpacking_done:;
1652 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_2int128_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items);
1653
1654 /* function exit code */
1655 __Pyx_RefNannyFinishContext();
1656 return __pyx_r;
1657 }
1658
1659 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_2int128_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
1660 unsigned int __pyx_v_factor;
1661 PyObject *__pyx_v_quad_items = NULL;
1662 unsigned PY_LONG_LONG __pyx_v_i;
1663 unsigned PY_LONG_LONG __pyx_v_ix;
1664 PyObject *__pyx_v_x = 0;
1665 PyObject *__pyx_v_item = 0;
1666 PyObject *__pyx_r = NULL;
1667 __Pyx_RefNannyDeclarations
1668 PyObject *__pyx_t_1 = NULL;
1669 unsigned PY_LONG_LONG __pyx_t_2;
1670 unsigned PY_LONG_LONG __pyx_t_3;
1671 unsigned PY_LONG_LONG __pyx_t_4;
1672 int __pyx_t_5;
1673 PyObject *__pyx_t_6 = NULL;
1674 int __pyx_lineno = 0;
1675 const char *__pyx_filename = NULL;
1676 int __pyx_clineno = 0;
1677 __Pyx_RefNannySetupContext("int128_to_quads", 0);
1678
1679 /* "clickhouse_driver/columns/largeint.pyx":37
1680 *
1681 * def int128_to_quads(items, unsigned long long n_items):
1682 * cdef unsigned int factor = 2 # <<<<<<<<<<<<<<
1683 * quad_items = PyTuple_New(n_items * factor)
1684 *
1685 */
1686 __pyx_v_factor = 2;
1687
1688 /* "clickhouse_driver/columns/largeint.pyx":38
1689 * def int128_to_quads(items, unsigned long long n_items):
1690 * cdef unsigned int factor = 2
1691 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<<
1692 *
1693 * cdef unsigned long long i, ix
1694 */
1695 __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
1696 __Pyx_GOTREF(__pyx_t_1);
1697 __pyx_v_quad_items = ((PyObject*)__pyx_t_1);
1698 __pyx_t_1 = 0;
1699
1700 /* "clickhouse_driver/columns/largeint.pyx":43
1701 * cdef object x, item
1702 *
1703 * for i in range(n_items): # <<<<<<<<<<<<<<
1704 * ix = factor * i
1705 *
1706 */
1707 __pyx_t_2 = __pyx_v_n_items;
1708 __pyx_t_3 = __pyx_t_2;
1709 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
1710 __pyx_v_i = __pyx_t_4;
1711
1712 /* "clickhouse_driver/columns/largeint.pyx":44
1713 *
1714 * for i in range(n_items):
1715 * ix = factor * i # <<<<<<<<<<<<<<
1716 *
1717 * x = items[i]
1718 */
1719 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
1720
1721 /* "clickhouse_driver/columns/largeint.pyx":46
1722 * ix = factor * i
1723 *
1724 * x = items[i] # <<<<<<<<<<<<<<
1725 * if x < 0:
1726 * x = -x - 1
1727 */
1728 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_items, __pyx_v_i, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
1729 __Pyx_GOTREF(__pyx_t_1);
1730 __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
1731 __pyx_t_1 = 0;
1732
1733 /* "clickhouse_driver/columns/largeint.pyx":47
1734 *
1735 * x = items[i]
1736 * if x < 0: # <<<<<<<<<<<<<<
1737 * x = -x - 1
1738 *
1739 */
1740 __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error)
1741 __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 47, __pyx_L1_error)
1742 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1743 if (__pyx_t_5) {
1744
1745 /* "clickhouse_driver/columns/largeint.pyx":48
1746 * x = items[i]
1747 * if x < 0:
1748 * x = -x - 1 # <<<<<<<<<<<<<<
1749 *
1750 * item = MAX_UINT64 - x & MAX_UINT64
1751 */
1752 __pyx_t_1 = PyNumber_Negative(__pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error)
1753 __Pyx_GOTREF(__pyx_t_1);
1754 __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 48, __pyx_L1_error)
1755 __Pyx_GOTREF(__pyx_t_6);
1756 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1757 __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_6);
1758 __pyx_t_6 = 0;
1759
1760 /* "clickhouse_driver/columns/largeint.pyx":50
1761 * x = -x - 1
1762 *
1763 * item = MAX_UINT64 - x & MAX_UINT64 # <<<<<<<<<<<<<<
1764 * Py_INCREF(item)
1765 * PyTuple_SET_ITEM(quad_items, ix, item)
1766 */
1767 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_v_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 50, __pyx_L1_error)
1768 __Pyx_GOTREF(__pyx_t_6);
1769 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
1770 __Pyx_GOTREF(__pyx_t_1);
1771 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1772 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
1773 __pyx_t_1 = 0;
1774
1775 /* "clickhouse_driver/columns/largeint.pyx":51
1776 *
1777 * item = MAX_UINT64 - x & MAX_UINT64
1778 * Py_INCREF(item) # <<<<<<<<<<<<<<
1779 * PyTuple_SET_ITEM(quad_items, ix, item)
1780 *
1781 */
1782 Py_INCREF(__pyx_v_item);
1783
1784 /* "clickhouse_driver/columns/largeint.pyx":52
1785 * item = MAX_UINT64 - x & MAX_UINT64
1786 * Py_INCREF(item)
1787 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
1788 *
1789 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
1790 */
1791 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
1792
1793 /* "clickhouse_driver/columns/largeint.pyx":54
1794 * PyTuple_SET_ITEM(quad_items, ix, item)
1795 *
1796 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
1797 * Py_INCREF(item)
1798 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
1799 */
1800 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
1801 __Pyx_GOTREF(__pyx_t_1);
1802 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
1803 __Pyx_GOTREF(__pyx_t_6);
1804 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1805 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
1806 __Pyx_GOTREF(__pyx_t_1);
1807 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1808 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
1809 __pyx_t_1 = 0;
1810
1811 /* "clickhouse_driver/columns/largeint.pyx":55
1812 *
1813 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
1814 * Py_INCREF(item) # <<<<<<<<<<<<<<
1815 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
1816 *
1817 */
1818 Py_INCREF(__pyx_v_item);
1819
1820 /* "clickhouse_driver/columns/largeint.pyx":56
1821 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
1822 * Py_INCREF(item)
1823 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
1824 *
1825 * else:
1826 */
1827 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
1828
1829 /* "clickhouse_driver/columns/largeint.pyx":47
1830 *
1831 * x = items[i]
1832 * if x < 0: # <<<<<<<<<<<<<<
1833 * x = -x - 1
1834 *
1835 */
1836 goto __pyx_L5;
1837 }
1838
1839 /* "clickhouse_driver/columns/largeint.pyx":59
1840 *
1841 * else:
1842 * item = x & MAX_UINT64 # <<<<<<<<<<<<<<
1843 * Py_INCREF(item)
1844 * PyTuple_SET_ITEM(quad_items, ix, item)
1845 */
1846 /*else*/ {
1847 __pyx_t_1 = PyNumber_And(__pyx_v_x, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
1848 __Pyx_GOTREF(__pyx_t_1);
1849 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
1850 __pyx_t_1 = 0;
1851
1852 /* "clickhouse_driver/columns/largeint.pyx":60
1853 * else:
1854 * item = x & MAX_UINT64
1855 * Py_INCREF(item) # <<<<<<<<<<<<<<
1856 * PyTuple_SET_ITEM(quad_items, ix, item)
1857 *
1858 */
1859 Py_INCREF(__pyx_v_item);
1860
1861 /* "clickhouse_driver/columns/largeint.pyx":61
1862 * item = x & MAX_UINT64
1863 * Py_INCREF(item)
1864 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
1865 *
1866 * item = (x >> 64) & MAX_UINT64
1867 */
1868 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
1869
1870 /* "clickhouse_driver/columns/largeint.pyx":63
1871 * PyTuple_SET_ITEM(quad_items, ix, item)
1872 *
1873 * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
1874 * Py_INCREF(item)
1875 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
1876 */
1877 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
1878 __Pyx_GOTREF(__pyx_t_1);
1879 __pyx_t_6 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 63, __pyx_L1_error)
1880 __Pyx_GOTREF(__pyx_t_6);
1881 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1882 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6);
1883 __pyx_t_6 = 0;
1884
1885 /* "clickhouse_driver/columns/largeint.pyx":64
1886 *
1887 * item = (x >> 64) & MAX_UINT64
1888 * Py_INCREF(item) # <<<<<<<<<<<<<<
1889 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
1890 *
1891 */
1892 Py_INCREF(__pyx_v_item);
1893
1894 /* "clickhouse_driver/columns/largeint.pyx":65
1895 * item = (x >> 64) & MAX_UINT64
1896 * Py_INCREF(item)
1897 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
1898 *
1899 * return quad_items
1900 */
1901 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
1902 }
1903 __pyx_L5:;
1904 }
1905
1906 /* "clickhouse_driver/columns/largeint.pyx":67
1907 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
1908 *
1909 * return quad_items # <<<<<<<<<<<<<<
1910 *
1911 *
1912 */
1913 __Pyx_XDECREF(__pyx_r);
1914 __Pyx_INCREF(__pyx_v_quad_items);
1915 __pyx_r = __pyx_v_quad_items;
1916 goto __pyx_L0;
1917
1918 /* "clickhouse_driver/columns/largeint.pyx":36
1919 *
1920 *
1921 * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
1922 * cdef unsigned int factor = 2
1923 * quad_items = PyTuple_New(n_items * factor)
1924 */
1925
1926 /* function exit code */
1927 __pyx_L1_error:;
1928 __Pyx_XDECREF(__pyx_t_1);
1929 __Pyx_XDECREF(__pyx_t_6);
1930 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1931 __pyx_r = NULL;
1932 __pyx_L0:;
1933 __Pyx_XDECREF(__pyx_v_quad_items);
1934 __Pyx_XDECREF(__pyx_v_x);
1935 __Pyx_XDECREF(__pyx_v_item);
1936 __Pyx_XGIVEREF(__pyx_r);
1937 __Pyx_RefNannyFinishContext();
1938 return __pyx_r;
1939 }
1940
1941 /* "clickhouse_driver/columns/largeint.pyx":70
1942 *
1943 *
1944 * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
1945 * cdef unsigned int factor = 2
1946 * items = PyTuple_New(n_items)
1947 */
1948
1949 /* Python wrapper */
1950 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_5uint128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1951 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_5uint128_from_quads = {"uint128_from_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_5uint128_from_quads, METH_VARARGS|METH_KEYWORDS, 0};
1952 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_5uint128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1953 PyObject *__pyx_v_quad_items = 0;
1954 unsigned PY_LONG_LONG __pyx_v_n_items;
1955 int __pyx_lineno = 0;
1956 const char *__pyx_filename = NULL;
1957 int __pyx_clineno = 0;
1958 PyObject *__pyx_r = 0;
1959 __Pyx_RefNannyDeclarations
1960 __Pyx_RefNannySetupContext("uint128_from_quads (wrapper)", 0);
1961 {
1962 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0};
1963 PyObject* values[2] = {0,0};
1964 if (unlikely(__pyx_kwds)) {
1965 Py_ssize_t kw_args;
1966 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1967 switch (pos_args) {
1968 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1969 CYTHON_FALLTHROUGH;
1970 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1971 CYTHON_FALLTHROUGH;
1972 case 0: break;
1973 default: goto __pyx_L5_argtuple_error;
1974 }
1975 kw_args = PyDict_Size(__pyx_kwds);
1976 switch (pos_args) {
1977 case 0:
1978 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--;
1979 else goto __pyx_L5_argtuple_error;
1980 CYTHON_FALLTHROUGH;
1981 case 1:
1982 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
1983 else {
1984 __Pyx_RaiseArgtupleInvalid("uint128_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 70, __pyx_L3_error)
1985 }
1986 }
1987 if (unlikely(kw_args > 0)) {
1988 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint128_from_quads") < 0)) __PYX_ERR(0, 70, __pyx_L3_error)
1989 }
1990 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
1991 goto __pyx_L5_argtuple_error;
1992 } else {
1993 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1994 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1995 }
1996 __pyx_v_quad_items = values[0];
1997 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L3_error)
1998 }
1999 goto __pyx_L4_argument_unpacking_done;
2000 __pyx_L5_argtuple_error:;
2001 __Pyx_RaiseArgtupleInvalid("uint128_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 70, __pyx_L3_error)
2002 __pyx_L3_error:;
2003 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2004 __Pyx_RefNannyFinishContext();
2005 return NULL;
2006 __pyx_L4_argument_unpacking_done:;
2007 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_4uint128_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items);
2008
2009 /* function exit code */
2010 __Pyx_RefNannyFinishContext();
2011 return __pyx_r;
2012 }
2013
2014 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_4uint128_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
2015 unsigned int __pyx_v_factor;
2016 PyObject *__pyx_v_items = NULL;
2017 unsigned PY_LONG_LONG __pyx_v_i;
2018 unsigned PY_LONG_LONG __pyx_v_ix;
2019 PyObject *__pyx_v_item = 0;
2020 PyObject *__pyx_r = NULL;
2021 __Pyx_RefNannyDeclarations
2022 PyObject *__pyx_t_1 = NULL;
2023 unsigned PY_LONG_LONG __pyx_t_2;
2024 unsigned PY_LONG_LONG __pyx_t_3;
2025 unsigned PY_LONG_LONG __pyx_t_4;
2026 unsigned PY_LONG_LONG __pyx_t_5;
2027 PyObject *__pyx_t_6 = NULL;
2028 PyObject *__pyx_t_7 = NULL;
2029 int __pyx_lineno = 0;
2030 const char *__pyx_filename = NULL;
2031 int __pyx_clineno = 0;
2032 __Pyx_RefNannySetupContext("uint128_from_quads", 0);
2033
2034 /* "clickhouse_driver/columns/largeint.pyx":71
2035 *
2036 * def uint128_from_quads(quad_items, unsigned long long n_items):
2037 * cdef unsigned int factor = 2 # <<<<<<<<<<<<<<
2038 * items = PyTuple_New(n_items)
2039 *
2040 */
2041 __pyx_v_factor = 2;
2042
2043 /* "clickhouse_driver/columns/largeint.pyx":72
2044 * def uint128_from_quads(quad_items, unsigned long long n_items):
2045 * cdef unsigned int factor = 2
2046 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<<
2047 *
2048 * cdef unsigned long long i, ix
2049 */
2050 __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error)
2051 __Pyx_GOTREF(__pyx_t_1);
2052 __pyx_v_items = ((PyObject*)__pyx_t_1);
2053 __pyx_t_1 = 0;
2054
2055 /* "clickhouse_driver/columns/largeint.pyx":77
2056 * cdef object item
2057 *
2058 * for i in range(n_items): # <<<<<<<<<<<<<<
2059 * ix = factor * i
2060 * item = (quad_items[ix + 1] << 64) + quad_items[ix]
2061 */
2062 __pyx_t_2 = __pyx_v_n_items;
2063 __pyx_t_3 = __pyx_t_2;
2064 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
2065 __pyx_v_i = __pyx_t_4;
2066
2067 /* "clickhouse_driver/columns/largeint.pyx":78
2068 *
2069 * for i in range(n_items):
2070 * ix = factor * i # <<<<<<<<<<<<<<
2071 * item = (quad_items[ix + 1] << 64) + quad_items[ix]
2072 *
2073 */
2074 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
2075
2076 /* "clickhouse_driver/columns/largeint.pyx":79
2077 * for i in range(n_items):
2078 * ix = factor * i
2079 * item = (quad_items[ix + 1] << 64) + quad_items[ix] # <<<<<<<<<<<<<<
2080 *
2081 * Py_INCREF(item)
2082 */
2083 __pyx_t_5 = (__pyx_v_ix + 1);
2084 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
2085 __Pyx_GOTREF(__pyx_t_1);
2086 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L1_error)
2087 __Pyx_GOTREF(__pyx_t_6);
2088 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2089 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
2090 __Pyx_GOTREF(__pyx_t_1);
2091 __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 79, __pyx_L1_error)
2092 __Pyx_GOTREF(__pyx_t_7);
2093 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2094 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2095 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7);
2096 __pyx_t_7 = 0;
2097
2098 /* "clickhouse_driver/columns/largeint.pyx":81
2099 * item = (quad_items[ix + 1] << 64) + quad_items[ix]
2100 *
2101 * Py_INCREF(item) # <<<<<<<<<<<<<<
2102 * PyTuple_SET_ITEM(items, i, item)
2103 *
2104 */
2105 Py_INCREF(__pyx_v_item);
2106
2107 /* "clickhouse_driver/columns/largeint.pyx":82
2108 *
2109 * Py_INCREF(item)
2110 * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<<
2111 *
2112 * return items
2113 */
2114 PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item);
2115 }
2116
2117 /* "clickhouse_driver/columns/largeint.pyx":84
2118 * PyTuple_SET_ITEM(items, i, item)
2119 *
2120 * return items # <<<<<<<<<<<<<<
2121 *
2122 *
2123 */
2124 __Pyx_XDECREF(__pyx_r);
2125 __Pyx_INCREF(__pyx_v_items);
2126 __pyx_r = __pyx_v_items;
2127 goto __pyx_L0;
2128
2129 /* "clickhouse_driver/columns/largeint.pyx":70
2130 *
2131 *
2132 * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
2133 * cdef unsigned int factor = 2
2134 * items = PyTuple_New(n_items)
2135 */
2136
2137 /* function exit code */
2138 __pyx_L1_error:;
2139 __Pyx_XDECREF(__pyx_t_1);
2140 __Pyx_XDECREF(__pyx_t_6);
2141 __Pyx_XDECREF(__pyx_t_7);
2142 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2143 __pyx_r = NULL;
2144 __pyx_L0:;
2145 __Pyx_XDECREF(__pyx_v_items);
2146 __Pyx_XDECREF(__pyx_v_item);
2147 __Pyx_XGIVEREF(__pyx_r);
2148 __Pyx_RefNannyFinishContext();
2149 return __pyx_r;
2150 }
2151
2152 /* "clickhouse_driver/columns/largeint.pyx":87
2153 *
2154 *
2155 * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
2156 * cdef unsigned int factor = 2
2157 * quad_items = PyTuple_New(n_items * factor)
2158 */
2159
2160 /* Python wrapper */
2161 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_7uint128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2162 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_7uint128_to_quads = {"uint128_to_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_7uint128_to_quads, METH_VARARGS|METH_KEYWORDS, 0};
2163 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_7uint128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2164 PyObject *__pyx_v_items = 0;
2165 unsigned PY_LONG_LONG __pyx_v_n_items;
2166 int __pyx_lineno = 0;
2167 const char *__pyx_filename = NULL;
2168 int __pyx_clineno = 0;
2169 PyObject *__pyx_r = 0;
2170 __Pyx_RefNannyDeclarations
2171 __Pyx_RefNannySetupContext("uint128_to_quads (wrapper)", 0);
2172 {
2173 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0};
2174 PyObject* values[2] = {0,0};
2175 if (unlikely(__pyx_kwds)) {
2176 Py_ssize_t kw_args;
2177 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2178 switch (pos_args) {
2179 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2180 CYTHON_FALLTHROUGH;
2181 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2182 CYTHON_FALLTHROUGH;
2183 case 0: break;
2184 default: goto __pyx_L5_argtuple_error;
2185 }
2186 kw_args = PyDict_Size(__pyx_kwds);
2187 switch (pos_args) {
2188 case 0:
2189 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--;
2190 else goto __pyx_L5_argtuple_error;
2191 CYTHON_FALLTHROUGH;
2192 case 1:
2193 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
2194 else {
2195 __Pyx_RaiseArgtupleInvalid("uint128_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 87, __pyx_L3_error)
2196 }
2197 }
2198 if (unlikely(kw_args > 0)) {
2199 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint128_to_quads") < 0)) __PYX_ERR(0, 87, __pyx_L3_error)
2200 }
2201 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
2202 goto __pyx_L5_argtuple_error;
2203 } else {
2204 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2205 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2206 }
2207 __pyx_v_items = values[0];
2208 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L3_error)
2209 }
2210 goto __pyx_L4_argument_unpacking_done;
2211 __pyx_L5_argtuple_error:;
2212 __Pyx_RaiseArgtupleInvalid("uint128_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error)
2213 __pyx_L3_error:;
2214 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2215 __Pyx_RefNannyFinishContext();
2216 return NULL;
2217 __pyx_L4_argument_unpacking_done:;
2218 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_6uint128_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items);
2219
2220 /* function exit code */
2221 __Pyx_RefNannyFinishContext();
2222 return __pyx_r;
2223 }
2224
2225 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_6uint128_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
2226 unsigned int __pyx_v_factor;
2227 PyObject *__pyx_v_quad_items = NULL;
2228 unsigned PY_LONG_LONG __pyx_v_i;
2229 unsigned PY_LONG_LONG __pyx_v_ix;
2230 PyObject *__pyx_v_x = 0;
2231 PyObject *__pyx_v_item = 0;
2232 PyObject *__pyx_r = NULL;
2233 __Pyx_RefNannyDeclarations
2234 PyObject *__pyx_t_1 = NULL;
2235 unsigned PY_LONG_LONG __pyx_t_2;
2236 unsigned PY_LONG_LONG __pyx_t_3;
2237 unsigned PY_LONG_LONG __pyx_t_4;
2238 PyObject *__pyx_t_5 = NULL;
2239 int __pyx_lineno = 0;
2240 const char *__pyx_filename = NULL;
2241 int __pyx_clineno = 0;
2242 __Pyx_RefNannySetupContext("uint128_to_quads", 0);
2243
2244 /* "clickhouse_driver/columns/largeint.pyx":88
2245 *
2246 * def uint128_to_quads(items, unsigned long long n_items):
2247 * cdef unsigned int factor = 2 # <<<<<<<<<<<<<<
2248 * quad_items = PyTuple_New(n_items * factor)
2249 *
2250 */
2251 __pyx_v_factor = 2;
2252
2253 /* "clickhouse_driver/columns/largeint.pyx":89
2254 * def uint128_to_quads(items, unsigned long long n_items):
2255 * cdef unsigned int factor = 2
2256 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<<
2257 *
2258 * cdef unsigned long long i, ix
2259 */
2260 __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
2261 __Pyx_GOTREF(__pyx_t_1);
2262 __pyx_v_quad_items = ((PyObject*)__pyx_t_1);
2263 __pyx_t_1 = 0;
2264
2265 /* "clickhouse_driver/columns/largeint.pyx":94
2266 * cdef object x, item
2267 *
2268 * for i in range(n_items): # <<<<<<<<<<<<<<
2269 * ix = factor * i
2270 *
2271 */
2272 __pyx_t_2 = __pyx_v_n_items;
2273 __pyx_t_3 = __pyx_t_2;
2274 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
2275 __pyx_v_i = __pyx_t_4;
2276
2277 /* "clickhouse_driver/columns/largeint.pyx":95
2278 *
2279 * for i in range(n_items):
2280 * ix = factor * i # <<<<<<<<<<<<<<
2281 *
2282 * x = items[i]
2283 */
2284 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
2285
2286 /* "clickhouse_driver/columns/largeint.pyx":97
2287 * ix = factor * i
2288 *
2289 * x = items[i] # <<<<<<<<<<<<<<
2290 * item = x & MAX_UINT64
2291 * Py_INCREF(item)
2292 */
2293 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_items, __pyx_v_i, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
2294 __Pyx_GOTREF(__pyx_t_1);
2295 __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
2296 __pyx_t_1 = 0;
2297
2298 /* "clickhouse_driver/columns/largeint.pyx":98
2299 *
2300 * x = items[i]
2301 * item = x & MAX_UINT64 # <<<<<<<<<<<<<<
2302 * Py_INCREF(item)
2303 * PyTuple_SET_ITEM(quad_items, ix, item)
2304 */
2305 __pyx_t_1 = PyNumber_And(__pyx_v_x, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
2306 __Pyx_GOTREF(__pyx_t_1);
2307 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
2308 __pyx_t_1 = 0;
2309
2310 /* "clickhouse_driver/columns/largeint.pyx":99
2311 * x = items[i]
2312 * item = x & MAX_UINT64
2313 * Py_INCREF(item) # <<<<<<<<<<<<<<
2314 * PyTuple_SET_ITEM(quad_items, ix, item)
2315 *
2316 */
2317 Py_INCREF(__pyx_v_item);
2318
2319 /* "clickhouse_driver/columns/largeint.pyx":100
2320 * item = x & MAX_UINT64
2321 * Py_INCREF(item)
2322 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
2323 *
2324 * item = (x >> 64) & MAX_UINT64
2325 */
2326 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
2327
2328 /* "clickhouse_driver/columns/largeint.pyx":102
2329 * PyTuple_SET_ITEM(quad_items, ix, item)
2330 *
2331 * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
2332 * Py_INCREF(item)
2333 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
2334 */
2335 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)
2336 __Pyx_GOTREF(__pyx_t_1);
2337 __pyx_t_5 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 102, __pyx_L1_error)
2338 __Pyx_GOTREF(__pyx_t_5);
2339 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2340 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5);
2341 __pyx_t_5 = 0;
2342
2343 /* "clickhouse_driver/columns/largeint.pyx":103
2344 *
2345 * item = (x >> 64) & MAX_UINT64
2346 * Py_INCREF(item) # <<<<<<<<<<<<<<
2347 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
2348 *
2349 */
2350 Py_INCREF(__pyx_v_item);
2351
2352 /* "clickhouse_driver/columns/largeint.pyx":104
2353 * item = (x >> 64) & MAX_UINT64
2354 * Py_INCREF(item)
2355 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
2356 *
2357 * return quad_items
2358 */
2359 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
2360 }
2361
2362 /* "clickhouse_driver/columns/largeint.pyx":106
2363 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
2364 *
2365 * return quad_items # <<<<<<<<<<<<<<
2366 *
2367 * # 256 bits
2368 */
2369 __Pyx_XDECREF(__pyx_r);
2370 __Pyx_INCREF(__pyx_v_quad_items);
2371 __pyx_r = __pyx_v_quad_items;
2372 goto __pyx_L0;
2373
2374 /* "clickhouse_driver/columns/largeint.pyx":87
2375 *
2376 *
2377 * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
2378 * cdef unsigned int factor = 2
2379 * quad_items = PyTuple_New(n_items * factor)
2380 */
2381
2382 /* function exit code */
2383 __pyx_L1_error:;
2384 __Pyx_XDECREF(__pyx_t_1);
2385 __Pyx_XDECREF(__pyx_t_5);
2386 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2387 __pyx_r = NULL;
2388 __pyx_L0:;
2389 __Pyx_XDECREF(__pyx_v_quad_items);
2390 __Pyx_XDECREF(__pyx_v_x);
2391 __Pyx_XDECREF(__pyx_v_item);
2392 __Pyx_XGIVEREF(__pyx_r);
2393 __Pyx_RefNannyFinishContext();
2394 return __pyx_r;
2395 }
2396
2397 /* "clickhouse_driver/columns/largeint.pyx":111
2398 *
2399 *
2400 * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
2401 * cdef unsigned int factor = 4
2402 * items = PyTuple_New(n_items)
2403 */
2404
2405 /* Python wrapper */
2406 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_9int256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2407 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_9int256_from_quads = {"int256_from_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_9int256_from_quads, METH_VARARGS|METH_KEYWORDS, 0};
2408 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_9int256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2409 PyObject *__pyx_v_quad_items = 0;
2410 unsigned PY_LONG_LONG __pyx_v_n_items;
2411 int __pyx_lineno = 0;
2412 const char *__pyx_filename = NULL;
2413 int __pyx_clineno = 0;
2414 PyObject *__pyx_r = 0;
2415 __Pyx_RefNannyDeclarations
2416 __Pyx_RefNannySetupContext("int256_from_quads (wrapper)", 0);
2417 {
2418 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0};
2419 PyObject* values[2] = {0,0};
2420 if (unlikely(__pyx_kwds)) {
2421 Py_ssize_t kw_args;
2422 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2423 switch (pos_args) {
2424 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2425 CYTHON_FALLTHROUGH;
2426 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2427 CYTHON_FALLTHROUGH;
2428 case 0: break;
2429 default: goto __pyx_L5_argtuple_error;
2430 }
2431 kw_args = PyDict_Size(__pyx_kwds);
2432 switch (pos_args) {
2433 case 0:
2434 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--;
2435 else goto __pyx_L5_argtuple_error;
2436 CYTHON_FALLTHROUGH;
2437 case 1:
2438 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
2439 else {
2440 __Pyx_RaiseArgtupleInvalid("int256_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 111, __pyx_L3_error)
2441 }
2442 }
2443 if (unlikely(kw_args > 0)) {
2444 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int256_from_quads") < 0)) __PYX_ERR(0, 111, __pyx_L3_error)
2445 }
2446 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
2447 goto __pyx_L5_argtuple_error;
2448 } else {
2449 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2450 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2451 }
2452 __pyx_v_quad_items = values[0];
2453 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 111, __pyx_L3_error)
2454 }
2455 goto __pyx_L4_argument_unpacking_done;
2456 __pyx_L5_argtuple_error:;
2457 __Pyx_RaiseArgtupleInvalid("int256_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 111, __pyx_L3_error)
2458 __pyx_L3_error:;
2459 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2460 __Pyx_RefNannyFinishContext();
2461 return NULL;
2462 __pyx_L4_argument_unpacking_done:;
2463 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_8int256_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items);
2464
2465 /* function exit code */
2466 __Pyx_RefNannyFinishContext();
2467 return __pyx_r;
2468 }
2469
2470 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_8int256_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
2471 unsigned int __pyx_v_factor;
2472 PyObject *__pyx_v_items = NULL;
2473 unsigned PY_LONG_LONG __pyx_v_i;
2474 unsigned PY_LONG_LONG __pyx_v_ix;
2475 PyObject *__pyx_v_item = 0;
2476 PyObject *__pyx_r = NULL;
2477 __Pyx_RefNannyDeclarations
2478 PyObject *__pyx_t_1 = NULL;
2479 unsigned PY_LONG_LONG __pyx_t_2;
2480 unsigned PY_LONG_LONG __pyx_t_3;
2481 unsigned PY_LONG_LONG __pyx_t_4;
2482 unsigned PY_LONG_LONG __pyx_t_5;
2483 PyObject *__pyx_t_6 = NULL;
2484 int __pyx_t_7;
2485 PyObject *__pyx_t_8 = NULL;
2486 int __pyx_lineno = 0;
2487 const char *__pyx_filename = NULL;
2488 int __pyx_clineno = 0;
2489 __Pyx_RefNannySetupContext("int256_from_quads", 0);
2490
2491 /* "clickhouse_driver/columns/largeint.pyx":112
2492 *
2493 * def int256_from_quads(quad_items, unsigned long long n_items):
2494 * cdef unsigned int factor = 4 # <<<<<<<<<<<<<<
2495 * items = PyTuple_New(n_items)
2496 *
2497 */
2498 __pyx_v_factor = 4;
2499
2500 /* "clickhouse_driver/columns/largeint.pyx":113
2501 * def int256_from_quads(quad_items, unsigned long long n_items):
2502 * cdef unsigned int factor = 4
2503 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<<
2504 *
2505 * cdef unsigned long long i, ix
2506 */
2507 __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error)
2508 __Pyx_GOTREF(__pyx_t_1);
2509 __pyx_v_items = ((PyObject*)__pyx_t_1);
2510 __pyx_t_1 = 0;
2511
2512 /* "clickhouse_driver/columns/largeint.pyx":118
2513 * cdef object item
2514 *
2515 * for i in range(n_items): # <<<<<<<<<<<<<<
2516 * ix = factor * i
2517 *
2518 */
2519 __pyx_t_2 = __pyx_v_n_items;
2520 __pyx_t_3 = __pyx_t_2;
2521 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
2522 __pyx_v_i = __pyx_t_4;
2523
2524 /* "clickhouse_driver/columns/largeint.pyx":119
2525 *
2526 * for i in range(n_items):
2527 * ix = factor * i # <<<<<<<<<<<<<<
2528 *
2529 * if quad_items[ix + 3] > MAX_INT64:
2530 */
2531 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
2532
2533 /* "clickhouse_driver/columns/largeint.pyx":121
2534 * ix = factor * i
2535 *
2536 * if quad_items[ix + 3] > MAX_INT64: # <<<<<<<<<<<<<<
2537 * item = (
2538 * -((MAX_UINT64 - quad_items[ix + 3]) << 192)
2539 */
2540 __pyx_t_5 = (__pyx_v_ix + 3);
2541 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
2542 __Pyx_GOTREF(__pyx_t_1);
2543 __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 121, __pyx_L1_error)
2544 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2545 __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 121, __pyx_L1_error)
2546 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2547 if (__pyx_t_7) {
2548
2549 /* "clickhouse_driver/columns/largeint.pyx":123
2550 * if quad_items[ix + 3] > MAX_INT64:
2551 * item = (
2552 * -((MAX_UINT64 - quad_items[ix + 3]) << 192) # <<<<<<<<<<<<<<
2553 * -((MAX_UINT64 - quad_items[ix + 2]) << 128)
2554 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
2555 */
2556 __pyx_t_5 = (__pyx_v_ix + 3);
2557 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error)
2558 __Pyx_GOTREF(__pyx_t_6);
2559 __pyx_t_1 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
2560 __Pyx_GOTREF(__pyx_t_1);
2561 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2562 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error)
2563 __Pyx_GOTREF(__pyx_t_6);
2564 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2565 __pyx_t_1 = PyNumber_Negative(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
2566 __Pyx_GOTREF(__pyx_t_1);
2567 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2568
2569 /* "clickhouse_driver/columns/largeint.pyx":124
2570 * item = (
2571 * -((MAX_UINT64 - quad_items[ix + 3]) << 192)
2572 * -((MAX_UINT64 - quad_items[ix + 2]) << 128) # <<<<<<<<<<<<<<
2573 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
2574 * - (MAX_UINT64 - quad_items[ix])
2575 */
2576 __pyx_t_5 = (__pyx_v_ix + 2);
2577 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 124, __pyx_L1_error)
2578 __Pyx_GOTREF(__pyx_t_6);
2579 __pyx_t_8 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 124, __pyx_L1_error)
2580 __Pyx_GOTREF(__pyx_t_8);
2581 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2582 __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 124, __pyx_L1_error)
2583 __Pyx_GOTREF(__pyx_t_6);
2584 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2585 __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 124, __pyx_L1_error)
2586 __Pyx_GOTREF(__pyx_t_8);
2587 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2588 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2589
2590 /* "clickhouse_driver/columns/largeint.pyx":125
2591 * -((MAX_UINT64 - quad_items[ix + 3]) << 192)
2592 * -((MAX_UINT64 - quad_items[ix + 2]) << 128)
2593 * -((MAX_UINT64 - quad_items[ix + 1]) << 64) # <<<<<<<<<<<<<<
2594 * - (MAX_UINT64 - quad_items[ix])
2595 * - 1
2596 */
2597 __pyx_t_5 = (__pyx_v_ix + 1);
2598 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 125, __pyx_L1_error)
2599 __Pyx_GOTREF(__pyx_t_6);
2600 __pyx_t_1 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
2601 __Pyx_GOTREF(__pyx_t_1);
2602 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2603 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 125, __pyx_L1_error)
2604 __Pyx_GOTREF(__pyx_t_6);
2605 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2606 __pyx_t_1 = PyNumber_Subtract(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
2607 __Pyx_GOTREF(__pyx_t_1);
2608 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2609 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2610
2611 /* "clickhouse_driver/columns/largeint.pyx":126
2612 * -((MAX_UINT64 - quad_items[ix + 2]) << 128)
2613 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
2614 * - (MAX_UINT64 - quad_items[ix]) # <<<<<<<<<<<<<<
2615 * - 1
2616 * )
2617 */
2618 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error)
2619 __Pyx_GOTREF(__pyx_t_6);
2620 __pyx_t_8 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 126, __pyx_L1_error)
2621 __Pyx_GOTREF(__pyx_t_8);
2622 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2623 __pyx_t_6 = PyNumber_Subtract(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error)
2624 __Pyx_GOTREF(__pyx_t_6);
2625 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2626 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2627
2628 /* "clickhouse_driver/columns/largeint.pyx":127
2629 * -((MAX_UINT64 - quad_items[ix + 1]) << 64)
2630 * - (MAX_UINT64 - quad_items[ix])
2631 * - 1 # <<<<<<<<<<<<<<
2632 * )
2633 *
2634 */
2635 __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_6, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 127, __pyx_L1_error)
2636 __Pyx_GOTREF(__pyx_t_8);
2637 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2638 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8);
2639 __pyx_t_8 = 0;
2640
2641 /* "clickhouse_driver/columns/largeint.pyx":121
2642 * ix = factor * i
2643 *
2644 * if quad_items[ix + 3] > MAX_INT64: # <<<<<<<<<<<<<<
2645 * item = (
2646 * -((MAX_UINT64 - quad_items[ix + 3]) << 192)
2647 */
2648 goto __pyx_L5;
2649 }
2650
2651 /* "clickhouse_driver/columns/largeint.pyx":134
2652 * (quad_items[ix + 3] << 192) +
2653 * (quad_items[ix + 2] << 128) +
2654 * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<<
2655 * quad_items[ix]
2656 * )
2657 */
2658 /*else*/ {
2659
2660 /* "clickhouse_driver/columns/largeint.pyx":132
2661 * else:
2662 * item = (
2663 * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<<
2664 * (quad_items[ix + 2] << 128) +
2665 * (quad_items[ix + 1] << 64) +
2666 */
2667 __pyx_t_5 = (__pyx_v_ix + 3);
2668 __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 132, __pyx_L1_error)
2669 __Pyx_GOTREF(__pyx_t_8);
2670 __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error)
2671 __Pyx_GOTREF(__pyx_t_6);
2672 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2673
2674 /* "clickhouse_driver/columns/largeint.pyx":133
2675 * item = (
2676 * (quad_items[ix + 3] << 192) +
2677 * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<<
2678 * (quad_items[ix + 1] << 64) +
2679 * quad_items[ix]
2680 */
2681 __pyx_t_5 = (__pyx_v_ix + 2);
2682 __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 133, __pyx_L1_error)
2683 __Pyx_GOTREF(__pyx_t_8);
2684 __pyx_t_1 = PyNumber_Lshift(__pyx_t_8, __pyx_int_128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
2685 __Pyx_GOTREF(__pyx_t_1);
2686 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2687
2688 /* "clickhouse_driver/columns/largeint.pyx":132
2689 * else:
2690 * item = (
2691 * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<<
2692 * (quad_items[ix + 2] << 128) +
2693 * (quad_items[ix + 1] << 64) +
2694 */
2695 __pyx_t_8 = PyNumber_Add(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 132, __pyx_L1_error)
2696 __Pyx_GOTREF(__pyx_t_8);
2697 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2698 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2699
2700 /* "clickhouse_driver/columns/largeint.pyx":134
2701 * (quad_items[ix + 3] << 192) +
2702 * (quad_items[ix + 2] << 128) +
2703 * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<<
2704 * quad_items[ix]
2705 * )
2706 */
2707 __pyx_t_5 = (__pyx_v_ix + 1);
2708 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
2709 __Pyx_GOTREF(__pyx_t_1);
2710 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 134, __pyx_L1_error)
2711 __Pyx_GOTREF(__pyx_t_6);
2712 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2713
2714 /* "clickhouse_driver/columns/largeint.pyx":133
2715 * item = (
2716 * (quad_items[ix + 3] << 192) +
2717 * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<<
2718 * (quad_items[ix + 1] << 64) +
2719 * quad_items[ix]
2720 */
2721 __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
2722 __Pyx_GOTREF(__pyx_t_1);
2723 __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2724 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2725
2726 /* "clickhouse_driver/columns/largeint.pyx":135
2727 * (quad_items[ix + 2] << 128) +
2728 * (quad_items[ix + 1] << 64) +
2729 * quad_items[ix] # <<<<<<<<<<<<<<
2730 * )
2731 *
2732 */
2733 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 135, __pyx_L1_error)
2734 __Pyx_GOTREF(__pyx_t_6);
2735
2736 /* "clickhouse_driver/columns/largeint.pyx":134
2737 * (quad_items[ix + 3] << 192) +
2738 * (quad_items[ix + 2] << 128) +
2739 * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<<
2740 * quad_items[ix]
2741 * )
2742 */
2743 __pyx_t_8 = PyNumber_Add(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 134, __pyx_L1_error)
2744 __Pyx_GOTREF(__pyx_t_8);
2745 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2746 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2747 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8);
2748 __pyx_t_8 = 0;
2749 }
2750 __pyx_L5:;
2751
2752 /* "clickhouse_driver/columns/largeint.pyx":138
2753 * )
2754 *
2755 * Py_INCREF(item) # <<<<<<<<<<<<<<
2756 * PyTuple_SET_ITEM(items, i, item)
2757 *
2758 */
2759 Py_INCREF(__pyx_v_item);
2760
2761 /* "clickhouse_driver/columns/largeint.pyx":139
2762 *
2763 * Py_INCREF(item)
2764 * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<<
2765 *
2766 * return items
2767 */
2768 PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item);
2769 }
2770
2771 /* "clickhouse_driver/columns/largeint.pyx":141
2772 * PyTuple_SET_ITEM(items, i, item)
2773 *
2774 * return items # <<<<<<<<<<<<<<
2775 *
2776 *
2777 */
2778 __Pyx_XDECREF(__pyx_r);
2779 __Pyx_INCREF(__pyx_v_items);
2780 __pyx_r = __pyx_v_items;
2781 goto __pyx_L0;
2782
2783 /* "clickhouse_driver/columns/largeint.pyx":111
2784 *
2785 *
2786 * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
2787 * cdef unsigned int factor = 4
2788 * items = PyTuple_New(n_items)
2789 */
2790
2791 /* function exit code */
2792 __pyx_L1_error:;
2793 __Pyx_XDECREF(__pyx_t_1);
2794 __Pyx_XDECREF(__pyx_t_6);
2795 __Pyx_XDECREF(__pyx_t_8);
2796 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2797 __pyx_r = NULL;
2798 __pyx_L0:;
2799 __Pyx_XDECREF(__pyx_v_items);
2800 __Pyx_XDECREF(__pyx_v_item);
2801 __Pyx_XGIVEREF(__pyx_r);
2802 __Pyx_RefNannyFinishContext();
2803 return __pyx_r;
2804 }
2805
2806 /* "clickhouse_driver/columns/largeint.pyx":144
2807 *
2808 *
2809 * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
2810 * cdef unsigned int factor = 4
2811 * quad_items = PyTuple_New(n_items * factor)
2812 */
2813
2814 /* Python wrapper */
2815 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_11int256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2816 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_11int256_to_quads = {"int256_to_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_11int256_to_quads, METH_VARARGS|METH_KEYWORDS, 0};
2817 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_11int256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2818 PyObject *__pyx_v_items = 0;
2819 unsigned PY_LONG_LONG __pyx_v_n_items;
2820 int __pyx_lineno = 0;
2821 const char *__pyx_filename = NULL;
2822 int __pyx_clineno = 0;
2823 PyObject *__pyx_r = 0;
2824 __Pyx_RefNannyDeclarations
2825 __Pyx_RefNannySetupContext("int256_to_quads (wrapper)", 0);
2826 {
2827 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0};
2828 PyObject* values[2] = {0,0};
2829 if (unlikely(__pyx_kwds)) {
2830 Py_ssize_t kw_args;
2831 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2832 switch (pos_args) {
2833 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2834 CYTHON_FALLTHROUGH;
2835 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2836 CYTHON_FALLTHROUGH;
2837 case 0: break;
2838 default: goto __pyx_L5_argtuple_error;
2839 }
2840 kw_args = PyDict_Size(__pyx_kwds);
2841 switch (pos_args) {
2842 case 0:
2843 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--;
2844 else goto __pyx_L5_argtuple_error;
2845 CYTHON_FALLTHROUGH;
2846 case 1:
2847 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
2848 else {
2849 __Pyx_RaiseArgtupleInvalid("int256_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 144, __pyx_L3_error)
2850 }
2851 }
2852 if (unlikely(kw_args > 0)) {
2853 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int256_to_quads") < 0)) __PYX_ERR(0, 144, __pyx_L3_error)
2854 }
2855 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
2856 goto __pyx_L5_argtuple_error;
2857 } else {
2858 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2859 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2860 }
2861 __pyx_v_items = values[0];
2862 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 144, __pyx_L3_error)
2863 }
2864 goto __pyx_L4_argument_unpacking_done;
2865 __pyx_L5_argtuple_error:;
2866 __Pyx_RaiseArgtupleInvalid("int256_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 144, __pyx_L3_error)
2867 __pyx_L3_error:;
2868 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
2869 __Pyx_RefNannyFinishContext();
2870 return NULL;
2871 __pyx_L4_argument_unpacking_done:;
2872 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_10int256_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items);
2873
2874 /* function exit code */
2875 __Pyx_RefNannyFinishContext();
2876 return __pyx_r;
2877 }
2878
2879 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_10int256_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
2880 unsigned int __pyx_v_factor;
2881 PyObject *__pyx_v_quad_items = NULL;
2882 unsigned PY_LONG_LONG __pyx_v_i;
2883 unsigned PY_LONG_LONG __pyx_v_ix;
2884 PyObject *__pyx_v_x = 0;
2885 PyObject *__pyx_v_item = 0;
2886 PyObject *__pyx_r = NULL;
2887 __Pyx_RefNannyDeclarations
2888 PyObject *__pyx_t_1 = NULL;
2889 unsigned PY_LONG_LONG __pyx_t_2;
2890 unsigned PY_LONG_LONG __pyx_t_3;
2891 unsigned PY_LONG_LONG __pyx_t_4;
2892 int __pyx_t_5;
2893 PyObject *__pyx_t_6 = NULL;
2894 int __pyx_lineno = 0;
2895 const char *__pyx_filename = NULL;
2896 int __pyx_clineno = 0;
2897 __Pyx_RefNannySetupContext("int256_to_quads", 0);
2898
2899 /* "clickhouse_driver/columns/largeint.pyx":145
2900 *
2901 * def int256_to_quads(items, unsigned long long n_items):
2902 * cdef unsigned int factor = 4 # <<<<<<<<<<<<<<
2903 * quad_items = PyTuple_New(n_items * factor)
2904 *
2905 */
2906 __pyx_v_factor = 4;
2907
2908 /* "clickhouse_driver/columns/largeint.pyx":146
2909 * def int256_to_quads(items, unsigned long long n_items):
2910 * cdef unsigned int factor = 4
2911 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<<
2912 *
2913 * cdef unsigned long long i, ix
2914 */
2915 __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error)
2916 __Pyx_GOTREF(__pyx_t_1);
2917 __pyx_v_quad_items = ((PyObject*)__pyx_t_1);
2918 __pyx_t_1 = 0;
2919
2920 /* "clickhouse_driver/columns/largeint.pyx":151
2921 * cdef object x, item
2922 *
2923 * for i in range(n_items): # <<<<<<<<<<<<<<
2924 * ix = factor * i
2925 *
2926 */
2927 __pyx_t_2 = __pyx_v_n_items;
2928 __pyx_t_3 = __pyx_t_2;
2929 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
2930 __pyx_v_i = __pyx_t_4;
2931
2932 /* "clickhouse_driver/columns/largeint.pyx":152
2933 *
2934 * for i in range(n_items):
2935 * ix = factor * i # <<<<<<<<<<<<<<
2936 *
2937 * x = items[i]
2938 */
2939 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
2940
2941 /* "clickhouse_driver/columns/largeint.pyx":154
2942 * ix = factor * i
2943 *
2944 * x = items[i] # <<<<<<<<<<<<<<
2945 * if x < 0:
2946 * x = -x - 1
2947 */
2948 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_items, __pyx_v_i, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error)
2949 __Pyx_GOTREF(__pyx_t_1);
2950 __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
2951 __pyx_t_1 = 0;
2952
2953 /* "clickhouse_driver/columns/largeint.pyx":155
2954 *
2955 * x = items[i]
2956 * if x < 0: # <<<<<<<<<<<<<<
2957 * x = -x - 1
2958 *
2959 */
2960 __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error)
2961 __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 155, __pyx_L1_error)
2962 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2963 if (__pyx_t_5) {
2964
2965 /* "clickhouse_driver/columns/largeint.pyx":156
2966 * x = items[i]
2967 * if x < 0:
2968 * x = -x - 1 # <<<<<<<<<<<<<<
2969 *
2970 * item = MAX_UINT64 - x & MAX_UINT64
2971 */
2972 __pyx_t_1 = PyNumber_Negative(__pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error)
2973 __Pyx_GOTREF(__pyx_t_1);
2974 __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
2975 __Pyx_GOTREF(__pyx_t_6);
2976 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2977 __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_6);
2978 __pyx_t_6 = 0;
2979
2980 /* "clickhouse_driver/columns/largeint.pyx":158
2981 * x = -x - 1
2982 *
2983 * item = MAX_UINT64 - x & MAX_UINT64 # <<<<<<<<<<<<<<
2984 * Py_INCREF(item)
2985 * PyTuple_SET_ITEM(quad_items, ix, item)
2986 */
2987 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_v_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)
2988 __Pyx_GOTREF(__pyx_t_6);
2989 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error)
2990 __Pyx_GOTREF(__pyx_t_1);
2991 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2992 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
2993 __pyx_t_1 = 0;
2994
2995 /* "clickhouse_driver/columns/largeint.pyx":159
2996 *
2997 * item = MAX_UINT64 - x & MAX_UINT64
2998 * Py_INCREF(item) # <<<<<<<<<<<<<<
2999 * PyTuple_SET_ITEM(quad_items, ix, item)
3000 *
3001 */
3002 Py_INCREF(__pyx_v_item);
3003
3004 /* "clickhouse_driver/columns/largeint.pyx":160
3005 * item = MAX_UINT64 - x & MAX_UINT64
3006 * Py_INCREF(item)
3007 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
3008 *
3009 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
3010 */
3011 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
3012
3013 /* "clickhouse_driver/columns/largeint.pyx":162
3014 * PyTuple_SET_ITEM(quad_items, ix, item)
3015 *
3016 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
3017 * Py_INCREF(item)
3018 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3019 */
3020 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
3021 __Pyx_GOTREF(__pyx_t_1);
3022 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error)
3023 __Pyx_GOTREF(__pyx_t_6);
3024 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3025 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
3026 __Pyx_GOTREF(__pyx_t_1);
3027 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3028 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
3029 __pyx_t_1 = 0;
3030
3031 /* "clickhouse_driver/columns/largeint.pyx":163
3032 *
3033 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
3034 * Py_INCREF(item) # <<<<<<<<<<<<<<
3035 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3036 *
3037 */
3038 Py_INCREF(__pyx_v_item);
3039
3040 /* "clickhouse_driver/columns/largeint.pyx":164
3041 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64
3042 * Py_INCREF(item)
3043 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
3044 *
3045 * item = MAX_UINT64 - (x >> 128) & MAX_UINT64
3046 */
3047 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
3048
3049 /* "clickhouse_driver/columns/largeint.pyx":166
3050 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3051 *
3052 * item = MAX_UINT64 - (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<<
3053 * Py_INCREF(item)
3054 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3055 */
3056 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
3057 __Pyx_GOTREF(__pyx_t_1);
3058 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 166, __pyx_L1_error)
3059 __Pyx_GOTREF(__pyx_t_6);
3060 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3061 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
3062 __Pyx_GOTREF(__pyx_t_1);
3063 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3064 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
3065 __pyx_t_1 = 0;
3066
3067 /* "clickhouse_driver/columns/largeint.pyx":167
3068 *
3069 * item = MAX_UINT64 - (x >> 128) & MAX_UINT64
3070 * Py_INCREF(item) # <<<<<<<<<<<<<<
3071 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3072 *
3073 */
3074 Py_INCREF(__pyx_v_item);
3075
3076 /* "clickhouse_driver/columns/largeint.pyx":168
3077 * item = MAX_UINT64 - (x >> 128) & MAX_UINT64
3078 * Py_INCREF(item)
3079 * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<<
3080 *
3081 * item = MAX_UINT64 - (x >> 192) & MAX_UINT64
3082 */
3083 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item);
3084
3085 /* "clickhouse_driver/columns/largeint.pyx":170
3086 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3087 *
3088 * item = MAX_UINT64 - (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<<
3089 * Py_INCREF(item)
3090 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3091 */
3092 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error)
3093 __Pyx_GOTREF(__pyx_t_1);
3094 __pyx_t_6 = PyNumber_Subtract(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 170, __pyx_L1_error)
3095 __Pyx_GOTREF(__pyx_t_6);
3096 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3097 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error)
3098 __Pyx_GOTREF(__pyx_t_1);
3099 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3100 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
3101 __pyx_t_1 = 0;
3102
3103 /* "clickhouse_driver/columns/largeint.pyx":171
3104 *
3105 * item = MAX_UINT64 - (x >> 192) & MAX_UINT64
3106 * Py_INCREF(item) # <<<<<<<<<<<<<<
3107 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3108 *
3109 */
3110 Py_INCREF(__pyx_v_item);
3111
3112 /* "clickhouse_driver/columns/largeint.pyx":172
3113 * item = MAX_UINT64 - (x >> 192) & MAX_UINT64
3114 * Py_INCREF(item)
3115 * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<<
3116 *
3117 * else:
3118 */
3119 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item);
3120
3121 /* "clickhouse_driver/columns/largeint.pyx":155
3122 *
3123 * x = items[i]
3124 * if x < 0: # <<<<<<<<<<<<<<
3125 * x = -x - 1
3126 *
3127 */
3128 goto __pyx_L5;
3129 }
3130
3131 /* "clickhouse_driver/columns/largeint.pyx":175
3132 *
3133 * else:
3134 * item = x & MAX_UINT64 # <<<<<<<<<<<<<<
3135 * Py_INCREF(item)
3136 * PyTuple_SET_ITEM(quad_items, ix, item)
3137 */
3138 /*else*/ {
3139 __pyx_t_1 = PyNumber_And(__pyx_v_x, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error)
3140 __Pyx_GOTREF(__pyx_t_1);
3141 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
3142 __pyx_t_1 = 0;
3143
3144 /* "clickhouse_driver/columns/largeint.pyx":176
3145 * else:
3146 * item = x & MAX_UINT64
3147 * Py_INCREF(item) # <<<<<<<<<<<<<<
3148 * PyTuple_SET_ITEM(quad_items, ix, item)
3149 *
3150 */
3151 Py_INCREF(__pyx_v_item);
3152
3153 /* "clickhouse_driver/columns/largeint.pyx":177
3154 * item = x & MAX_UINT64
3155 * Py_INCREF(item)
3156 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
3157 *
3158 * item = (x >> 64) & MAX_UINT64
3159 */
3160 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
3161
3162 /* "clickhouse_driver/columns/largeint.pyx":179
3163 * PyTuple_SET_ITEM(quad_items, ix, item)
3164 *
3165 * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
3166 * Py_INCREF(item)
3167 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3168 */
3169 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error)
3170 __Pyx_GOTREF(__pyx_t_1);
3171 __pyx_t_6 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 179, __pyx_L1_error)
3172 __Pyx_GOTREF(__pyx_t_6);
3173 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3174 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6);
3175 __pyx_t_6 = 0;
3176
3177 /* "clickhouse_driver/columns/largeint.pyx":180
3178 *
3179 * item = (x >> 64) & MAX_UINT64
3180 * Py_INCREF(item) # <<<<<<<<<<<<<<
3181 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3182 *
3183 */
3184 Py_INCREF(__pyx_v_item);
3185
3186 /* "clickhouse_driver/columns/largeint.pyx":181
3187 * item = (x >> 64) & MAX_UINT64
3188 * Py_INCREF(item)
3189 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
3190 *
3191 * item = (x >> 128) & MAX_UINT64
3192 */
3193 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
3194
3195 /* "clickhouse_driver/columns/largeint.pyx":183
3196 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3197 *
3198 * item = (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<<
3199 * Py_INCREF(item)
3200 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3201 */
3202 __pyx_t_6 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 183, __pyx_L1_error)
3203 __Pyx_GOTREF(__pyx_t_6);
3204 __pyx_t_1 = PyNumber_And(__pyx_t_6, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 183, __pyx_L1_error)
3205 __Pyx_GOTREF(__pyx_t_1);
3206 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3207 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
3208 __pyx_t_1 = 0;
3209
3210 /* "clickhouse_driver/columns/largeint.pyx":184
3211 *
3212 * item = (x >> 128) & MAX_UINT64
3213 * Py_INCREF(item) # <<<<<<<<<<<<<<
3214 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3215 *
3216 */
3217 Py_INCREF(__pyx_v_item);
3218
3219 /* "clickhouse_driver/columns/largeint.pyx":185
3220 * item = (x >> 128) & MAX_UINT64
3221 * Py_INCREF(item)
3222 * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<<
3223 *
3224 * item = (x >> 192) & MAX_UINT64
3225 */
3226 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item);
3227
3228 /* "clickhouse_driver/columns/largeint.pyx":187
3229 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3230 *
3231 * item = (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<<
3232 * Py_INCREF(item)
3233 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3234 */
3235 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error)
3236 __Pyx_GOTREF(__pyx_t_1);
3237 __pyx_t_6 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
3238 __Pyx_GOTREF(__pyx_t_6);
3239 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3240 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6);
3241 __pyx_t_6 = 0;
3242
3243 /* "clickhouse_driver/columns/largeint.pyx":188
3244 *
3245 * item = (x >> 192) & MAX_UINT64
3246 * Py_INCREF(item) # <<<<<<<<<<<<<<
3247 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3248 *
3249 */
3250 Py_INCREF(__pyx_v_item);
3251
3252 /* "clickhouse_driver/columns/largeint.pyx":189
3253 * item = (x >> 192) & MAX_UINT64
3254 * Py_INCREF(item)
3255 * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<<
3256 *
3257 * return quad_items
3258 */
3259 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item);
3260 }
3261 __pyx_L5:;
3262 }
3263
3264 /* "clickhouse_driver/columns/largeint.pyx":191
3265 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3266 *
3267 * return quad_items # <<<<<<<<<<<<<<
3268 *
3269 *
3270 */
3271 __Pyx_XDECREF(__pyx_r);
3272 __Pyx_INCREF(__pyx_v_quad_items);
3273 __pyx_r = __pyx_v_quad_items;
3274 goto __pyx_L0;
3275
3276 /* "clickhouse_driver/columns/largeint.pyx":144
3277 *
3278 *
3279 * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
3280 * cdef unsigned int factor = 4
3281 * quad_items = PyTuple_New(n_items * factor)
3282 */
3283
3284 /* function exit code */
3285 __pyx_L1_error:;
3286 __Pyx_XDECREF(__pyx_t_1);
3287 __Pyx_XDECREF(__pyx_t_6);
3288 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
3289 __pyx_r = NULL;
3290 __pyx_L0:;
3291 __Pyx_XDECREF(__pyx_v_quad_items);
3292 __Pyx_XDECREF(__pyx_v_x);
3293 __Pyx_XDECREF(__pyx_v_item);
3294 __Pyx_XGIVEREF(__pyx_r);
3295 __Pyx_RefNannyFinishContext();
3296 return __pyx_r;
3297 }
3298
3299 /* "clickhouse_driver/columns/largeint.pyx":194
3300 *
3301 *
3302 * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
3303 * cdef unsigned int factor = 4
3304 * items = PyTuple_New(n_items)
3305 */
3306
3307 /* Python wrapper */
3308 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_13uint256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3309 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_13uint256_from_quads = {"uint256_from_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_13uint256_from_quads, METH_VARARGS|METH_KEYWORDS, 0};
3310 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_13uint256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3311 PyObject *__pyx_v_quad_items = 0;
3312 unsigned PY_LONG_LONG __pyx_v_n_items;
3313 int __pyx_lineno = 0;
3314 const char *__pyx_filename = NULL;
3315 int __pyx_clineno = 0;
3316 PyObject *__pyx_r = 0;
3317 __Pyx_RefNannyDeclarations
3318 __Pyx_RefNannySetupContext("uint256_from_quads (wrapper)", 0);
3319 {
3320 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0};
3321 PyObject* values[2] = {0,0};
3322 if (unlikely(__pyx_kwds)) {
3323 Py_ssize_t kw_args;
3324 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
3325 switch (pos_args) {
3326 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3327 CYTHON_FALLTHROUGH;
3328 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3329 CYTHON_FALLTHROUGH;
3330 case 0: break;
3331 default: goto __pyx_L5_argtuple_error;
3332 }
3333 kw_args = PyDict_Size(__pyx_kwds);
3334 switch (pos_args) {
3335 case 0:
3336 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--;
3337 else goto __pyx_L5_argtuple_error;
3338 CYTHON_FALLTHROUGH;
3339 case 1:
3340 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
3341 else {
3342 __Pyx_RaiseArgtupleInvalid("uint256_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 194, __pyx_L3_error)
3343 }
3344 }
3345 if (unlikely(kw_args > 0)) {
3346 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint256_from_quads") < 0)) __PYX_ERR(0, 194, __pyx_L3_error)
3347 }
3348 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
3349 goto __pyx_L5_argtuple_error;
3350 } else {
3351 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3352 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3353 }
3354 __pyx_v_quad_items = values[0];
3355 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L3_error)
3356 }
3357 goto __pyx_L4_argument_unpacking_done;
3358 __pyx_L5_argtuple_error:;
3359 __Pyx_RaiseArgtupleInvalid("uint256_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 194, __pyx_L3_error)
3360 __pyx_L3_error:;
3361 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
3362 __Pyx_RefNannyFinishContext();
3363 return NULL;
3364 __pyx_L4_argument_unpacking_done:;
3365 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_12uint256_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items);
3366
3367 /* function exit code */
3368 __Pyx_RefNannyFinishContext();
3369 return __pyx_r;
3370 }
3371
3372 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_12uint256_from_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quad_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
3373 unsigned int __pyx_v_factor;
3374 PyObject *__pyx_v_items = NULL;
3375 unsigned PY_LONG_LONG __pyx_v_i;
3376 unsigned PY_LONG_LONG __pyx_v_ix;
3377 PyObject *__pyx_v_item = 0;
3378 PyObject *__pyx_r = NULL;
3379 __Pyx_RefNannyDeclarations
3380 PyObject *__pyx_t_1 = NULL;
3381 unsigned PY_LONG_LONG __pyx_t_2;
3382 unsigned PY_LONG_LONG __pyx_t_3;
3383 unsigned PY_LONG_LONG __pyx_t_4;
3384 unsigned PY_LONG_LONG __pyx_t_5;
3385 PyObject *__pyx_t_6 = NULL;
3386 PyObject *__pyx_t_7 = NULL;
3387 int __pyx_lineno = 0;
3388 const char *__pyx_filename = NULL;
3389 int __pyx_clineno = 0;
3390 __Pyx_RefNannySetupContext("uint256_from_quads", 0);
3391
3392 /* "clickhouse_driver/columns/largeint.pyx":195
3393 *
3394 * def uint256_from_quads(quad_items, unsigned long long n_items):
3395 * cdef unsigned int factor = 4 # <<<<<<<<<<<<<<
3396 * items = PyTuple_New(n_items)
3397 *
3398 */
3399 __pyx_v_factor = 4;
3400
3401 /* "clickhouse_driver/columns/largeint.pyx":196
3402 * def uint256_from_quads(quad_items, unsigned long long n_items):
3403 * cdef unsigned int factor = 4
3404 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<<
3405 *
3406 * cdef unsigned long long i, ix
3407 */
3408 __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error)
3409 __Pyx_GOTREF(__pyx_t_1);
3410 __pyx_v_items = ((PyObject*)__pyx_t_1);
3411 __pyx_t_1 = 0;
3412
3413 /* "clickhouse_driver/columns/largeint.pyx":201
3414 * cdef object item
3415 *
3416 * for i in range(n_items): # <<<<<<<<<<<<<<
3417 * ix = factor * i
3418 * item = (
3419 */
3420 __pyx_t_2 = __pyx_v_n_items;
3421 __pyx_t_3 = __pyx_t_2;
3422 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
3423 __pyx_v_i = __pyx_t_4;
3424
3425 /* "clickhouse_driver/columns/largeint.pyx":202
3426 *
3427 * for i in range(n_items):
3428 * ix = factor * i # <<<<<<<<<<<<<<
3429 * item = (
3430 * (quad_items[ix + 3] << 192) +
3431 */
3432 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
3433
3434 /* "clickhouse_driver/columns/largeint.pyx":204
3435 * ix = factor * i
3436 * item = (
3437 * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<<
3438 * (quad_items[ix + 2] << 128) +
3439 * (quad_items[ix + 1] << 64) +
3440 */
3441 __pyx_t_5 = (__pyx_v_ix + 3);
3442 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
3443 __Pyx_GOTREF(__pyx_t_1);
3444 __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
3445 __Pyx_GOTREF(__pyx_t_6);
3446 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3447
3448 /* "clickhouse_driver/columns/largeint.pyx":205
3449 * item = (
3450 * (quad_items[ix + 3] << 192) +
3451 * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<<
3452 * (quad_items[ix + 1] << 64) +
3453 * quad_items[ix]
3454 */
3455 __pyx_t_5 = (__pyx_v_ix + 2);
3456 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)
3457 __Pyx_GOTREF(__pyx_t_1);
3458 __pyx_t_7 = PyNumber_Lshift(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 205, __pyx_L1_error)
3459 __Pyx_GOTREF(__pyx_t_7);
3460 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3461
3462 /* "clickhouse_driver/columns/largeint.pyx":204
3463 * ix = factor * i
3464 * item = (
3465 * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<<
3466 * (quad_items[ix + 2] << 128) +
3467 * (quad_items[ix + 1] << 64) +
3468 */
3469 __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
3470 __Pyx_GOTREF(__pyx_t_1);
3471 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3472 __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
3473
3474 /* "clickhouse_driver/columns/largeint.pyx":206
3475 * (quad_items[ix + 3] << 192) +
3476 * (quad_items[ix + 2] << 128) +
3477 * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<<
3478 * quad_items[ix]
3479 * )
3480 */
3481 __pyx_t_5 = (__pyx_v_ix + 1);
3482 __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_t_5, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 206, __pyx_L1_error)
3483 __Pyx_GOTREF(__pyx_t_7);
3484 __pyx_t_6 = PyNumber_Lshift(__pyx_t_7, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 206, __pyx_L1_error)
3485 __Pyx_GOTREF(__pyx_t_6);
3486 __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
3487
3488 /* "clickhouse_driver/columns/largeint.pyx":205
3489 * item = (
3490 * (quad_items[ix + 3] << 192) +
3491 * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<<
3492 * (quad_items[ix + 1] << 64) +
3493 * quad_items[ix]
3494 */
3495 __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 205, __pyx_L1_error)
3496 __Pyx_GOTREF(__pyx_t_7);
3497 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3498 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3499
3500 /* "clickhouse_driver/columns/largeint.pyx":207
3501 * (quad_items[ix + 2] << 128) +
3502 * (quad_items[ix + 1] << 64) +
3503 * quad_items[ix] # <<<<<<<<<<<<<<
3504 * )
3505 *
3506 */
3507 __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_quad_items, __pyx_v_ix, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 207, __pyx_L1_error)
3508 __Pyx_GOTREF(__pyx_t_6);
3509
3510 /* "clickhouse_driver/columns/largeint.pyx":206
3511 * (quad_items[ix + 3] << 192) +
3512 * (quad_items[ix + 2] << 128) +
3513 * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<<
3514 * quad_items[ix]
3515 * )
3516 */
3517 __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error)
3518 __Pyx_GOTREF(__pyx_t_1);
3519 __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
3520 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3521 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
3522 __pyx_t_1 = 0;
3523
3524 /* "clickhouse_driver/columns/largeint.pyx":210
3525 * )
3526 *
3527 * Py_INCREF(item) # <<<<<<<<<<<<<<
3528 * PyTuple_SET_ITEM(items, i, item)
3529 *
3530 */
3531 Py_INCREF(__pyx_v_item);
3532
3533 /* "clickhouse_driver/columns/largeint.pyx":211
3534 *
3535 * Py_INCREF(item)
3536 * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<<
3537 *
3538 * return items
3539 */
3540 PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item);
3541 }
3542
3543 /* "clickhouse_driver/columns/largeint.pyx":213
3544 * PyTuple_SET_ITEM(items, i, item)
3545 *
3546 * return items # <<<<<<<<<<<<<<
3547 *
3548 *
3549 */
3550 __Pyx_XDECREF(__pyx_r);
3551 __Pyx_INCREF(__pyx_v_items);
3552 __pyx_r = __pyx_v_items;
3553 goto __pyx_L0;
3554
3555 /* "clickhouse_driver/columns/largeint.pyx":194
3556 *
3557 *
3558 * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
3559 * cdef unsigned int factor = 4
3560 * items = PyTuple_New(n_items)
3561 */
3562
3563 /* function exit code */
3564 __pyx_L1_error:;
3565 __Pyx_XDECREF(__pyx_t_1);
3566 __Pyx_XDECREF(__pyx_t_6);
3567 __Pyx_XDECREF(__pyx_t_7);
3568 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
3569 __pyx_r = NULL;
3570 __pyx_L0:;
3571 __Pyx_XDECREF(__pyx_v_items);
3572 __Pyx_XDECREF(__pyx_v_item);
3573 __Pyx_XGIVEREF(__pyx_r);
3574 __Pyx_RefNannyFinishContext();
3575 return __pyx_r;
3576 }
3577
3578 /* "clickhouse_driver/columns/largeint.pyx":216
3579 *
3580 *
3581 * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
3582 * cdef unsigned int factor = 4
3583 * quad_items = PyTuple_New(n_items * factor)
3584 */
3585
3586 /* Python wrapper */
3587 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_15uint256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3588 static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_8largeint_15uint256_to_quads = {"uint256_to_quads", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_7columns_8largeint_15uint256_to_quads, METH_VARARGS|METH_KEYWORDS, 0};
3589 static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_15uint256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3590 PyObject *__pyx_v_items = 0;
3591 unsigned PY_LONG_LONG __pyx_v_n_items;
3592 int __pyx_lineno = 0;
3593 const char *__pyx_filename = NULL;
3594 int __pyx_clineno = 0;
3595 PyObject *__pyx_r = 0;
3596 __Pyx_RefNannyDeclarations
3597 __Pyx_RefNannySetupContext("uint256_to_quads (wrapper)", 0);
3598 {
3599 static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0};
3600 PyObject* values[2] = {0,0};
3601 if (unlikely(__pyx_kwds)) {
3602 Py_ssize_t kw_args;
3603 const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
3604 switch (pos_args) {
3605 case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3606 CYTHON_FALLTHROUGH;
3607 case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3608 CYTHON_FALLTHROUGH;
3609 case 0: break;
3610 default: goto __pyx_L5_argtuple_error;
3611 }
3612 kw_args = PyDict_Size(__pyx_kwds);
3613 switch (pos_args) {
3614 case 0:
3615 if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--;
3616 else goto __pyx_L5_argtuple_error;
3617 CYTHON_FALLTHROUGH;
3618 case 1:
3619 if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--;
3620 else {
3621 __Pyx_RaiseArgtupleInvalid("uint256_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 216, __pyx_L3_error)
3622 }
3623 }
3624 if (unlikely(kw_args > 0)) {
3625 if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint256_to_quads") < 0)) __PYX_ERR(0, 216, __pyx_L3_error)
3626 }
3627 } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
3628 goto __pyx_L5_argtuple_error;
3629 } else {
3630 values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3631 values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3632 }
3633 __pyx_v_items = values[0];
3634 __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[1]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 216, __pyx_L3_error)
3635 }
3636 goto __pyx_L4_argument_unpacking_done;
3637 __pyx_L5_argtuple_error:;
3638 __Pyx_RaiseArgtupleInvalid("uint256_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 216, __pyx_L3_error)
3639 __pyx_L3_error:;
3640 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
3641 __Pyx_RefNannyFinishContext();
3642 return NULL;
3643 __pyx_L4_argument_unpacking_done:;
3644 __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_14uint256_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items);
3645
3646 /* function exit code */
3647 __Pyx_RefNannyFinishContext();
3648 return __pyx_r;
3649 }
3650
3651 static PyObject *__pyx_pf_17clickhouse_driver_7columns_8largeint_14uint256_to_quads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, unsigned PY_LONG_LONG __pyx_v_n_items) {
3652 unsigned int __pyx_v_factor;
3653 PyObject *__pyx_v_quad_items = NULL;
3654 unsigned PY_LONG_LONG __pyx_v_i;
3655 unsigned PY_LONG_LONG __pyx_v_ix;
3656 PyObject *__pyx_v_x = 0;
3657 PyObject *__pyx_v_item = 0;
3658 PyObject *__pyx_r = NULL;
3659 __Pyx_RefNannyDeclarations
3660 PyObject *__pyx_t_1 = NULL;
3661 unsigned PY_LONG_LONG __pyx_t_2;
3662 unsigned PY_LONG_LONG __pyx_t_3;
3663 unsigned PY_LONG_LONG __pyx_t_4;
3664 PyObject *__pyx_t_5 = NULL;
3665 int __pyx_lineno = 0;
3666 const char *__pyx_filename = NULL;
3667 int __pyx_clineno = 0;
3668 __Pyx_RefNannySetupContext("uint256_to_quads", 0);
3669
3670 /* "clickhouse_driver/columns/largeint.pyx":217
3671 *
3672 * def uint256_to_quads(items, unsigned long long n_items):
3673 * cdef unsigned int factor = 4 # <<<<<<<<<<<<<<
3674 * quad_items = PyTuple_New(n_items * factor)
3675 *
3676 */
3677 __pyx_v_factor = 4;
3678
3679 /* "clickhouse_driver/columns/largeint.pyx":218
3680 * def uint256_to_quads(items, unsigned long long n_items):
3681 * cdef unsigned int factor = 4
3682 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<<
3683 *
3684 * cdef unsigned long long i, ix
3685 */
3686 __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error)
3687 __Pyx_GOTREF(__pyx_t_1);
3688 __pyx_v_quad_items = ((PyObject*)__pyx_t_1);
3689 __pyx_t_1 = 0;
3690
3691 /* "clickhouse_driver/columns/largeint.pyx":223
3692 * cdef object x, item
3693 *
3694 * for i in range(n_items): # <<<<<<<<<<<<<<
3695 * ix = factor * i
3696 *
3697 */
3698 __pyx_t_2 = __pyx_v_n_items;
3699 __pyx_t_3 = __pyx_t_2;
3700 for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
3701 __pyx_v_i = __pyx_t_4;
3702
3703 /* "clickhouse_driver/columns/largeint.pyx":224
3704 *
3705 * for i in range(n_items):
3706 * ix = factor * i # <<<<<<<<<<<<<<
3707 *
3708 * x = items[i]
3709 */
3710 __pyx_v_ix = (__pyx_v_factor * __pyx_v_i);
3711
3712 /* "clickhouse_driver/columns/largeint.pyx":226
3713 * ix = factor * i
3714 *
3715 * x = items[i] # <<<<<<<<<<<<<<
3716 * item = x & MAX_UINT64
3717 * Py_INCREF(item)
3718 */
3719 __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_items, __pyx_v_i, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error)
3720 __Pyx_GOTREF(__pyx_t_1);
3721 __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
3722 __pyx_t_1 = 0;
3723
3724 /* "clickhouse_driver/columns/largeint.pyx":227
3725 *
3726 * x = items[i]
3727 * item = x & MAX_UINT64 # <<<<<<<<<<<<<<
3728 * Py_INCREF(item)
3729 * PyTuple_SET_ITEM(quad_items, ix, item)
3730 */
3731 __pyx_t_1 = PyNumber_And(__pyx_v_x, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error)
3732 __Pyx_GOTREF(__pyx_t_1);
3733 __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
3734 __pyx_t_1 = 0;
3735
3736 /* "clickhouse_driver/columns/largeint.pyx":228
3737 * x = items[i]
3738 * item = x & MAX_UINT64
3739 * Py_INCREF(item) # <<<<<<<<<<<<<<
3740 * PyTuple_SET_ITEM(quad_items, ix, item)
3741 *
3742 */
3743 Py_INCREF(__pyx_v_item);
3744
3745 /* "clickhouse_driver/columns/largeint.pyx":229
3746 * item = x & MAX_UINT64
3747 * Py_INCREF(item)
3748 * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<<
3749 *
3750 * item = (x >> 64) & MAX_UINT64
3751 */
3752 PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item);
3753
3754 /* "clickhouse_driver/columns/largeint.pyx":231
3755 * PyTuple_SET_ITEM(quad_items, ix, item)
3756 *
3757 * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<<
3758 * Py_INCREF(item)
3759 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3760 */
3761 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error)
3762 __Pyx_GOTREF(__pyx_t_1);
3763 __pyx_t_5 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 231, __pyx_L1_error)
3764 __Pyx_GOTREF(__pyx_t_5);
3765 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3766 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5);
3767 __pyx_t_5 = 0;
3768
3769 /* "clickhouse_driver/columns/largeint.pyx":232
3770 *
3771 * item = (x >> 64) & MAX_UINT64
3772 * Py_INCREF(item) # <<<<<<<<<<<<<<
3773 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3774 *
3775 */
3776 Py_INCREF(__pyx_v_item);
3777
3778 /* "clickhouse_driver/columns/largeint.pyx":233
3779 * item = (x >> 64) & MAX_UINT64
3780 * Py_INCREF(item)
3781 * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<<
3782 *
3783 * item = (x >> 128) & MAX_UINT64
3784 */
3785 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item);
3786
3787 /* "clickhouse_driver/columns/largeint.pyx":235
3788 * PyTuple_SET_ITEM(quad_items, ix + 1, item)
3789 *
3790 * item = (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<<
3791 * Py_INCREF(item)
3792 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3793 */
3794 __pyx_t_5 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 235, __pyx_L1_error)
3795 __Pyx_GOTREF(__pyx_t_5);
3796 __pyx_t_1 = PyNumber_And(__pyx_t_5, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __pyx_L1_error)
3797 __Pyx_GOTREF(__pyx_t_1);
3798 __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3799 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1);
3800 __pyx_t_1 = 0;
3801
3802 /* "clickhouse_driver/columns/largeint.pyx":236
3803 *
3804 * item = (x >> 128) & MAX_UINT64
3805 * Py_INCREF(item) # <<<<<<<<<<<<<<
3806 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3807 *
3808 */
3809 Py_INCREF(__pyx_v_item);
3810
3811 /* "clickhouse_driver/columns/largeint.pyx":237
3812 * item = (x >> 128) & MAX_UINT64
3813 * Py_INCREF(item)
3814 * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<<
3815 *
3816 * item = (x >> 192) & MAX_UINT64
3817 */
3818 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item);
3819
3820 /* "clickhouse_driver/columns/largeint.pyx":239
3821 * PyTuple_SET_ITEM(quad_items, ix + 2, item)
3822 *
3823 * item = (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<<
3824 * Py_INCREF(item)
3825 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3826 */
3827 __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error)
3828 __Pyx_GOTREF(__pyx_t_1);
3829 __pyx_t_5 = PyNumber_And(__pyx_t_1, __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 239, __pyx_L1_error)
3830 __Pyx_GOTREF(__pyx_t_5);
3831 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3832 __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5);
3833 __pyx_t_5 = 0;
3834
3835 /* "clickhouse_driver/columns/largeint.pyx":240
3836 *
3837 * item = (x >> 192) & MAX_UINT64
3838 * Py_INCREF(item) # <<<<<<<<<<<<<<
3839 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3840 *
3841 */
3842 Py_INCREF(__pyx_v_item);
3843
3844 /* "clickhouse_driver/columns/largeint.pyx":241
3845 * item = (x >> 192) & MAX_UINT64
3846 * Py_INCREF(item)
3847 * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<<
3848 *
3849 * return quad_items
3850 */
3851 PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item);
3852 }
3853
3854 /* "clickhouse_driver/columns/largeint.pyx":243
3855 * PyTuple_SET_ITEM(quad_items, ix + 3, item)
3856 *
3857 * return quad_items # <<<<<<<<<<<<<<
3858 */
3859 __Pyx_XDECREF(__pyx_r);
3860 __Pyx_INCREF(__pyx_v_quad_items);
3861 __pyx_r = __pyx_v_quad_items;
3862 goto __pyx_L0;
3863
3864 /* "clickhouse_driver/columns/largeint.pyx":216
3865 *
3866 *
3867 * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
3868 * cdef unsigned int factor = 4
3869 * quad_items = PyTuple_New(n_items * factor)
3870 */
3871
3872 /* function exit code */
3873 __pyx_L1_error:;
3874 __Pyx_XDECREF(__pyx_t_1);
3875 __Pyx_XDECREF(__pyx_t_5);
3876 __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename);
3877 __pyx_r = NULL;
3878 __pyx_L0:;
3879 __Pyx_XDECREF(__pyx_v_quad_items);
3880 __Pyx_XDECREF(__pyx_v_x);
3881 __Pyx_XDECREF(__pyx_v_item);
3882 __Pyx_XGIVEREF(__pyx_r);
3883 __Pyx_RefNannyFinishContext();
3884 return __pyx_r;
3885 }
3886
3887 static PyMethodDef __pyx_methods[] = {
3888 {0, 0, 0, 0}
3889 };
3890
3891 #if PY_MAJOR_VERSION >= 3
3892 #if CYTHON_PEP489_MULTI_PHASE_INIT
3893 static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
3894 static int __pyx_pymod_exec_largeint(PyObject* module); /*proto*/
3895 static PyModuleDef_Slot __pyx_moduledef_slots[] = {
3896 {Py_mod_create, (void*)__pyx_pymod_create},
3897 {Py_mod_exec, (void*)__pyx_pymod_exec_largeint},
3898 {0, NULL}
3899 };
3900 #endif
3901
3902 static struct PyModuleDef __pyx_moduledef = {
3903 PyModuleDef_HEAD_INIT,
3904 "largeint",
3905 0, /* m_doc */
3906 #if CYTHON_PEP489_MULTI_PHASE_INIT
3907 0, /* m_size */
3908 #else
3909 -1, /* m_size */
3910 #endif
3911 __pyx_methods /* m_methods */,
3912 #if CYTHON_PEP489_MULTI_PHASE_INIT
3913 __pyx_moduledef_slots, /* m_slots */
3914 #else
3915 NULL, /* m_reload */
3916 #endif
3917 NULL, /* m_traverse */
3918 NULL, /* m_clear */
3919 NULL /* m_free */
3920 };
3921 #endif
3922 #ifndef CYTHON_SMALL_CODE
3923 #if defined(__clang__)
3924 #define CYTHON_SMALL_CODE
3925 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
3926 #define CYTHON_SMALL_CODE __attribute__((cold))
3927 #else
3928 #define CYTHON_SMALL_CODE
3929 #endif
3930 #endif
3931
3932 static __Pyx_StringTabEntry __pyx_string_tab[] = {
3933 {&__pyx_n_s_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 1, 1},
3934 {&__pyx_n_s_MAX_INT64, __pyx_k_MAX_INT64, sizeof(__pyx_k_MAX_INT64), 0, 0, 1, 1},
3935 {&__pyx_n_s_MAX_UINT64, __pyx_k_MAX_UINT64, sizeof(__pyx_k_MAX_UINT64), 0, 0, 1, 1},
3936 {&__pyx_kp_s_clickhouse_driver_columns_largei, __pyx_k_clickhouse_driver_columns_largei, sizeof(__pyx_k_clickhouse_driver_columns_largei), 0, 0, 1, 0},
3937 {&__pyx_n_s_clickhouse_driver_columns_largei_2, __pyx_k_clickhouse_driver_columns_largei_2, sizeof(__pyx_k_clickhouse_driver_columns_largei_2), 0, 0, 1, 1},
3938 {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
3939 {&__pyx_n_s_factor, __pyx_k_factor, sizeof(__pyx_k_factor), 0, 0, 1, 1},
3940 {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
3941 {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
3942 {&__pyx_n_s_int128_from_quads, __pyx_k_int128_from_quads, sizeof(__pyx_k_int128_from_quads), 0, 0, 1, 1},
3943 {&__pyx_n_s_int128_to_quads, __pyx_k_int128_to_quads, sizeof(__pyx_k_int128_to_quads), 0, 0, 1, 1},
3944 {&__pyx_n_s_int256_from_quads, __pyx_k_int256_from_quads, sizeof(__pyx_k_int256_from_quads), 0, 0, 1, 1},
3945 {&__pyx_n_s_int256_to_quads, __pyx_k_int256_to_quads, sizeof(__pyx_k_int256_to_quads), 0, 0, 1, 1},
3946 {&__pyx_n_s_item, __pyx_k_item, sizeof(__pyx_k_item), 0, 0, 1, 1},
3947 {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
3948 {&__pyx_n_s_ix, __pyx_k_ix, sizeof(__pyx_k_ix), 0, 0, 1, 1},
3949 {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
3950 {&__pyx_n_s_n_items, __pyx_k_n_items, sizeof(__pyx_k_n_items), 0, 0, 1, 1},
3951 {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
3952 {&__pyx_n_s_quad_items, __pyx_k_quad_items, sizeof(__pyx_k_quad_items), 0, 0, 1, 1},
3953 {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
3954 {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
3955 {&__pyx_n_s_uint128_from_quads, __pyx_k_uint128_from_quads, sizeof(__pyx_k_uint128_from_quads), 0, 0, 1, 1},
3956 {&__pyx_n_s_uint128_to_quads, __pyx_k_uint128_to_quads, sizeof(__pyx_k_uint128_to_quads), 0, 0, 1, 1},
3957 {&__pyx_n_s_uint256_from_quads, __pyx_k_uint256_from_quads, sizeof(__pyx_k_uint256_from_quads), 0, 0, 1, 1},
3958 {&__pyx_n_s_uint256_to_quads, __pyx_k_uint256_to_quads, sizeof(__pyx_k_uint256_to_quads), 0, 0, 1, 1},
3959 {&__pyx_n_s_writer, __pyx_k_writer, sizeof(__pyx_k_writer), 0, 0, 1, 1},
3960 {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
3961 {0, 0, 0, 0, 0, 0, 0}
3962 };
3963 static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
3964 __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 17, __pyx_L1_error)
3965 return 0;
3966 __pyx_L1_error:;
3967 return -1;
3968 }
3969
3970 static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
3971 __Pyx_RefNannyDeclarations
3972 __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
3973
3974 /* "clickhouse_driver/columns/largeint.pyx":10
3975 *
3976 *
3977 * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
3978 * cdef unsigned int factor = 2
3979 * items = PyTuple_New(n_items)
3980 */
3981 __pyx_tuple__2 = PyTuple_Pack(7, __pyx_n_s_quad_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_item); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 10, __pyx_L1_error)
3982 __Pyx_GOTREF(__pyx_tuple__2);
3983 __Pyx_GIVEREF(__pyx_tuple__2);
3984 __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__2, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_int128_from_quads, 10, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) __PYX_ERR(0, 10, __pyx_L1_error)
3985
3986 /* "clickhouse_driver/columns/largeint.pyx":36
3987 *
3988 *
3989 * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
3990 * cdef unsigned int factor = 2
3991 * quad_items = PyTuple_New(n_items * factor)
3992 */
3993 __pyx_tuple__4 = PyTuple_Pack(8, __pyx_n_s_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_quad_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_x, __pyx_n_s_item); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 36, __pyx_L1_error)
3994 __Pyx_GOTREF(__pyx_tuple__4);
3995 __Pyx_GIVEREF(__pyx_tuple__4);
3996 __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_int128_to_quads, 36, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 36, __pyx_L1_error)
3997
3998 /* "clickhouse_driver/columns/largeint.pyx":70
3999 *
4000 *
4001 * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4002 * cdef unsigned int factor = 2
4003 * items = PyTuple_New(n_items)
4004 */
4005 __pyx_tuple__6 = PyTuple_Pack(7, __pyx_n_s_quad_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_item); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 70, __pyx_L1_error)
4006 __Pyx_GOTREF(__pyx_tuple__6);
4007 __Pyx_GIVEREF(__pyx_tuple__6);
4008 __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_uint128_from_quads, 70, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 70, __pyx_L1_error)
4009
4010 /* "clickhouse_driver/columns/largeint.pyx":87
4011 *
4012 *
4013 * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4014 * cdef unsigned int factor = 2
4015 * quad_items = PyTuple_New(n_items * factor)
4016 */
4017 __pyx_tuple__8 = PyTuple_Pack(8, __pyx_n_s_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_quad_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_x, __pyx_n_s_item); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 87, __pyx_L1_error)
4018 __Pyx_GOTREF(__pyx_tuple__8);
4019 __Pyx_GIVEREF(__pyx_tuple__8);
4020 __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_uint128_to_quads, 87, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 87, __pyx_L1_error)
4021
4022 /* "clickhouse_driver/columns/largeint.pyx":111
4023 *
4024 *
4025 * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4026 * cdef unsigned int factor = 4
4027 * items = PyTuple_New(n_items)
4028 */
4029 __pyx_tuple__10 = PyTuple_Pack(7, __pyx_n_s_quad_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_item); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 111, __pyx_L1_error)
4030 __Pyx_GOTREF(__pyx_tuple__10);
4031 __Pyx_GIVEREF(__pyx_tuple__10);
4032 __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_int256_from_quads, 111, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 111, __pyx_L1_error)
4033
4034 /* "clickhouse_driver/columns/largeint.pyx":144
4035 *
4036 *
4037 * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4038 * cdef unsigned int factor = 4
4039 * quad_items = PyTuple_New(n_items * factor)
4040 */
4041 __pyx_tuple__12 = PyTuple_Pack(8, __pyx_n_s_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_quad_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_x, __pyx_n_s_item); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 144, __pyx_L1_error)
4042 __Pyx_GOTREF(__pyx_tuple__12);
4043 __Pyx_GIVEREF(__pyx_tuple__12);
4044 __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_int256_to_quads, 144, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 144, __pyx_L1_error)
4045
4046 /* "clickhouse_driver/columns/largeint.pyx":194
4047 *
4048 *
4049 * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4050 * cdef unsigned int factor = 4
4051 * items = PyTuple_New(n_items)
4052 */
4053 __pyx_tuple__14 = PyTuple_Pack(7, __pyx_n_s_quad_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_item); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 194, __pyx_L1_error)
4054 __Pyx_GOTREF(__pyx_tuple__14);
4055 __Pyx_GIVEREF(__pyx_tuple__14);
4056 __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_uint256_from_quads, 194, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 194, __pyx_L1_error)
4057
4058 /* "clickhouse_driver/columns/largeint.pyx":216
4059 *
4060 *
4061 * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4062 * cdef unsigned int factor = 4
4063 * quad_items = PyTuple_New(n_items * factor)
4064 */
4065 __pyx_tuple__16 = PyTuple_Pack(8, __pyx_n_s_items, __pyx_n_s_n_items, __pyx_n_s_factor, __pyx_n_s_quad_items, __pyx_n_s_i, __pyx_n_s_ix, __pyx_n_s_x, __pyx_n_s_item); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 216, __pyx_L1_error)
4066 __Pyx_GOTREF(__pyx_tuple__16);
4067 __Pyx_GIVEREF(__pyx_tuple__16);
4068 __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_columns_largei, __pyx_n_s_uint256_to_quads, 216, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 216, __pyx_L1_error)
4069 __Pyx_RefNannyFinishContext();
4070 return 0;
4071 __pyx_L1_error:;
4072 __Pyx_RefNannyFinishContext();
4073 return -1;
4074 }
4075
4076 static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
4077 if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
4078 __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
4079 __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
4080 __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) __PYX_ERR(0, 1, __pyx_L1_error)
4081 __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) __PYX_ERR(0, 1, __pyx_L1_error)
4082 __pyx_int_192 = PyInt_FromLong(192); if (unlikely(!__pyx_int_192)) __PYX_ERR(0, 1, __pyx_L1_error)
4083 return 0;
4084 __pyx_L1_error:;
4085 return -1;
4086 }
4087
4088 static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
4089 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
4090 static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
4091 static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
4092 static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
4093 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
4094 static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
4095
4096 static int __Pyx_modinit_global_init_code(void) {
4097 __Pyx_RefNannyDeclarations
4098 __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
4099 /*--- Global init code ---*/
4100 __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64 = Py_None; Py_INCREF(Py_None);
4101 __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64 = Py_None; Py_INCREF(Py_None);
4102 __Pyx_RefNannyFinishContext();
4103 return 0;
4104 }
4105
4106 static int __Pyx_modinit_variable_export_code(void) {
4107 __Pyx_RefNannyDeclarations
4108 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
4109 /*--- Variable export code ---*/
4110 __Pyx_RefNannyFinishContext();
4111 return 0;
4112 }
4113
4114 static int __Pyx_modinit_function_export_code(void) {
4115 __Pyx_RefNannyDeclarations
4116 __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
4117 /*--- Function export code ---*/
4118 __Pyx_RefNannyFinishContext();
4119 return 0;
4120 }
4121
4122 static int __Pyx_modinit_type_init_code(void) {
4123 __Pyx_RefNannyDeclarations
4124 __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
4125 /*--- Type init code ---*/
4126 __Pyx_RefNannyFinishContext();
4127 return 0;
4128 }
4129
4130 static int __Pyx_modinit_type_import_code(void) {
4131 __Pyx_RefNannyDeclarations
4132 PyObject *__pyx_t_1 = NULL;
4133 int __pyx_lineno = 0;
4134 const char *__pyx_filename = NULL;
4135 int __pyx_clineno = 0;
4136 __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
4137 /*--- Type import code ---*/
4138 __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error)
4139 __Pyx_GOTREF(__pyx_t_1);
4140 __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type",
4141 #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
4142 sizeof(PyTypeObject),
4143 #else
4144 sizeof(PyHeapTypeObject),
4145 #endif
4146 __Pyx_ImportType_CheckSize_Warn);
4147 if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(1, 9, __pyx_L1_error)
4148 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4149 __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error)
4150 __Pyx_GOTREF(__pyx_t_1);
4151 __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn);
4152 if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(2, 8, __pyx_L1_error)
4153 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4154 __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 15, __pyx_L1_error)
4155 __Pyx_GOTREF(__pyx_t_1);
4156 __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn);
4157 if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(3, 15, __pyx_L1_error)
4158 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4159 __Pyx_RefNannyFinishContext();
4160 return 0;
4161 __pyx_L1_error:;
4162 __Pyx_XDECREF(__pyx_t_1);
4163 __Pyx_RefNannyFinishContext();
4164 return -1;
4165 }
4166
4167 static int __Pyx_modinit_variable_import_code(void) {
4168 __Pyx_RefNannyDeclarations
4169 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
4170 /*--- Variable import code ---*/
4171 __Pyx_RefNannyFinishContext();
4172 return 0;
4173 }
4174
4175 static int __Pyx_modinit_function_import_code(void) {
4176 __Pyx_RefNannyDeclarations
4177 __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
4178 /*--- Function import code ---*/
4179 __Pyx_RefNannyFinishContext();
4180 return 0;
4181 }
4182
4183
4184 #ifndef CYTHON_NO_PYINIT_EXPORT
4185 #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
4186 #elif PY_MAJOR_VERSION < 3
4187 #ifdef __cplusplus
4188 #define __Pyx_PyMODINIT_FUNC extern "C" void
4189 #else
4190 #define __Pyx_PyMODINIT_FUNC void
4191 #endif
4192 #else
4193 #ifdef __cplusplus
4194 #define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
4195 #else
4196 #define __Pyx_PyMODINIT_FUNC PyObject *
4197 #endif
4198 #endif
4199
4200
4201 #if PY_MAJOR_VERSION < 3
4202 __Pyx_PyMODINIT_FUNC initlargeint(void) CYTHON_SMALL_CODE; /*proto*/
4203 __Pyx_PyMODINIT_FUNC initlargeint(void)
4204 #else
4205 __Pyx_PyMODINIT_FUNC PyInit_largeint(void) CYTHON_SMALL_CODE; /*proto*/
4206 __Pyx_PyMODINIT_FUNC PyInit_largeint(void)
4207 #if CYTHON_PEP489_MULTI_PHASE_INIT
4208 {
4209 return PyModuleDef_Init(&__pyx_moduledef);
4210 }
4211 static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
4212 #if PY_VERSION_HEX >= 0x030700A1
4213 static PY_INT64_T main_interpreter_id = -1;
4214 PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
4215 if (main_interpreter_id == -1) {
4216 main_interpreter_id = current_id;
4217 return (unlikely(current_id == -1)) ? -1 : 0;
4218 } else if (unlikely(main_interpreter_id != current_id))
4219 #else
4220 static PyInterpreterState *main_interpreter = NULL;
4221 PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
4222 if (!main_interpreter) {
4223 main_interpreter = current_interpreter;
4224 } else if (unlikely(main_interpreter != current_interpreter))
4225 #endif
4226 {
4227 PyErr_SetString(
4228 PyExc_ImportError,
4229 "Interpreter change detected - this module can only be loaded into one interpreter per process.");
4230 return -1;
4231 }
4232 return 0;
4233 }
4234 static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
4235 PyObject *value = PyObject_GetAttrString(spec, from_name);
4236 int result = 0;
4237 if (likely(value)) {
4238 if (allow_none || value != Py_None) {
4239 result = PyDict_SetItemString(moddict, to_name, value);
4240 }
4241 Py_DECREF(value);
4242 } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
4243 PyErr_Clear();
4244 } else {
4245 result = -1;
4246 }
4247 return result;
4248 }
4249 static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
4250 PyObject *module = NULL, *moddict, *modname;
4251 if (__Pyx_check_single_interpreter())
4252 return NULL;
4253 if (__pyx_m)
4254 return __Pyx_NewRef(__pyx_m);
4255 modname = PyObject_GetAttrString(spec, "name");
4256 if (unlikely(!modname)) goto bad;
4257 module = PyModule_NewObject(modname);
4258 Py_DECREF(modname);
4259 if (unlikely(!module)) goto bad;
4260 moddict = PyModule_GetDict(module);
4261 if (unlikely(!moddict)) goto bad;
4262 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
4263 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
4264 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
4265 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
4266 return module;
4267 bad:
4268 Py_XDECREF(module);
4269 return NULL;
4270 }
4271
4272
4273 static CYTHON_SMALL_CODE int __pyx_pymod_exec_largeint(PyObject *__pyx_pyinit_module)
4274 #endif
4275 #endif
4276 {
4277 PyObject *__pyx_t_1 = NULL;
4278 PyObject *__pyx_t_2 = NULL;
4279 int __pyx_lineno = 0;
4280 const char *__pyx_filename = NULL;
4281 int __pyx_clineno = 0;
4282 __Pyx_RefNannyDeclarations
4283 #if CYTHON_PEP489_MULTI_PHASE_INIT
4284 if (__pyx_m) {
4285 if (__pyx_m == __pyx_pyinit_module) return 0;
4286 PyErr_SetString(PyExc_RuntimeError, "Module 'largeint' has already been imported. Re-initialisation is not supported.");
4287 return -1;
4288 }
4289 #elif PY_MAJOR_VERSION >= 3
4290 if (__pyx_m) return __Pyx_NewRef(__pyx_m);
4291 #endif
4292 #if CYTHON_REFNANNY
4293 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
4294 if (!__Pyx_RefNanny) {
4295 PyErr_Clear();
4296 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
4297 if (!__Pyx_RefNanny)
4298 Py_FatalError("failed to import 'refnanny' module");
4299 }
4300 #endif
4301 __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_largeint(void)", 0);
4302 if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4303 #ifdef __Pxy_PyFrame_Initialize_Offsets
4304 __Pxy_PyFrame_Initialize_Offsets();
4305 #endif
4306 __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
4307 __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
4308 __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
4309 #ifdef __Pyx_CyFunction_USED
4310 if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4311 #endif
4312 #ifdef __Pyx_FusedFunction_USED
4313 if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4314 #endif
4315 #ifdef __Pyx_Coroutine_USED
4316 if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4317 #endif
4318 #ifdef __Pyx_Generator_USED
4319 if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4320 #endif
4321 #ifdef __Pyx_AsyncGen_USED
4322 if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4323 #endif
4324 #ifdef __Pyx_StopAsyncIteration_USED
4325 if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4326 #endif
4327 /*--- Library function declarations ---*/
4328 /*--- Threads initialization code ---*/
4329 #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
4330 #ifdef WITH_THREAD /* Python build with threading support? */
4331 PyEval_InitThreads();
4332 #endif
4333 #endif
4334 /*--- Module creation code ---*/
4335 #if CYTHON_PEP489_MULTI_PHASE_INIT
4336 __pyx_m = __pyx_pyinit_module;
4337 Py_INCREF(__pyx_m);
4338 #else
4339 #if PY_MAJOR_VERSION < 3
4340 __pyx_m = Py_InitModule4("largeint", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
4341 #else
4342 __pyx_m = PyModule_Create(&__pyx_moduledef);
4343 #endif
4344 if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
4345 #endif
4346 __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
4347 Py_INCREF(__pyx_d);
4348 __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
4349 Py_INCREF(__pyx_b);
4350 __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
4351 Py_INCREF(__pyx_cython_runtime);
4352 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
4353 /*--- Initialize various global constants etc. ---*/
4354 if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4355 #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
4356 if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4357 #endif
4358 if (__pyx_module_is_main_clickhouse_driver__columns__largeint) {
4359 if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4360 }
4361 #if PY_MAJOR_VERSION >= 3
4362 {
4363 PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
4364 if (!PyDict_GetItemString(modules, "clickhouse_driver.columns.largeint")) {
4365 if (unlikely(PyDict_SetItemString(modules, "clickhouse_driver.columns.largeint", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
4366 }
4367 }
4368 #endif
4369 /*--- Builtin init code ---*/
4370 if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4371 /*--- Constants init code ---*/
4372 if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4373 /*--- Global type/function init code ---*/
4374 (void)__Pyx_modinit_global_init_code();
4375 (void)__Pyx_modinit_variable_export_code();
4376 (void)__Pyx_modinit_function_export_code();
4377 (void)__Pyx_modinit_type_init_code();
4378 if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
4379 (void)__Pyx_modinit_variable_import_code();
4380 (void)__Pyx_modinit_function_import_code();
4381 /*--- Execution code ---*/
4382 #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
4383 if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4384 #endif
4385
4386 /* "clickhouse_driver/columns/largeint.pyx":4
4387 * from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
4388 *
4389 * from .. import writer # <<<<<<<<<<<<<<
4390 *
4391 * cpdef object MAX_UINT64 = writer.MAX_UINT64
4392 */
4393 __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error)
4394 __Pyx_GOTREF(__pyx_t_1);
4395 __Pyx_INCREF(__pyx_n_s_writer);
4396 __Pyx_GIVEREF(__pyx_n_s_writer);
4397 PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_writer);
4398 __pyx_t_2 = __Pyx_Import(__pyx_n_s_, __pyx_t_1, 2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error)
4399 __Pyx_GOTREF(__pyx_t_2);
4400 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4401 __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_writer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error)
4402 __Pyx_GOTREF(__pyx_t_1);
4403 if (PyDict_SetItem(__pyx_d, __pyx_n_s_writer, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
4404 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4405 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4406
4407 /* "clickhouse_driver/columns/largeint.pyx":6
4408 * from .. import writer
4409 *
4410 * cpdef object MAX_UINT64 = writer.MAX_UINT64 # <<<<<<<<<<<<<<
4411 * cpdef object MAX_INT64 = writer.MAX_INT64
4412 *
4413 */
4414 __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_writer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error)
4415 __Pyx_GOTREF(__pyx_t_2);
4416 __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_MAX_UINT64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
4417 __Pyx_GOTREF(__pyx_t_1);
4418 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4419 __Pyx_XGOTREF(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64);
4420 __Pyx_DECREF_SET(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1);
4421 __Pyx_GIVEREF(__pyx_t_1);
4422 __pyx_t_1 = 0;
4423
4424 /* "clickhouse_driver/columns/largeint.pyx":7
4425 *
4426 * cpdef object MAX_UINT64 = writer.MAX_UINT64
4427 * cpdef object MAX_INT64 = writer.MAX_INT64 # <<<<<<<<<<<<<<
4428 *
4429 *
4430 */
4431 __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_writer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
4432 __Pyx_GOTREF(__pyx_t_1);
4433 __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_MAX_INT64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
4434 __Pyx_GOTREF(__pyx_t_2);
4435 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4436 __Pyx_XGOTREF(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64);
4437 __Pyx_DECREF_SET(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64, __pyx_t_2);
4438 __Pyx_GIVEREF(__pyx_t_2);
4439 __pyx_t_2 = 0;
4440
4441 /* "clickhouse_driver/columns/largeint.pyx":10
4442 *
4443 *
4444 * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4445 * cdef unsigned int factor = 2
4446 * items = PyTuple_New(n_items)
4447 */
4448 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_1int128_from_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error)
4449 __Pyx_GOTREF(__pyx_t_2);
4450 if (PyDict_SetItem(__pyx_d, __pyx_n_s_int128_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
4451 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4452
4453 /* "clickhouse_driver/columns/largeint.pyx":36
4454 *
4455 *
4456 * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4457 * cdef unsigned int factor = 2
4458 * quad_items = PyTuple_New(n_items * factor)
4459 */
4460 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_3int128_to_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
4461 __Pyx_GOTREF(__pyx_t_2);
4462 if (PyDict_SetItem(__pyx_d, __pyx_n_s_int128_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
4463 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4464
4465 /* "clickhouse_driver/columns/largeint.pyx":70
4466 *
4467 *
4468 * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4469 * cdef unsigned int factor = 2
4470 * items = PyTuple_New(n_items)
4471 */
4472 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_5uint128_from_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error)
4473 __Pyx_GOTREF(__pyx_t_2);
4474 if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint128_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 70, __pyx_L1_error)
4475 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4476
4477 /* "clickhouse_driver/columns/largeint.pyx":87
4478 *
4479 *
4480 * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4481 * cdef unsigned int factor = 2
4482 * quad_items = PyTuple_New(n_items * factor)
4483 */
4484 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_7uint128_to_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
4485 __Pyx_GOTREF(__pyx_t_2);
4486 if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint128_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 87, __pyx_L1_error)
4487 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4488
4489 /* "clickhouse_driver/columns/largeint.pyx":111
4490 *
4491 *
4492 * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4493 * cdef unsigned int factor = 4
4494 * items = PyTuple_New(n_items)
4495 */
4496 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_9int256_from_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error)
4497 __Pyx_GOTREF(__pyx_t_2);
4498 if (PyDict_SetItem(__pyx_d, __pyx_n_s_int256_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 111, __pyx_L1_error)
4499 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4500
4501 /* "clickhouse_driver/columns/largeint.pyx":144
4502 *
4503 *
4504 * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4505 * cdef unsigned int factor = 4
4506 * quad_items = PyTuple_New(n_items * factor)
4507 */
4508 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_11int256_to_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error)
4509 __Pyx_GOTREF(__pyx_t_2);
4510 if (PyDict_SetItem(__pyx_d, __pyx_n_s_int256_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 144, __pyx_L1_error)
4511 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4512
4513 /* "clickhouse_driver/columns/largeint.pyx":194
4514 *
4515 *
4516 * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<<
4517 * cdef unsigned int factor = 4
4518 * items = PyTuple_New(n_items)
4519 */
4520 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_13uint256_from_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error)
4521 __Pyx_GOTREF(__pyx_t_2);
4522 if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint256_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 194, __pyx_L1_error)
4523 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4524
4525 /* "clickhouse_driver/columns/largeint.pyx":216
4526 *
4527 *
4528 * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<<
4529 * cdef unsigned int factor = 4
4530 * quad_items = PyTuple_New(n_items * factor)
4531 */
4532 __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_7columns_8largeint_15uint256_to_quads, NULL, __pyx_n_s_clickhouse_driver_columns_largei_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 216, __pyx_L1_error)
4533 __Pyx_GOTREF(__pyx_t_2);
4534 if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint256_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 216, __pyx_L1_error)
4535 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4536
4537 /* "clickhouse_driver/columns/largeint.pyx":1
4538 * from cpython cimport Py_INCREF # <<<<<<<<<<<<<<
4539 * from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
4540 *
4541 */
4542 __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
4543 __Pyx_GOTREF(__pyx_t_2);
4544 if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4545 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4546
4547 /*--- Wrapped vars code ---*/
4548
4549 goto __pyx_L0;
4550 __pyx_L1_error:;
4551 __Pyx_XDECREF(__pyx_t_1);
4552 __Pyx_XDECREF(__pyx_t_2);
4553 if (__pyx_m) {
4554 if (__pyx_d) {
4555 __Pyx_AddTraceback("init clickhouse_driver.columns.largeint", __pyx_clineno, __pyx_lineno, __pyx_filename);
4556 }
4557 Py_CLEAR(__pyx_m);
4558 } else if (!PyErr_Occurred()) {
4559 PyErr_SetString(PyExc_ImportError, "init clickhouse_driver.columns.largeint");
4560 }
4561 __pyx_L0:;
4562 __Pyx_RefNannyFinishContext();
4563 #if CYTHON_PEP489_MULTI_PHASE_INIT
4564 return (__pyx_m != NULL) ? 0 : -1;
4565 #elif PY_MAJOR_VERSION >= 3
4566 return __pyx_m;
4567 #else
4568 return;
4569 #endif
4570 }
4571
4572 /* --- Runtime support code --- */
4573 /* Refnanny */
4574 #if CYTHON_REFNANNY
4575 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
4576 PyObject *m = NULL, *p = NULL;
4577 void *r = NULL;
4578 m = PyImport_ImportModule(modname);
4579 if (!m) goto end;
4580 p = PyObject_GetAttrString(m, "RefNannyAPI");
4581 if (!p) goto end;
4582 r = PyLong_AsVoidPtr(p);
4583 end:
4584 Py_XDECREF(p);
4585 Py_XDECREF(m);
4586 return (__Pyx_RefNannyAPIStruct *)r;
4587 }
4588 #endif
4589
4590 /* PyObjectGetAttrStr */
4591 #if CYTHON_USE_TYPE_SLOTS
4592 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
4593 PyTypeObject* tp = Py_TYPE(obj);
4594 if (likely(tp->tp_getattro))
4595 return tp->tp_getattro(obj, attr_name);
4596 #if PY_MAJOR_VERSION < 3
4597 if (likely(tp->tp_getattr))
4598 return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
4599 #endif
4600 return PyObject_GetAttr(obj, attr_name);
4601 }
4602 #endif
4603
4604 /* GetBuiltinName */
4605 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
4606 PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
4607 if (unlikely(!result)) {
4608 PyErr_Format(PyExc_NameError,
4609 #if PY_MAJOR_VERSION >= 3
4610 "name '%U' is not defined", name);
4611 #else
4612 "name '%.200s' is not defined", PyString_AS_STRING(name));
4613 #endif
4614 }
4615 return result;
4616 }
4617
4618 /* RaiseArgTupleInvalid */
4619 static void __Pyx_RaiseArgtupleInvalid(
4620 const char* func_name,
4621 int exact,
4622 Py_ssize_t num_min,
4623 Py_ssize_t num_max,
4624 Py_ssize_t num_found)
4625 {
4626 Py_ssize_t num_expected;
4627 const char *more_or_less;
4628 if (num_found < num_min) {
4629 num_expected = num_min;
4630 more_or_less = "at least";
4631 } else {
4632 num_expected = num_max;
4633 more_or_less = "at most";
4634 }
4635 if (exact) {
4636 more_or_less = "exactly";
4637 }
4638 PyErr_Format(PyExc_TypeError,
4639 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
4640 func_name, more_or_less, num_expected,
4641 (num_expected == 1) ? "" : "s", num_found);
4642 }
4643
4644 /* RaiseDoubleKeywords */
4645 static void __Pyx_RaiseDoubleKeywordsError(
4646 const char* func_name,
4647 PyObject* kw_name)
4648 {
4649 PyErr_Format(PyExc_TypeError,
4650 #if PY_MAJOR_VERSION >= 3
4651 "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
4652 #else
4653 "%s() got multiple values for keyword argument '%s'", func_name,
4654 PyString_AsString(kw_name));
4655 #endif
4656 }
4657
4658 /* ParseKeywords */
4659 static int __Pyx_ParseOptionalKeywords(
4660 PyObject *kwds,
4661 PyObject **argnames[],
4662 PyObject *kwds2,
4663 PyObject *values[],
4664 Py_ssize_t num_pos_args,
4665 const char* function_name)
4666 {
4667 PyObject *key = 0, *value = 0;
4668 Py_ssize_t pos = 0;
4669 PyObject*** name;
4670 PyObject*** first_kw_arg = argnames + num_pos_args;
4671 while (PyDict_Next(kwds, &pos, &key, &value)) {
4672 name = first_kw_arg;
4673 while (*name && (**name != key)) name++;
4674 if (*name) {
4675 values[name-argnames] = value;
4676 continue;
4677 }
4678 name = first_kw_arg;
4679 #if PY_MAJOR_VERSION < 3
4680 if (likely(PyString_Check(key))) {
4681 while (*name) {
4682 if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
4683 && _PyString_Eq(**name, key)) {
4684 values[name-argnames] = value;
4685 break;
4686 }
4687 name++;
4688 }
4689 if (*name) continue;
4690 else {
4691 PyObject*** argname = argnames;
4692 while (argname != first_kw_arg) {
4693 if ((**argname == key) || (
4694 (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
4695 && _PyString_Eq(**argname, key))) {
4696 goto arg_passed_twice;
4697 }
4698 argname++;
4699 }
4700 }
4701 } else
4702 #endif
4703 if (likely(PyUnicode_Check(key))) {
4704 while (*name) {
4705 int cmp = (**name == key) ? 0 :
4706 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4707 (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
4708 #endif
4709 PyUnicode_Compare(**name, key);
4710 if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4711 if (cmp == 0) {
4712 values[name-argnames] = value;
4713 break;
4714 }
4715 name++;
4716 }
4717 if (*name) continue;
4718 else {
4719 PyObject*** argname = argnames;
4720 while (argname != first_kw_arg) {
4721 int cmp = (**argname == key) ? 0 :
4722 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4723 (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
4724 #endif
4725 PyUnicode_Compare(**argname, key);
4726 if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4727 if (cmp == 0) goto arg_passed_twice;
4728 argname++;
4729 }
4730 }
4731 } else
4732 goto invalid_keyword_type;
4733 if (kwds2) {
4734 if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
4735 } else {
4736 goto invalid_keyword;
4737 }
4738 }
4739 return 0;
4740 arg_passed_twice:
4741 __Pyx_RaiseDoubleKeywordsError(function_name, key);
4742 goto bad;
4743 invalid_keyword_type:
4744 PyErr_Format(PyExc_TypeError,
4745 "%.200s() keywords must be strings", function_name);
4746 goto bad;
4747 invalid_keyword:
4748 PyErr_Format(PyExc_TypeError,
4749 #if PY_MAJOR_VERSION < 3
4750 "%.200s() got an unexpected keyword argument '%.200s'",
4751 function_name, PyString_AsString(key));
4752 #else
4753 "%s() got an unexpected keyword argument '%U'",
4754 function_name, key);
4755 #endif
4756 bad:
4757 return -1;
4758 }
4759
4760 /* GetItemInt */
4761 static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
4762 PyObject *r;
4763 if (!j) return NULL;
4764 r = PyObject_GetItem(o, j);
4765 Py_DECREF(j);
4766 return r;
4767 }
4768 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
4769 CYTHON_NCP_UNUSED int wraparound,
4770 CYTHON_NCP_UNUSED int boundscheck) {
4771 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
4772 Py_ssize_t wrapped_i = i;
4773 if (wraparound & unlikely(i < 0)) {
4774 wrapped_i += PyList_GET_SIZE(o);
4775 }
4776 if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
4777 PyObject *r = PyList_GET_ITEM(o, wrapped_i);
4778 Py_INCREF(r);
4779 return r;
4780 }
4781 return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
4782 #else
4783 return PySequence_GetItem(o, i);
4784 #endif
4785 }
4786 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
4787 CYTHON_NCP_UNUSED int wraparound,
4788 CYTHON_NCP_UNUSED int boundscheck) {
4789 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
4790 Py_ssize_t wrapped_i = i;
4791 if (wraparound & unlikely(i < 0)) {
4792 wrapped_i += PyTuple_GET_SIZE(o);
4793 }
4794 if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
4795 PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
4796 Py_INCREF(r);
4797 return r;
4798 }
4799 return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
4800 #else
4801 return PySequence_GetItem(o, i);
4802 #endif
4803 }
4804 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
4805 CYTHON_NCP_UNUSED int wraparound,
4806 CYTHON_NCP_UNUSED int boundscheck) {
4807 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
4808 if (is_list || PyList_CheckExact(o)) {
4809 Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
4810 if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
4811 PyObject *r = PyList_GET_ITEM(o, n);
4812 Py_INCREF(r);
4813 return r;
4814 }
4815 }
4816 else if (PyTuple_CheckExact(o)) {
4817 Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
4818 if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
4819 PyObject *r = PyTuple_GET_ITEM(o, n);
4820 Py_INCREF(r);
4821 return r;
4822 }
4823 } else {
4824 PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
4825 if (likely(m && m->sq_item)) {
4826 if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
4827 Py_ssize_t l = m->sq_length(o);
4828 if (likely(l >= 0)) {
4829 i += l;
4830 } else {
4831 if (!PyErr_ExceptionMatches(PyExc_OverflowError))
4832 return NULL;
4833 PyErr_Clear();
4834 }
4835 }
4836 return m->sq_item(o, i);
4837 }
4838 }
4839 #else
4840 if (is_list || PySequence_Check(o)) {
4841 return PySequence_GetItem(o, i);
4842 }
4843 #endif
4844 return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
4845 }
4846
4847 /* PyIntBinop */
4848 #if !CYTHON_COMPILING_IN_PYPY
4849 static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
4850 (void)inplace;
4851 (void)zerodivision_check;
4852 #if PY_MAJOR_VERSION < 3
4853 if (likely(PyInt_CheckExact(op1))) {
4854 const long b = intval;
4855 long x;
4856 long a = PyInt_AS_LONG(op1);
4857 x = (long)((unsigned long)a - b);
4858 if (likely((x^a) >= 0 || (x^~b) >= 0))
4859 return PyInt_FromLong(x);
4860 return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
4861 }
4862 #endif
4863 #if CYTHON_USE_PYLONG_INTERNALS
4864 if (likely(PyLong_CheckExact(op1))) {
4865 const long b = intval;
4866 long a, x;
4867 #ifdef HAVE_LONG_LONG
4868 const PY_LONG_LONG llb = intval;
4869 PY_LONG_LONG lla, llx;
4870 #endif
4871 const digit* digits = ((PyLongObject*)op1)->ob_digit;
4872 const Py_ssize_t size = Py_SIZE(op1);
4873 if (likely(__Pyx_sst_abs(size) <= 1)) {
4874 a = likely(size) ? digits[0] : 0;
4875 if (size == -1) a = -a;
4876 } else {
4877 switch (size) {
4878 case -2:
4879 if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4880 a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4881 break;
4882 #ifdef HAVE_LONG_LONG
4883 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4884 lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4885 goto long_long;
4886 #endif
4887 }
4888 CYTHON_FALLTHROUGH;
4889 case 2:
4890 if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4891 a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4892 break;
4893 #ifdef HAVE_LONG_LONG
4894 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4895 lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4896 goto long_long;
4897 #endif
4898 }
4899 CYTHON_FALLTHROUGH;
4900 case -3:
4901 if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4902 a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4903 break;
4904 #ifdef HAVE_LONG_LONG
4905 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4906 lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4907 goto long_long;
4908 #endif
4909 }
4910 CYTHON_FALLTHROUGH;
4911 case 3:
4912 if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4913 a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4914 break;
4915 #ifdef HAVE_LONG_LONG
4916 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4917 lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4918 goto long_long;
4919 #endif
4920 }
4921 CYTHON_FALLTHROUGH;
4922 case -4:
4923 if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4924 a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4925 break;
4926 #ifdef HAVE_LONG_LONG
4927 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4928 lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4929 goto long_long;
4930 #endif
4931 }
4932 CYTHON_FALLTHROUGH;
4933 case 4:
4934 if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4935 a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4936 break;
4937 #ifdef HAVE_LONG_LONG
4938 } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4939 lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4940 goto long_long;
4941 #endif
4942 }
4943 CYTHON_FALLTHROUGH;
4944 default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
4945 }
4946 }
4947 x = a - b;
4948 return PyLong_FromLong(x);
4949 #ifdef HAVE_LONG_LONG
4950 long_long:
4951 llx = lla - llb;
4952 return PyLong_FromLongLong(llx);
4953 #endif
4954
4955
4956 }
4957 #endif
4958 if (PyFloat_CheckExact(op1)) {
4959 const long b = intval;
4960 double a = PyFloat_AS_DOUBLE(op1);
4961 double result;
4962 PyFPE_START_PROTECT("subtract", return NULL)
4963 result = ((double)a) - (double)b;
4964 PyFPE_END_PROTECT(result)
4965 return PyFloat_FromDouble(result);
4966 }
4967 return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
4968 }
4969 #endif
4970
4971 /* TypeImport */
4972 #ifndef __PYX_HAVE_RT_ImportType
4973 #define __PYX_HAVE_RT_ImportType
4974 static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
4975 size_t size, enum __Pyx_ImportType_CheckSize check_size)
4976 {
4977 PyObject *result = 0;
4978 char warning[200];
4979 Py_ssize_t basicsize;
4980 #ifdef Py_LIMITED_API
4981 PyObject *py_basicsize;
4982 #endif
4983 result = PyObject_GetAttrString(module, class_name);
4984 if (!result)
4985 goto bad;
4986 if (!PyType_Check(result)) {
4987 PyErr_Format(PyExc_TypeError,
4988 "%.200s.%.200s is not a type object",
4989 module_name, class_name);
4990 goto bad;
4991 }
4992 #ifndef Py_LIMITED_API
4993 basicsize = ((PyTypeObject *)result)->tp_basicsize;
4994 #else
4995 py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
4996 if (!py_basicsize)
4997 goto bad;
4998 basicsize = PyLong_AsSsize_t(py_basicsize);
4999 Py_DECREF(py_basicsize);
5000 py_basicsize = 0;
5001 if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
5002 goto bad;
5003 #endif
5004 if ((size_t)basicsize < size) {
5005 PyErr_Format(PyExc_ValueError,
5006 "%.200s.%.200s size changed, may indicate binary incompatibility. "
5007 "Expected %zd from C header, got %zd from PyObject",
5008 module_name, class_name, size, basicsize);
5009 goto bad;
5010 }
5011 if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
5012 PyErr_Format(PyExc_ValueError,
5013 "%.200s.%.200s size changed, may indicate binary incompatibility. "
5014 "Expected %zd from C header, got %zd from PyObject",
5015 module_name, class_name, size, basicsize);
5016 goto bad;
5017 }
5018 else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
5019 PyOS_snprintf(warning, sizeof(warning),
5020 "%s.%s size changed, may indicate binary incompatibility. "
5021 "Expected %zd from C header, got %zd from PyObject",
5022 module_name, class_name, size, basicsize);
5023 if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
5024 }
5025 return (PyTypeObject *)result;
5026 bad:
5027 Py_XDECREF(result);
5028 return NULL;
5029 }
5030 #endif
5031
5032 /* Import */
5033 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
5034 PyObject *empty_list = 0;
5035 PyObject *module = 0;
5036 PyObject *global_dict = 0;
5037 PyObject *empty_dict = 0;
5038 PyObject *list;
5039 #if PY_MAJOR_VERSION < 3
5040 PyObject *py_import;
5041 py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
5042 if (!py_import)
5043 goto bad;
5044 #endif
5045 if (from_list)
5046 list = from_list;
5047 else {
5048 empty_list = PyList_New(0);
5049 if (!empty_list)
5050 goto bad;
5051 list = empty_list;
5052 }
5053 global_dict = PyModule_GetDict(__pyx_m);
5054 if (!global_dict)
5055 goto bad;
5056 empty_dict = PyDict_New();
5057 if (!empty_dict)
5058 goto bad;
5059 {
5060 #if PY_MAJOR_VERSION >= 3
5061 if (level == -1) {
5062 if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
5063 module = PyImport_ImportModuleLevelObject(
5064 name, global_dict, empty_dict, list, 1);
5065 if (!module) {
5066 if (!PyErr_ExceptionMatches(PyExc_ImportError))
5067 goto bad;
5068 PyErr_Clear();
5069 }
5070 }
5071 level = 0;
5072 }
5073 #endif
5074 if (!module) {
5075 #if PY_MAJOR_VERSION < 3
5076 PyObject *py_level = PyInt_FromLong(level);
5077 if (!py_level)
5078 goto bad;
5079 module = PyObject_CallFunctionObjArgs(py_import,
5080 name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
5081 Py_DECREF(py_level);
5082 #else
5083 module = PyImport_ImportModuleLevelObject(
5084 name, global_dict, empty_dict, list, level);
5085 #endif
5086 }
5087 }
5088 bad:
5089 #if PY_MAJOR_VERSION < 3
5090 Py_XDECREF(py_import);
5091 #endif
5092 Py_XDECREF(empty_list);
5093 Py_XDECREF(empty_dict);
5094 return module;
5095 }
5096
5097 /* ImportFrom */
5098 static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
5099 PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
5100 if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
5101 PyErr_Format(PyExc_ImportError,
5102 #if PY_MAJOR_VERSION < 3
5103 "cannot import name %.230s", PyString_AS_STRING(name));
5104 #else
5105 "cannot import name %S", name);
5106 #endif
5107 }
5108 return value;
5109 }
5110
5111 /* PyDictVersioning */
5112 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
5113 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
5114 PyObject *dict = Py_TYPE(obj)->tp_dict;
5115 return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
5116 }
5117 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
5118 PyObject **dictptr = NULL;
5119 Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
5120 if (offset) {
5121 #if CYTHON_COMPILING_IN_CPYTHON
5122 dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
5123 #else
5124 dictptr = _PyObject_GetDictPtr(obj);
5125 #endif
5126 }
5127 return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
5128 }
5129 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
5130 PyObject *dict = Py_TYPE(obj)->tp_dict;
5131 if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
5132 return 0;
5133 return obj_dict_version == __Pyx_get_object_dict_version(obj);
5134 }
5135 #endif
5136
5137 /* GetModuleGlobalName */
5138 #if CYTHON_USE_DICT_VERSIONS
5139 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
5140 #else
5141 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
5142 #endif
5143 {
5144 PyObject *result;
5145 #if !CYTHON_AVOID_BORROWED_REFS
5146 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
5147 result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
5148 __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
5149 if (likely(result)) {
5150 return __Pyx_NewRef(result);
5151 } else if (unlikely(PyErr_Occurred())) {
5152 return NULL;
5153 }
5154 #else
5155 result = PyDict_GetItem(__pyx_d, name);
5156 __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
5157 if (likely(result)) {
5158 return __Pyx_NewRef(result);
5159 }
5160 #endif
5161 #else
5162 result = PyObject_GetItem(__pyx_d, name);
5163 __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
5164 if (likely(result)) {
5165 return __Pyx_NewRef(result);
5166 }
5167 PyErr_Clear();
5168 #endif
5169 return __Pyx_GetBuiltinName(name);
5170 }
5171
5172 /* PyErrFetchRestore */
5173 #if CYTHON_FAST_THREAD_STATE
5174 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
5175 PyObject *tmp_type, *tmp_value, *tmp_tb;
5176 tmp_type = tstate->curexc_type;
5177 tmp_value = tstate->curexc_value;
5178 tmp_tb = tstate->curexc_traceback;
5179 tstate->curexc_type = type;
5180 tstate->curexc_value = value;
5181 tstate->curexc_traceback = tb;
5182 Py_XDECREF(tmp_type);
5183 Py_XDECREF(tmp_value);
5184 Py_XDECREF(tmp_tb);
5185 }
5186 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
5187 *type = tstate->curexc_type;
5188 *value = tstate->curexc_value;
5189 *tb = tstate->curexc_traceback;
5190 tstate->curexc_type = 0;
5191 tstate->curexc_value = 0;
5192 tstate->curexc_traceback = 0;
5193 }
5194 #endif
5195
5196 /* CLineInTraceback */
5197 #ifndef CYTHON_CLINE_IN_TRACEBACK
5198 static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
5199 PyObject *use_cline;
5200 PyObject *ptype, *pvalue, *ptraceback;
5201 #if CYTHON_COMPILING_IN_CPYTHON
5202 PyObject **cython_runtime_dict;
5203 #endif
5204 if (unlikely(!__pyx_cython_runtime)) {
5205 return c_line;
5206 }
5207 __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
5208 #if CYTHON_COMPILING_IN_CPYTHON
5209 cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
5210 if (likely(cython_runtime_dict)) {
5211 __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
5212 use_cline, *cython_runtime_dict,
5213 __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
5214 } else
5215 #endif
5216 {
5217 PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
5218 if (use_cline_obj) {
5219 use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
5220 Py_DECREF(use_cline_obj);
5221 } else {
5222 PyErr_Clear();
5223 use_cline = NULL;
5224 }
5225 }
5226 if (!use_cline) {
5227 c_line = 0;
5228 PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
5229 }
5230 else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
5231 c_line = 0;
5232 }
5233 __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
5234 return c_line;
5235 }
5236 #endif
5237
5238 /* CodeObjectCache */
5239 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
5240 int start = 0, mid = 0, end = count - 1;
5241 if (end >= 0 && code_line > entries[end].code_line) {
5242 return count;
5243 }
5244 while (start < end) {
5245 mid = start + (end - start) / 2;
5246 if (code_line < entries[mid].code_line) {
5247 end = mid;
5248 } else if (code_line > entries[mid].code_line) {
5249 start = mid + 1;
5250 } else {
5251 return mid;
5252 }
5253 }
5254 if (code_line <= entries[mid].code_line) {
5255 return mid;
5256 } else {
5257 return mid + 1;
5258 }
5259 }
5260 static PyCodeObject *__pyx_find_code_object(int code_line) {
5261 PyCodeObject* code_object;
5262 int pos;
5263 if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
5264 return NULL;
5265 }
5266 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5267 if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
5268 return NULL;
5269 }
5270 code_object = __pyx_code_cache.entries[pos].code_object;
5271 Py_INCREF(code_object);
5272 return code_object;
5273 }
5274 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
5275 int pos, i;
5276 __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
5277 if (unlikely(!code_line)) {
5278 return;
5279 }
5280 if (unlikely(!entries)) {
5281 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
5282 if (likely(entries)) {
5283 __pyx_code_cache.entries = entries;
5284 __pyx_code_cache.max_count = 64;
5285 __pyx_code_cache.count = 1;
5286 entries[0].code_line = code_line;
5287 entries[0].code_object = code_object;
5288 Py_INCREF(code_object);
5289 }
5290 return;
5291 }
5292 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5293 if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
5294 PyCodeObject* tmp = entries[pos].code_object;
5295 entries[pos].code_object = code_object;
5296 Py_DECREF(tmp);
5297 return;
5298 }
5299 if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
5300 int new_max = __pyx_code_cache.max_count + 64;
5301 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
5302 __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
5303 if (unlikely(!entries)) {
5304 return;
5305 }
5306 __pyx_code_cache.entries = entries;
5307 __pyx_code_cache.max_count = new_max;
5308 }
5309 for (i=__pyx_code_cache.count; i>pos; i--) {
5310 entries[i] = entries[i-1];
5311 }
5312 entries[pos].code_line = code_line;
5313 entries[pos].code_object = code_object;
5314 __pyx_code_cache.count++;
5315 Py_INCREF(code_object);
5316 }
5317
5318 /* AddTraceback */
5319 #include "compile.h"
5320 #include "frameobject.h"
5321 #include "traceback.h"
5322 static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
5323 const char *funcname, int c_line,
5324 int py_line, const char *filename) {
5325 PyCodeObject *py_code = 0;
5326 PyObject *py_srcfile = 0;
5327 PyObject *py_funcname = 0;
5328 #if PY_MAJOR_VERSION < 3
5329 py_srcfile = PyString_FromString(filename);
5330 #else
5331 py_srcfile = PyUnicode_FromString(filename);
5332 #endif
5333 if (!py_srcfile) goto bad;
5334 if (c_line) {
5335 #if PY_MAJOR_VERSION < 3
5336 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5337 #else
5338 py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5339 #endif
5340 }
5341 else {
5342 #if PY_MAJOR_VERSION < 3
5343 py_funcname = PyString_FromString(funcname);
5344 #else
5345 py_funcname = PyUnicode_FromString(funcname);
5346 #endif
5347 }
5348 if (!py_funcname) goto bad;
5349 py_code = __Pyx_PyCode_New(
5350 0,
5351 0,
5352 0,
5353 0,
5354 0,
5355 __pyx_empty_bytes, /*PyObject *code,*/
5356 __pyx_empty_tuple, /*PyObject *consts,*/
5357 __pyx_empty_tuple, /*PyObject *names,*/
5358 __pyx_empty_tuple, /*PyObject *varnames,*/
5359 __pyx_empty_tuple, /*PyObject *freevars,*/
5360 __pyx_empty_tuple, /*PyObject *cellvars,*/
5361 py_srcfile, /*PyObject *filename,*/
5362 py_funcname, /*PyObject *name,*/
5363 py_line,
5364 __pyx_empty_bytes /*PyObject *lnotab*/
5365 );
5366 Py_DECREF(py_srcfile);
5367 Py_DECREF(py_funcname);
5368 return py_code;
5369 bad:
5370 Py_XDECREF(py_srcfile);
5371 Py_XDECREF(py_funcname);
5372 return NULL;
5373 }
5374 static void __Pyx_AddTraceback(const char *funcname, int c_line,
5375 int py_line, const char *filename) {
5376 PyCodeObject *py_code = 0;
5377 PyFrameObject *py_frame = 0;
5378 PyThreadState *tstate = __Pyx_PyThreadState_Current;
5379 if (c_line) {
5380 c_line = __Pyx_CLineForTraceback(tstate, c_line);
5381 }
5382 py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
5383 if (!py_code) {
5384 py_code = __Pyx_CreateCodeObjectForTraceback(
5385 funcname, c_line, py_line, filename);
5386 if (!py_code) goto bad;
5387 __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
5388 }
5389 py_frame = PyFrame_New(
5390 tstate, /*PyThreadState *tstate,*/
5391 py_code, /*PyCodeObject *code,*/
5392 __pyx_d, /*PyObject *globals,*/
5393 0 /*PyObject *locals*/
5394 );
5395 if (!py_frame) goto bad;
5396 __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
5397 PyTraceBack_Here(py_frame);
5398 bad:
5399 Py_XDECREF(py_code);
5400 Py_XDECREF(py_frame);
5401 }
5402
5403 /* CIntFromPyVerify */
5404 #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
5405 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
5406 #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
5407 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
5408 #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
5409 {\
5410 func_type value = func_value;\
5411 if (sizeof(target_type) < sizeof(func_type)) {\
5412 if (unlikely(value != (func_type) (target_type) value)) {\
5413 func_type zero = 0;\
5414 if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
5415 return (target_type) -1;\
5416 if (is_unsigned && unlikely(value < zero))\
5417 goto raise_neg_overflow;\
5418 else\
5419 goto raise_overflow;\
5420 }\
5421 }\
5422 return (target_type) value;\
5423 }
5424
5425 /* CIntToPy */
5426 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) {
5427 const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
5428 const int is_unsigned = neg_one > const_zero;
5429 if (is_unsigned) {
5430 if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
5431 return PyInt_FromLong((long) value);
5432 } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
5433 return PyLong_FromUnsignedLong((unsigned long) value);
5434 #ifdef HAVE_LONG_LONG
5435 } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
5436 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
5437 #endif
5438 }
5439 } else {
5440 if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
5441 return PyInt_FromLong((long) value);
5442 #ifdef HAVE_LONG_LONG
5443 } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
5444 return PyLong_FromLongLong((PY_LONG_LONG) value);
5445 #endif
5446 }
5447 }
5448 {
5449 int one = 1; int little = (int)*(unsigned char *)&one;
5450 unsigned char *bytes = (unsigned char *)&value;
5451 return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG),
5452 little, !is_unsigned);
5453 }
5454 }
5455
5456 /* CIntFromPy */
5457 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) {
5458 const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
5459 const int is_unsigned = neg_one > const_zero;
5460 #if PY_MAJOR_VERSION < 3
5461 if (likely(PyInt_Check(x))) {
5462 if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
5463 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x))
5464 } else {
5465 long val = PyInt_AS_LONG(x);
5466 if (is_unsigned && unlikely(val < 0)) {
5467 goto raise_neg_overflow;
5468 }
5469 return (unsigned PY_LONG_LONG) val;
5470 }
5471 } else
5472 #endif
5473 if (likely(PyLong_Check(x))) {
5474 if (is_unsigned) {
5475 #if CYTHON_USE_PYLONG_INTERNALS
5476 const digit* digits = ((PyLongObject*)x)->ob_digit;
5477 switch (Py_SIZE(x)) {
5478 case 0: return (unsigned PY_LONG_LONG) 0;
5479 case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0])
5480 case 2:
5481 if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
5482 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5483 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5484 } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) {
5485 return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
5486 }
5487 }
5488 break;
5489 case 3:
5490 if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
5491 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5492 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5493 } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) {
5494 return (unsigned PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
5495 }
5496 }
5497 break;
5498 case 4:
5499 if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
5500 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5501 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5502 } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) {
5503 return (unsigned PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
5504 }
5505 }
5506 break;
5507 }
5508 #endif
5509 #if CYTHON_COMPILING_IN_CPYTHON
5510 if (unlikely(Py_SIZE(x) < 0)) {
5511 goto raise_neg_overflow;
5512 }
5513 #else
5514 {
5515 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5516 if (unlikely(result < 0))
5517 return (unsigned PY_LONG_LONG) -1;
5518 if (unlikely(result == 1))
5519 goto raise_neg_overflow;
5520 }
5521 #endif
5522 if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
5523 __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x))
5524 #ifdef HAVE_LONG_LONG
5525 } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
5526 __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5527 #endif
5528 }
5529 } else {
5530 #if CYTHON_USE_PYLONG_INTERNALS
5531 const digit* digits = ((PyLongObject*)x)->ob_digit;
5532 switch (Py_SIZE(x)) {
5533 case 0: return (unsigned PY_LONG_LONG) 0;
5534 case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0]))
5535 case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, +digits[0])
5536 case -2:
5537 if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) {
5538 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5539 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5540 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
5541 return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5542 }
5543 }
5544 break;
5545 case 2:
5546 if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
5547 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5548 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5549 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
5550 return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5551 }
5552 }
5553 break;
5554 case -3:
5555 if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
5556 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5557 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5558 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
5559 return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5560 }
5561 }
5562 break;
5563 case 3:
5564 if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
5565 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5566 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5567 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
5568 return (unsigned PY_LONG_LONG) ((((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5569 }
5570 }
5571 break;
5572 case -4:
5573 if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
5574 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5575 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5576 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
5577 return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5578 }
5579 }
5580 break;
5581 case 4:
5582 if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
5583 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5584 __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5585 } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
5586 return (unsigned PY_LONG_LONG) ((((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
5587 }
5588 }
5589 break;
5590 }
5591 #endif
5592 if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
5593 __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x))
5594 #ifdef HAVE_LONG_LONG
5595 } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
5596 __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x))
5597 #endif
5598 }
5599 }
5600 {
5601 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
5602 PyErr_SetString(PyExc_RuntimeError,
5603 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
5604 #else
5605 unsigned PY_LONG_LONG val;
5606 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
5607 #if PY_MAJOR_VERSION < 3
5608 if (likely(v) && !PyLong_Check(v)) {
5609 PyObject *tmp = v;
5610 v = PyNumber_Long(tmp);
5611 Py_DECREF(tmp);
5612 }
5613 #endif
5614 if (likely(v)) {
5615 int one = 1; int is_little = (int)*(unsigned char *)&one;
5616 unsigned char *bytes = (unsigned char *)&val;
5617 int ret = _PyLong_AsByteArray((PyLongObject *)v,
5618 bytes, sizeof(val),
5619 is_little, !is_unsigned);
5620 Py_DECREF(v);
5621 if (likely(!ret))
5622 return val;
5623 }
5624 #endif
5625 return (unsigned PY_LONG_LONG) -1;
5626 }
5627 } else {
5628 unsigned PY_LONG_LONG val;
5629 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
5630 if (!tmp) return (unsigned PY_LONG_LONG) -1;
5631 val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp);
5632 Py_DECREF(tmp);
5633 return val;
5634 }
5635 raise_overflow:
5636 PyErr_SetString(PyExc_OverflowError,
5637 "value too large to convert to unsigned PY_LONG_LONG");
5638 return (unsigned PY_LONG_LONG) -1;
5639 raise_neg_overflow:
5640 PyErr_SetString(PyExc_OverflowError,
5641 "can't convert negative value to unsigned PY_LONG_LONG");
5642 return (unsigned PY_LONG_LONG) -1;
5643 }
5644
5645 /* CIntToPy */
5646 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
5647 const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
5648 const int is_unsigned = neg_one > const_zero;
5649 if (is_unsigned) {
5650 if (sizeof(long) < sizeof(long)) {
5651 return PyInt_FromLong((long) value);
5652 } else if (sizeof(long) <= sizeof(unsigned long)) {
5653 return PyLong_FromUnsignedLong((unsigned long) value);
5654 #ifdef HAVE_LONG_LONG
5655 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
5656 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
5657 #endif
5658 }
5659 } else {
5660 if (sizeof(long) <= sizeof(long)) {
5661 return PyInt_FromLong((long) value);
5662 #ifdef HAVE_LONG_LONG
5663 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
5664 return PyLong_FromLongLong((PY_LONG_LONG) value);
5665 #endif
5666 }
5667 }
5668 {
5669 int one = 1; int little = (int)*(unsigned char *)&one;
5670 unsigned char *bytes = (unsigned char *)&value;
5671 return _PyLong_FromByteArray(bytes, sizeof(long),
5672 little, !is_unsigned);
5673 }
5674 }
5675
5676 /* CIntFromPy */
5677 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
5678 const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
5679 const int is_unsigned = neg_one > const_zero;
5680 #if PY_MAJOR_VERSION < 3
5681 if (likely(PyInt_Check(x))) {
5682 if (sizeof(long) < sizeof(long)) {
5683 __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
5684 } else {
5685 long val = PyInt_AS_LONG(x);
5686 if (is_unsigned && unlikely(val < 0)) {
5687 goto raise_neg_overflow;
5688 }
5689 return (long) val;
5690 }
5691 } else
5692 #endif
5693 if (likely(PyLong_Check(x))) {
5694 if (is_unsigned) {
5695 #if CYTHON_USE_PYLONG_INTERNALS
5696 const digit* digits = ((PyLongObject*)x)->ob_digit;
5697 switch (Py_SIZE(x)) {
5698 case 0: return (long) 0;
5699 case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
5700 case 2:
5701 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
5702 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5703 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5704 } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
5705 return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5706 }
5707 }
5708 break;
5709 case 3:
5710 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
5711 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5712 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5713 } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
5714 return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5715 }
5716 }
5717 break;
5718 case 4:
5719 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
5720 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5721 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5722 } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
5723 return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5724 }
5725 }
5726 break;
5727 }
5728 #endif
5729 #if CYTHON_COMPILING_IN_CPYTHON
5730 if (unlikely(Py_SIZE(x) < 0)) {
5731 goto raise_neg_overflow;
5732 }
5733 #else
5734 {
5735 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5736 if (unlikely(result < 0))
5737 return (long) -1;
5738 if (unlikely(result == 1))
5739 goto raise_neg_overflow;
5740 }
5741 #endif
5742 if (sizeof(long) <= sizeof(unsigned long)) {
5743 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
5744 #ifdef HAVE_LONG_LONG
5745 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
5746 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5747 #endif
5748 }
5749 } else {
5750 #if CYTHON_USE_PYLONG_INTERNALS
5751 const digit* digits = ((PyLongObject*)x)->ob_digit;
5752 switch (Py_SIZE(x)) {
5753 case 0: return (long) 0;
5754 case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
5755 case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
5756 case -2:
5757 if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
5758 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5759 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5760 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5761 return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5762 }
5763 }
5764 break;
5765 case 2:
5766 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
5767 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5768 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5769 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5770 return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5771 }
5772 }
5773 break;
5774 case -3:
5775 if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5776 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5777 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5778 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5779 return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5780 }
5781 }
5782 break;
5783 case 3:
5784 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
5785 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5786 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5787 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5788 return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5789 }
5790 }
5791 break;
5792 case -4:
5793 if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5794 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5795 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5796 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5797 return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5798 }
5799 }
5800 break;
5801 case 4:
5802 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
5803 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5804 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5805 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5806 return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5807 }
5808 }
5809 break;
5810 }
5811 #endif
5812 if (sizeof(long) <= sizeof(long)) {
5813 __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
5814 #ifdef HAVE_LONG_LONG
5815 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
5816 __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
5817 #endif
5818 }
5819 }
5820 {
5821 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
5822 PyErr_SetString(PyExc_RuntimeError,
5823 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
5824 #else
5825 long val;
5826 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
5827 #if PY_MAJOR_VERSION < 3
5828 if (likely(v) && !PyLong_Check(v)) {
5829 PyObject *tmp = v;
5830 v = PyNumber_Long(tmp);
5831 Py_DECREF(tmp);
5832 }
5833 #endif
5834 if (likely(v)) {
5835 int one = 1; int is_little = (int)*(unsigned char *)&one;
5836 unsigned char *bytes = (unsigned char *)&val;
5837 int ret = _PyLong_AsByteArray((PyLongObject *)v,
5838 bytes, sizeof(val),
5839 is_little, !is_unsigned);
5840 Py_DECREF(v);
5841 if (likely(!ret))
5842 return val;
5843 }
5844 #endif
5845 return (long) -1;
5846 }
5847 } else {
5848 long val;
5849 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
5850 if (!tmp) return (long) -1;
5851 val = __Pyx_PyInt_As_long(tmp);
5852 Py_DECREF(tmp);
5853 return val;
5854 }
5855 raise_overflow:
5856 PyErr_SetString(PyExc_OverflowError,
5857 "value too large to convert to long");
5858 return (long) -1;
5859 raise_neg_overflow:
5860 PyErr_SetString(PyExc_OverflowError,
5861 "can't convert negative value to long");
5862 return (long) -1;
5863 }
5864
5865 /* CIntFromPy */
5866 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
5867 const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
5868 const int is_unsigned = neg_one > const_zero;
5869 #if PY_MAJOR_VERSION < 3
5870 if (likely(PyInt_Check(x))) {
5871 if (sizeof(int) < sizeof(long)) {
5872 __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
5873 } else {
5874 long val = PyInt_AS_LONG(x);
5875 if (is_unsigned && unlikely(val < 0)) {
5876 goto raise_neg_overflow;
5877 }
5878 return (int) val;
5879 }
5880 } else
5881 #endif
5882 if (likely(PyLong_Check(x))) {
5883 if (is_unsigned) {
5884 #if CYTHON_USE_PYLONG_INTERNALS
5885 const digit* digits = ((PyLongObject*)x)->ob_digit;
5886 switch (Py_SIZE(x)) {
5887 case 0: return (int) 0;
5888 case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
5889 case 2:
5890 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5891 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5892 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5893 } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
5894 return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5895 }
5896 }
5897 break;
5898 case 3:
5899 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5900 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5901 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5902 } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
5903 return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5904 }
5905 }
5906 break;
5907 case 4:
5908 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5909 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5910 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5911 } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
5912 return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5913 }
5914 }
5915 break;
5916 }
5917 #endif
5918 #if CYTHON_COMPILING_IN_CPYTHON
5919 if (unlikely(Py_SIZE(x) < 0)) {
5920 goto raise_neg_overflow;
5921 }
5922 #else
5923 {
5924 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5925 if (unlikely(result < 0))
5926 return (int) -1;
5927 if (unlikely(result == 1))
5928 goto raise_neg_overflow;
5929 }
5930 #endif
5931 if (sizeof(int) <= sizeof(unsigned long)) {
5932 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
5933 #ifdef HAVE_LONG_LONG
5934 } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
5935 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5936 #endif
5937 }
5938 } else {
5939 #if CYTHON_USE_PYLONG_INTERNALS
5940 const digit* digits = ((PyLongObject*)x)->ob_digit;
5941 switch (Py_SIZE(x)) {
5942 case 0: return (int) 0;
5943 case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
5944 case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
5945 case -2:
5946 if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
5947 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5948 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5949 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5950 return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5951 }
5952 }
5953 break;
5954 case 2:
5955 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5956 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5957 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5958 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5959 return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5960 }
5961 }
5962 break;
5963 case -3:
5964 if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5965 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5966 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5967 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5968 return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5969 }
5970 }
5971 break;
5972 case 3:
5973 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5974 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5975 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5976 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5977 return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5978 }
5979 }
5980 break;
5981 case -4:
5982 if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5983 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5984 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5985 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5986 return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5987 }
5988 }
5989 break;
5990 case 4:
5991 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5992 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5993 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5994 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5995 return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5996 }
5997 }
5998 break;
5999 }
6000 #endif
6001 if (sizeof(int) <= sizeof(long)) {
6002 __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
6003 #ifdef HAVE_LONG_LONG
6004 } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
6005 __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
6006 #endif
6007 }
6008 }
6009 {
6010 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
6011 PyErr_SetString(PyExc_RuntimeError,
6012 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
6013 #else
6014 int val;
6015 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
6016 #if PY_MAJOR_VERSION < 3
6017 if (likely(v) && !PyLong_Check(v)) {
6018 PyObject *tmp = v;
6019 v = PyNumber_Long(tmp);
6020 Py_DECREF(tmp);
6021 }
6022 #endif
6023 if (likely(v)) {
6024 int one = 1; int is_little = (int)*(unsigned char *)&one;
6025 unsigned char *bytes = (unsigned char *)&val;
6026 int ret = _PyLong_AsByteArray((PyLongObject *)v,
6027 bytes, sizeof(val),
6028 is_little, !is_unsigned);
6029 Py_DECREF(v);
6030 if (likely(!ret))
6031 return val;
6032 }
6033 #endif
6034 return (int) -1;
6035 }
6036 } else {
6037 int val;
6038 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
6039 if (!tmp) return (int) -1;
6040 val = __Pyx_PyInt_As_int(tmp);
6041 Py_DECREF(tmp);
6042 return val;
6043 }
6044 raise_overflow:
6045 PyErr_SetString(PyExc_OverflowError,
6046 "value too large to convert to int");
6047 return (int) -1;
6048 raise_neg_overflow:
6049 PyErr_SetString(PyExc_OverflowError,
6050 "can't convert negative value to int");
6051 return (int) -1;
6052 }
6053
6054 /* FastTypeChecks */
6055 #if CYTHON_COMPILING_IN_CPYTHON
6056 static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
6057 while (a) {
6058 a = a->tp_base;
6059 if (a == b)
6060 return 1;
6061 }
6062 return b == &PyBaseObject_Type;
6063 }
6064 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
6065 PyObject *mro;
6066 if (a == b) return 1;
6067 mro = a->tp_mro;
6068 if (likely(mro)) {
6069 Py_ssize_t i, n;
6070 n = PyTuple_GET_SIZE(mro);
6071 for (i = 0; i < n; i++) {
6072 if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
6073 return 1;
6074 }
6075 return 0;
6076 }
6077 return __Pyx_InBases(a, b);
6078 }
6079 #if PY_MAJOR_VERSION == 2
6080 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
6081 PyObject *exception, *value, *tb;
6082 int res;
6083 __Pyx_PyThreadState_declare
6084 __Pyx_PyThreadState_assign
6085 __Pyx_ErrFetch(&exception, &value, &tb);
6086 res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
6087 if (unlikely(res == -1)) {
6088 PyErr_WriteUnraisable(err);
6089 res = 0;
6090 }
6091 if (!res) {
6092 res = PyObject_IsSubclass(err, exc_type2);
6093 if (unlikely(res == -1)) {
6094 PyErr_WriteUnraisable(err);
6095 res = 0;
6096 }
6097 }
6098 __Pyx_ErrRestore(exception, value, tb);
6099 return res;
6100 }
6101 #else
6102 static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
6103 int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
6104 if (!res) {
6105 res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
6106 }
6107 return res;
6108 }
6109 #endif
6110 static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
6111 Py_ssize_t i, n;
6112 assert(PyExceptionClass_Check(exc_type));
6113 n = PyTuple_GET_SIZE(tuple);
6114 #if PY_MAJOR_VERSION >= 3
6115 for (i=0; i<n; i++) {
6116 if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
6117 }
6118 #endif
6119 for (i=0; i<n; i++) {
6120 PyObject *t = PyTuple_GET_ITEM(tuple, i);
6121 #if PY_MAJOR_VERSION < 3
6122 if (likely(exc_type == t)) return 1;
6123 #endif
6124 if (likely(PyExceptionClass_Check(t))) {
6125 if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
6126 } else {
6127 }
6128 }
6129 return 0;
6130 }
6131 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
6132 if (likely(err == exc_type)) return 1;
6133 if (likely(PyExceptionClass_Check(err))) {
6134 if (likely(PyExceptionClass_Check(exc_type))) {
6135 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
6136 } else if (likely(PyTuple_Check(exc_type))) {
6137 return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
6138 } else {
6139 }
6140 }
6141 return PyErr_GivenExceptionMatches(err, exc_type);
6142 }
6143 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
6144 assert(PyExceptionClass_Check(exc_type1));
6145 assert(PyExceptionClass_Check(exc_type2));
6146 if (likely(err == exc_type1 || err == exc_type2)) return 1;
6147 if (likely(PyExceptionClass_Check(err))) {
6148 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
6149 }
6150 return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
6151 }
6152 #endif
6153
6154 /* CheckBinaryVersion */
6155 static int __Pyx_check_binary_version(void) {
6156 char ctversion[4], rtversion[4];
6157 PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
6158 PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
6159 if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
6160 char message[200];
6161 PyOS_snprintf(message, sizeof(message),
6162 "compiletime version %s of module '%.100s' "
6163 "does not match runtime version %s",
6164 ctversion, __Pyx_MODULE_NAME, rtversion);
6165 return PyErr_WarnEx(NULL, message, 1);
6166 }
6167 return 0;
6168 }
6169
6170 /* InitStrings */
6171 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
6172 while (t->p) {
6173 #if PY_MAJOR_VERSION < 3
6174 if (t->is_unicode) {
6175 *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
6176 } else if (t->intern) {
6177 *t->p = PyString_InternFromString(t->s);
6178 } else {
6179 *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
6180 }
6181 #else
6182 if (t->is_unicode | t->is_str) {
6183 if (t->intern) {
6184 *t->p = PyUnicode_InternFromString(t->s);
6185 } else if (t->encoding) {
6186 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
6187 } else {
6188 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
6189 }
6190 } else {
6191 *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
6192 }
6193 #endif
6194 if (!*t->p)
6195 return -1;
6196 if (PyObject_Hash(*t->p) == -1)
6197 return -1;
6198 ++t;
6199 }
6200 return 0;
6201 }
6202
6203 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
6204 return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
6205 }
6206 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
6207 Py_ssize_t ignore;
6208 return __Pyx_PyObject_AsStringAndSize(o, &ignore);
6209 }
6210 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
6211 #if !CYTHON_PEP393_ENABLED
6212 static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6213 char* defenc_c;
6214 PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
6215 if (!defenc) return NULL;
6216 defenc_c = PyBytes_AS_STRING(defenc);
6217 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6218 {
6219 char* end = defenc_c + PyBytes_GET_SIZE(defenc);
6220 char* c;
6221 for (c = defenc_c; c < end; c++) {
6222 if ((unsigned char) (*c) >= 128) {
6223 PyUnicode_AsASCIIString(o);
6224 return NULL;
6225 }
6226 }
6227 }
6228 #endif
6229 *length = PyBytes_GET_SIZE(defenc);
6230 return defenc_c;
6231 }
6232 #else
6233 static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6234 if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
6235 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6236 if (likely(PyUnicode_IS_ASCII(o))) {
6237 *length = PyUnicode_GET_LENGTH(o);
6238 return PyUnicode_AsUTF8(o);
6239 } else {
6240 PyUnicode_AsASCIIString(o);
6241 return NULL;
6242 }
6243 #else
6244 return PyUnicode_AsUTF8AndSize(o, length);
6245 #endif
6246 }
6247 #endif
6248 #endif
6249 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6250 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
6251 if (
6252 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6253 __Pyx_sys_getdefaultencoding_not_ascii &&
6254 #endif
6255 PyUnicode_Check(o)) {
6256 return __Pyx_PyUnicode_AsStringAndSize(o, length);
6257 } else
6258 #endif
6259 #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
6260 if (PyByteArray_Check(o)) {
6261 *length = PyByteArray_GET_SIZE(o);
6262 return PyByteArray_AS_STRING(o);
6263 } else
6264 #endif
6265 {
6266 char* result;
6267 int r = PyBytes_AsStringAndSize(o, &result, length);
6268 if (unlikely(r < 0)) {
6269 return NULL;
6270 } else {
6271 return result;
6272 }
6273 }
6274 }
6275 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
6276 int is_true = x == Py_True;
6277 if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
6278 else return PyObject_IsTrue(x);
6279 }
6280 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
6281 int retval;
6282 if (unlikely(!x)) return -1;
6283 retval = __Pyx_PyObject_IsTrue(x);
6284 Py_DECREF(x);
6285 return retval;
6286 }
6287 static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
6288 #if PY_MAJOR_VERSION >= 3
6289 if (PyLong_Check(result)) {
6290 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
6291 "__int__ returned non-int (type %.200s). "
6292 "The ability to return an instance of a strict subclass of int "
6293 "is deprecated, and may be removed in a future version of Python.",
6294 Py_TYPE(result)->tp_name)) {
6295 Py_DECREF(result);
6296 return NULL;
6297 }
6298 return result;
6299 }
6300 #endif
6301 PyErr_Format(PyExc_TypeError,
6302 "__%.4s__ returned non-%.4s (type %.200s)",
6303 type_name, type_name, Py_TYPE(result)->tp_name);
6304 Py_DECREF(result);
6305 return NULL;
6306 }
6307 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
6308 #if CYTHON_USE_TYPE_SLOTS
6309 PyNumberMethods *m;
6310 #endif
6311 const char *name = NULL;
6312 PyObject *res = NULL;
6313 #if PY_MAJOR_VERSION < 3
6314 if (likely(PyInt_Check(x) || PyLong_Check(x)))
6315 #else
6316 if (likely(PyLong_Check(x)))
6317 #endif
6318 return __Pyx_NewRef(x);
6319 #if CYTHON_USE_TYPE_SLOTS
6320 m = Py_TYPE(x)->tp_as_number;
6321 #if PY_MAJOR_VERSION < 3
6322 if (m && m->nb_int) {
6323 name = "int";
6324 res = m->nb_int(x);
6325 }
6326 else if (m && m->nb_long) {
6327 name = "long";
6328 res = m->nb_long(x);
6329 }
6330 #else
6331 if (likely(m && m->nb_int)) {
6332 name = "int";
6333 res = m->nb_int(x);
6334 }
6335 #endif
6336 #else
6337 if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
6338 res = PyNumber_Int(x);
6339 }
6340 #endif
6341 if (likely(res)) {
6342 #if PY_MAJOR_VERSION < 3
6343 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
6344 #else
6345 if (unlikely(!PyLong_CheckExact(res))) {
6346 #endif
6347 return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
6348 }
6349 }
6350 else if (!PyErr_Occurred()) {
6351 PyErr_SetString(PyExc_TypeError,
6352 "an integer is required");
6353 }
6354 return res;
6355 }
6356 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
6357 Py_ssize_t ival;
6358 PyObject *x;
6359 #if PY_MAJOR_VERSION < 3
6360 if (likely(PyInt_CheckExact(b))) {
6361 if (sizeof(Py_ssize_t) >= sizeof(long))
6362 return PyInt_AS_LONG(b);
6363 else
6364 return PyInt_AsSsize_t(b);
6365 }
6366 #endif
6367 if (likely(PyLong_CheckExact(b))) {
6368 #if CYTHON_USE_PYLONG_INTERNALS
6369 const digit* digits = ((PyLongObject*)b)->ob_digit;
6370 const Py_ssize_t size = Py_SIZE(b);
6371 if (likely(__Pyx_sst_abs(size) <= 1)) {
6372 ival = likely(size) ? digits[0] : 0;
6373 if (size == -1) ival = -ival;
6374 return ival;
6375 } else {
6376 switch (size) {
6377 case 2:
6378 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6379 return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6380 }
6381 break;
6382 case -2:
6383 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6384 return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6385 }
6386 break;
6387 case 3:
6388 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6389 return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6390 }
6391 break;
6392 case -3:
6393 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6394 return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6395 }
6396 break;
6397 case 4:
6398 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6399 return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6400 }
6401 break;
6402 case -4:
6403 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6404 return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6405 }
6406 break;
6407 }
6408 }
6409 #endif
6410 return PyLong_AsSsize_t(b);
6411 }
6412 x = PyNumber_Index(b);
6413 if (!x) return -1;
6414 ival = PyInt_AsSsize_t(x);
6415 Py_DECREF(x);
6416 return ival;
6417 }
6418 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
6419 return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
6420 }
6421 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
6422 return PyInt_FromSize_t(ival);
6423 }
6424
6425
6426 #endif /* Py_PYTHON_H */
0 from cpython cimport Py_INCREF
1 from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
2
3 from .. import writer
4
5 cpdef object MAX_UINT64 = writer.MAX_UINT64
6 cpdef object MAX_INT64 = writer.MAX_INT64
7
8
9 def int128_from_quads(quad_items, unsigned long long n_items):
10 cdef unsigned int factor = 2
11 items = PyTuple_New(n_items)
12
13 cdef unsigned long long i, ix
14 cdef object item
15
16 for i in range(n_items):
17 ix = factor * i
18
19 if quad_items[ix + 1] > MAX_INT64:
20 item = (
21 -((MAX_UINT64 - quad_items[ix + 1]) << 64)
22 - (MAX_UINT64 - quad_items[ix])
23 - 1
24 )
25
26 else:
27 item = (quad_items[ix + 1] << 64) + quad_items[ix]
28
29 Py_INCREF(item)
30 PyTuple_SET_ITEM(items, i, item)
31
32 return items
33
34
35 def int128_to_quads(items, unsigned long long n_items):
36 cdef unsigned int factor = 2
37 quad_items = PyTuple_New(n_items * factor)
38
39 cdef unsigned long long i, ix
40 cdef object x, item
41
42 for i in range(n_items):
43 ix = factor * i
44
45 x = items[i]
46 if x < 0:
47 x = -x - 1
48
49 item = MAX_UINT64 - x & MAX_UINT64
50 Py_INCREF(item)
51 PyTuple_SET_ITEM(quad_items, ix, item)
52
53 item = MAX_UINT64 - (x >> 64) & MAX_UINT64
54 Py_INCREF(item)
55 PyTuple_SET_ITEM(quad_items, ix + 1, item)
56
57 else:
58 item = x & MAX_UINT64
59 Py_INCREF(item)
60 PyTuple_SET_ITEM(quad_items, ix, item)
61
62 item = (x >> 64) & MAX_UINT64
63 Py_INCREF(item)
64 PyTuple_SET_ITEM(quad_items, ix + 1, item)
65
66 return quad_items
67
68
69 def uint128_from_quads(quad_items, unsigned long long n_items):
70 cdef unsigned int factor = 2
71 items = PyTuple_New(n_items)
72
73 cdef unsigned long long i, ix
74 cdef object item
75
76 for i in range(n_items):
77 ix = factor * i
78 item = (quad_items[ix + 1] << 64) + quad_items[ix]
79
80 Py_INCREF(item)
81 PyTuple_SET_ITEM(items, i, item)
82
83 return items
84
85
86 def uint128_to_quads(items, unsigned long long n_items):
87 cdef unsigned int factor = 2
88 quad_items = PyTuple_New(n_items * factor)
89
90 cdef unsigned long long i, ix
91 cdef object x, item
92
93 for i in range(n_items):
94 ix = factor * i
95
96 x = items[i]
97 item = x & MAX_UINT64
98 Py_INCREF(item)
99 PyTuple_SET_ITEM(quad_items, ix, item)
100
101 item = (x >> 64) & MAX_UINT64
102 Py_INCREF(item)
103 PyTuple_SET_ITEM(quad_items, ix + 1, item)
104
105 return quad_items
106
107 # 256 bits
108
109
110 def int256_from_quads(quad_items, unsigned long long n_items):
111 cdef unsigned int factor = 4
112 items = PyTuple_New(n_items)
113
114 cdef unsigned long long i, ix
115 cdef object item
116
117 for i in range(n_items):
118 ix = factor * i
119
120 if quad_items[ix + 3] > MAX_INT64:
121 item = (
122 -((MAX_UINT64 - quad_items[ix + 3]) << 192)
123 -((MAX_UINT64 - quad_items[ix + 2]) << 128)
124 -((MAX_UINT64 - quad_items[ix + 1]) << 64)
125 - (MAX_UINT64 - quad_items[ix])
126 - 1
127 )
128
129 else:
130 item = (
131 (quad_items[ix + 3] << 192) +
132 (quad_items[ix + 2] << 128) +
133 (quad_items[ix + 1] << 64) +
134 quad_items[ix]
135 )
136
137 Py_INCREF(item)
138 PyTuple_SET_ITEM(items, i, item)
139
140 return items
141
142
143 def int256_to_quads(items, unsigned long long n_items):
144 cdef unsigned int factor = 4
145 quad_items = PyTuple_New(n_items * factor)
146
147 cdef unsigned long long i, ix
148 cdef object x, item
149
150 for i in range(n_items):
151 ix = factor * i
152
153 x = items[i]
154 if x < 0:
155 x = -x - 1
156
157 item = MAX_UINT64 - x & MAX_UINT64
158 Py_INCREF(item)
159 PyTuple_SET_ITEM(quad_items, ix, item)
160
161 item = MAX_UINT64 - (x >> 64) & MAX_UINT64
162 Py_INCREF(item)
163 PyTuple_SET_ITEM(quad_items, ix + 1, item)
164
165 item = MAX_UINT64 - (x >> 128) & MAX_UINT64
166 Py_INCREF(item)
167 PyTuple_SET_ITEM(quad_items, ix + 2, item)
168
169 item = MAX_UINT64 - (x >> 192) & MAX_UINT64
170 Py_INCREF(item)
171 PyTuple_SET_ITEM(quad_items, ix + 3, item)
172
173 else:
174 item = x & MAX_UINT64
175 Py_INCREF(item)
176 PyTuple_SET_ITEM(quad_items, ix, item)
177
178 item = (x >> 64) & MAX_UINT64
179 Py_INCREF(item)
180 PyTuple_SET_ITEM(quad_items, ix + 1, item)
181
182 item = (x >> 128) & MAX_UINT64
183 Py_INCREF(item)
184 PyTuple_SET_ITEM(quad_items, ix + 2, item)
185
186 item = (x >> 192) & MAX_UINT64
187 Py_INCREF(item)
188 PyTuple_SET_ITEM(quad_items, ix + 3, item)
189
190 return quad_items
191
192
193 def uint256_from_quads(quad_items, unsigned long long n_items):
194 cdef unsigned int factor = 4
195 items = PyTuple_New(n_items)
196
197 cdef unsigned long long i, ix
198 cdef object item
199
200 for i in range(n_items):
201 ix = factor * i
202 item = (
203 (quad_items[ix + 3] << 192) +
204 (quad_items[ix + 2] << 128) +
205 (quad_items[ix + 1] << 64) +
206 quad_items[ix]
207 )
208
209 Py_INCREF(item)
210 PyTuple_SET_ITEM(items, i, item)
211
212 return items
213
214
215 def uint256_to_quads(items, unsigned long long n_items):
216 cdef unsigned int factor = 4
217 quad_items = PyTuple_New(n_items * factor)
218
219 cdef unsigned long long i, ix
220 cdef object x, item
221
222 for i in range(n_items):
223 ix = factor * i
224
225 x = items[i]
226 item = x & MAX_UINT64
227 Py_INCREF(item)
228 PyTuple_SET_ITEM(quad_items, ix, item)
229
230 item = (x >> 64) & MAX_UINT64
231 Py_INCREF(item)
232 PyTuple_SET_ITEM(quad_items, ix + 1, item)
233
234 item = (x >> 128) & MAX_UINT64
235 Py_INCREF(item)
236 PyTuple_SET_ITEM(quad_items, ix + 2, item)
237
238 item = (x >> 192) & MAX_UINT64
239 Py_INCREF(item)
240 PyTuple_SET_ITEM(quad_items, ix + 3, item)
241
242 return quad_items
9595
9696 self.nested_column.write_data(index, buf)
9797 write_binary_int64(len(items), buf)
98 int_column.write_data(keys, buf)
98 int_column.write_items(keys, buf)
9999
100100 def _read_data(self, n_items, buf, nulls_map=None):
101101 if not n_items:
0 from .base import Column
1 from .intcolumn import UInt64Column
2 from ..util.helpers import pairwise
3
4
5 class MapColumn(Column):
6 py_types = (dict, )
7
8 def __init__(self, key_column, value_column, **kwargs):
9 self.offset_column = UInt64Column()
10 self.key_column = key_column
11 self.value_column = value_column
12 super(MapColumn, self).__init__(**kwargs)
13
14 def read_state_prefix(self, buf):
15 self.key_column.read_state_prefix(buf)
16 self.value_column.read_state_prefix(buf)
17
18 def write_state_prefix(self, buf):
19 self.key_column.write_state_prefix(buf)
20 self.value_column.write_state_prefix(buf)
21
22 def read_items(self, n_items, buf):
23 offsets = list(self.offset_column.read_items(n_items, buf))
24 last_offset = offsets[-1]
25 keys = self.key_column.read_data(last_offset, buf)
26 values = self.value_column.read_data(last_offset, buf)
27
28 offsets.insert(0, 0)
29
30 return [
31 dict(zip(keys[begin:end], values[begin:end]))
32 for begin, end in pairwise(offsets)
33 ]
34
35 def write_items(self, items, buf):
36 offsets = []
37 keys = []
38 values = []
39
40 total = 0
41 for x in items:
42 total += len(x)
43 offsets.append(total)
44 keys.extend(x.keys())
45 values.extend(x.values())
46
47 self.offset_column.write_items(offsets, buf)
48 self.key_column.write_data(keys, buf)
49 self.value_column.write_data(values, buf)
50
51
52 def create_map_column(spec, column_by_spec_getter):
53 key, value = spec[4:-1].split(',')
54 key_column = column_by_spec_getter(key.strip())
55 value_column = column_by_spec_getter(value.strip())
56
57 return MapColumn(key_column, value_column)
00 import numpy as np
1 import pandas as pd
12
23 from ..base import Column
34
56 class NumpyColumn(Column):
67 dtype = None
78
9 normalize_null_value = True
10
811 def read_items(self, n_items, buf):
912 data = buf.read(n_items * self.dtype.itemsize)
10 return np.frombuffer(data, self.dtype, n_items)
13 return np.frombuffer(data, self.dtype.newbyteorder('<'), n_items)
1114
1215 def write_items(self, items, buf):
13 buf.write(items.astype(self.dtype).tobytes())
16 buf.write(items.astype(self.dtype.newbyteorder('<')).tobytes())
17
18 def _write_nulls_map(self, items, buf):
19 s = self.make_null_struct(len(items))
20 nulls_map = self._get_nulls_map(items)
21 buf.write(s.pack(*nulls_map))
22
23 def _get_nulls_map(self, items):
24 return [bool(x) for x in pd.isnull(items)]
25
26 def _read_data(self, n_items, buf, nulls_map=None):
27 items = self.read_items(n_items, buf)
28
29 if self.after_read_items:
30 return self.after_read_items(items, nulls_map)
31 elif nulls_map is not None:
32 items = np.array(items, dtype=object)
33 np.place(items, nulls_map, None)
34
35 return items
36
37 def prepare_items(self, items):
38 nulls_map = pd.isnull(items)
39
40 # Always replace null values to null_value for proper inserts into
41 # non-nullable columns.
42 if isinstance(items, np.ndarray) and self.normalize_null_value:
43 items = np.array(items)
44 np.place(items, nulls_map, self.null_value)
45
46 return items
66 dtype = np.dtype(np.uint16)
77 ch_type = 'Date'
88
9 null_value = np.datetime64(0, 'Y')
10
911 def read_items(self, n_items, buf):
1012 data = super(NumpyDateColumn, self).read_items(n_items, buf)
1113 return data.astype('datetime64[D]')
14
15 def write_items(self, items, buf):
16 super(NumpyDateColumn, self).write_items(
17 items.astype('datetime64[D]'), buf
18 )
77
88 class NumpyDateTimeColumnBase(NumpyColumn):
99 datetime_dtype = None
10
11 null_value = np.datetime64(0, 'Y')
1012
1113 def __init__(self, timezone=None, offset_naive=True, local_timezone=None,
1214 **kwargs):
124126 # As Numpy do not use local timezone for converting timestamp to
125127 # datetime we need always detect local timezone for manual converting.
126128 try:
129 local_timezone = get_localzone().key
130 except AttributeError:
127131 local_timezone = get_localzone().zone
128132 except Exception:
129133 pass
00 import numpy as np
11
22 from .base import NumpyColumn
3
4 # normalize_null_value = False due to float('nan')
5 # With normalization pandas.isnull will threat float('nan') as NULL value.
36
47
58 class NumpyFloat32Column(NumpyColumn):
69 dtype = np.dtype(np.float32)
710 ch_type = 'Float32'
11 normalize_null_value = False
12
13 def _get_nulls_map(self, items):
14 return [x is None for x in items]
815
916
1017 class NumpyFloat64Column(NumpyColumn):
1118 dtype = np.dtype(np.float64)
1219 ch_type = 'Float64'
20 normalize_null_value = False
21
22 def _get_nulls_map(self, items):
23 return [x is None for x in items]
00 from math import log
11
2 import numpy as np
23 import pandas as pd
34
45 from ..lowcardinalitycolumn import LowCardinalityColumn
2223 **kwargs)
2324
2425 def _write_data(self, items, buf):
25 # TODO: nullable support
26
2726 # Do not write anything for empty column.
2827 # May happen while writing empty arrays.
2928 if not len(items):
3029 return
30
31 # Replace nans with defaults if not nullabe.
32 if isinstance(items, np.ndarray) and not self.nested_column.nullable:
33 nulls = pd.isnull(items)
34 items = np.where(nulls, self.nested_column.null_value, items)
3135
3236 c = pd.Categorical(items)
3337
3943 index = c.categories
4044 keys = c.codes
4145
46 if self.nested_column.nullable:
47 # First element represents NULL if column is nullable.
48 index = index.insert(0, self.nested_column.null_value)
49 keys = keys + 1
50 # Prevent null map writing. Reset nested column nullable flag.
51 self.nested_column.nullable = False
52
4253 write_binary_int64(serialization_type, buf)
4354 write_binary_int64(len(index), buf)
4455
4556 self.nested_column.write_data(index.to_numpy(items.dtype), buf)
4657 write_binary_int64(len(items), buf)
47 int_column.write_data(keys, buf)
58 int_column.write_items(keys, buf)
4859
4960 def _read_data(self, n_items, buf, nulls_map=None):
5061 if not n_items:
7182 # categorical) and drop corresponding first index
7283 # this is analog of original operation:
7384 # index = (None, ) + index[1:]
85 keys = np.array(keys, dtype='int64') # deal with possible overflow
7486 keys = keys - 1
7587 index = index[1:]
7688 return pd.Categorical.from_codes(keys, index)
1111 from .lowcardinalitycolumn import create_numpy_low_cardinality_column
1212 from ..nothingcolumn import NothingColumn
1313 from ..nullcolumn import NullColumn
14 # from .nullablecolumn import create_nullable_column
14 from ..nullablecolumn import create_nullable_column
1515 from ..simpleaggregatefunctioncolumn import (
1616 create_simple_aggregate_function_column
1717 )
5959 elif spec.startswith('Tuple'):
6060 return create_tuple_column(spec, create_column_with_options)
6161
62 # elif spec.startswith('Nullable'):
63 # return create_nullable_column(spec, create_column_with_options)
62 elif spec.startswith('Nullable'):
63 return create_nullable_column(spec, create_column_with_options)
6464
6565 elif spec.startswith('LowCardinality'):
6666 return create_numpy_low_cardinality_column(spec,
44
55
66 class NumpyStringColumn(NumpyColumn):
7 dtype = np.dtype('object')
7 null_value = ''
88
99 default_encoding = defines.STRINGS_ENCODING
1010
2222
2323
2424 class NumpyByteStringColumn(NumpyColumn):
25 null_value = b''
26
2527 def read_items(self, n_items, buf):
2628 return np.array(buf.read_strings(n_items), dtype=self.dtype)
2729
00 from .. import errors
11 from .arraycolumn import create_array_column
2 from .datecolumn import DateColumn
2 from .datecolumn import DateColumn, Date32Column
33 from .datetimecolumn import create_datetime_column
44 from .decimalcolumn import create_decimal_column
55 from . import exceptions as column_exceptions
77 from .floatcolumn import Float32Column, Float64Column
88 from .intcolumn import (
99 Int8Column, Int16Column, Int32Column, Int64Column,
10 Int128Column, UInt128Column, Int256Column, UInt256Column,
1011 UInt8Column, UInt16Column, UInt32Column, UInt64Column
1112 )
1213 from .lowcardinalitycolumn import create_low_cardinality_column
14 from .mapcolumn import create_map_column
1315 from .nothingcolumn import NothingColumn
1416 from .nullcolumn import NullColumn
1517 from .nullablecolumn import create_nullable_column
2830
2931
3032 column_by_type = {c.ch_type: c for c in [
31 DateColumn, Float32Column, Float64Column,
33 DateColumn, Date32Column, Float32Column, Float64Column,
3234 Int8Column, Int16Column, Int32Column, Int64Column,
35 Int128Column, UInt128Column, Int256Column, UInt256Column,
3336 UInt8Column, UInt16Column, UInt32Column, UInt64Column,
3437 NothingColumn, NullColumn, UUIDColumn,
3538 IntervalYearColumn, IntervalMonthColumn, IntervalWeekColumn,
7780 return create_simple_aggregate_function_column(
7881 spec, create_column_with_options)
7982
83 elif spec.startswith('Map'):
84 return create_map_column(spec, create_column_with_options)
85
8086 else:
8187 try:
8288 cls = column_by_type[spec]
00
11 from .. import defines
2 from ..util import compat
32 from .base import Column
43
54
65 class String(Column):
76 ch_type = 'String'
8 py_types = compat.string_types
7 py_types = (str, )
98 null_value = ''
109
1110 default_encoding = defines.STRINGS_ENCODING
11
22 from .base import FormatColumn
33 from .. import errors
4 from ..util import compat
54 from ..writer import MAX_UINT64
65
76
87 class UUIDColumn(FormatColumn):
98 ch_type = 'UUID'
10 py_types = compat.string_types + (UUID, )
9 py_types = (str, UUID)
1110 format = 'Q'
1211
1312 # UUID is stored by two uint64 numbers.
33 from collections import deque
44 from contextlib import contextmanager
55 from time import time
6 from urllib.parse import urlparse
67
78 from . import defines
89 from . import errors
2021 from .reader import read_binary_str
2122 from .readhelpers import read_exception
2223 from .settings.writer import write_settings
23 from .util.compat import urlparse
24 from .streams.native import BlockInputStream, BlockOutputStream
2425 from .varint import write_varint, read_varint
2526 from .writer import write_binary_str
2627
108109 :param ssl_version: see :func:`ssl.wrap_socket` docs.
109110 :param ca_certs: see :func:`ssl.wrap_socket` docs.
110111 :param ciphers: see :func:`ssl.wrap_socket` docs.
112 :param keyfile: see :func:`ssl.wrap_socket` docs.
113 :param certfile: see :func:`ssl.wrap_socket` docs.
111114 :param alt_hosts: list of alternative hosts for connection.
112115 Example: alt_hosts=host1:port1,host2:port2.
113116 :param settings_is_important: ``False`` means unknown settings will be
118121
119122 def __init__(
120123 self, host, port=None,
121 database='default', user='default', password='',
124 database=defines.DEFAULT_DATABASE,
125 user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD,
122126 client_name=defines.CLIENT_NAME,
123127 connect_timeout=defines.DBMS_DEFAULT_CONNECT_TIMEOUT_SEC,
124128 send_receive_timeout=defines.DBMS_DEFAULT_TIMEOUT_SEC,
128132 secure=False,
129133 # Secure socket parameters.
130134 verify=True, ssl_version=None, ca_certs=None, ciphers=None,
135 keyfile=None, certfile=None,
131136 alt_hosts=None,
132137 settings_is_important=False,
133138 ):
162167 ssl_options['ca_certs'] = ca_certs
163168 if ciphers is not None:
164169 ssl_options['ciphers'] = ciphers
170 if keyfile is not None:
171 ssl_options['keyfile'] = keyfile
172 if certfile is not None:
173 ssl_options['certfile'] = certfile
165174
166175 self.ssl_options = ssl_options
167176
184193
185194 self.connected = False
186195
196 self.client_trace_context = None
187197 self.server_info = None
188198 self.context = Context()
189199
190200 # Block writer/reader
191201 self.block_in = None
192202 self.block_out = None
203 self.block_in_raw = None # log blocks are always not compressed
193204
194205 super(Connection, self).__init__()
195206
261272 if 'cert_reqs' in ssl_options:
262273 context.options = ssl_options['cert_reqs']
263274
275 if 'certfile' in ssl_options:
276 keyfile = ssl_options.get('keyfile')
277 context.load_cert_chain(ssl_options['certfile'], keyfile=keyfile)
278
264279 return context
265280
266281 def _init_connection(self, host, port):
279294 self.receive_hello()
280295
281296 self.block_in = self.get_block_in_stream()
297 self.block_in_raw = BlockInputStream(self.fin, self.context)
282298 self.block_out = self.get_block_out_stream()
283299
284300 def _format_connection_error(self, e, host, port):
331347
332348 self.connected = False
333349
350 self.client_trace_context = None
334351 self.server_info = None
335352
336353 self.block_in = None
354 self.block_in_raw = None
337355 self.block_out = None
338356
339357 def disconnect(self):
414432 raise self.receive_exception()
415433
416434 else:
417 self.disconnect()
418435 message = self.unexpected_packet_message('Hello or Exception',
419436 packet_type)
437 self.disconnect()
420438 raise errors.UnexpectedPacketFromServerError(message)
421439
422440 def ping(self):
460478 elif packet_type == ServerPacketTypes.EXCEPTION:
461479 packet.exception = self.receive_exception()
462480
463 elif packet.type == ServerPacketTypes.PROGRESS:
481 elif packet_type == ServerPacketTypes.PROGRESS:
464482 packet.progress = self.receive_progress()
465483
466 elif packet.type == ServerPacketTypes.PROFILE_INFO:
484 elif packet_type == ServerPacketTypes.PROFILE_INFO:
467485 packet.profile_info = self.receive_profile_info()
468486
469487 elif packet_type == ServerPacketTypes.TOTALS:
473491 packet.block = self.receive_data()
474492
475493 elif packet_type == ServerPacketTypes.LOG:
476 block = self.receive_data()
494 block = self.receive_data(raw=True)
477495 log_block(block)
478496
479497 elif packet_type == ServerPacketTypes.END_OF_STREAM:
485503 )
486504
487505 else:
506 message = 'Unknown packet {} from server {}'.format(
507 packet_type, self.get_description()
508 )
488509 self.disconnect()
489 raise errors.UnknownPacketFromServerError(
490 'Unknown packet {} from server {}'.format(
491 packet_type, self.get_description()
492 )
493 )
510 raise errors.UnknownPacketFromServerError(message)
494511
495512 return packet
496513
500517
501518 return CompressedBlockInputStream(self.fin, self.context)
502519 else:
503 from .streams.native import BlockInputStream
504
505520 return BlockInputStream(self.fin, self.context)
506521
507522 def get_block_out_stream(self):
513528 self.fout, self.context
514529 )
515530 else:
516 from .streams.native import BlockOutputStream
517
518531 return BlockOutputStream(self.fout, self.context)
519532
520 def receive_data(self):
533 def receive_data(self, raw=False):
521534 revision = self.server_info.revision
522535
523536 if revision >= defines.DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES:
524537 read_binary_str(self.fin)
525538
526 return self.block_in.read()
539 return (self.block_in_raw if raw else self.block_in).read()
527540
528541 def receive_exception(self):
529542 return read_exception(self.fin)
563576
564577 revision = self.server_info.revision
565578 if revision >= defines.DBMS_MIN_REVISION_WITH_CLIENT_INFO:
566 client_info = ClientInfo(self.client_name)
579 client_info = ClientInfo(self.client_name, self.context)
567580 client_info.query_kind = ClientInfo.QueryKind.INITIAL_QUERY
568581
569582 client_info.write(revision, self.fout)
594607
595608 def send_external_tables(self, tables, types_check=False):
596609 for table in tables or []:
610 if not table['structure']:
611 raise ValueError(
612 'Empty table "{}" structure'.format(table['name'])
613 )
614
597615 block = RowOrientedBlock(table['structure'], table['data'],
598616 types_check=types_check)
599617 self.send_data(block, table_name=table['name'])
22 Warning, Error, DataError, DatabaseError, ProgrammingError, IntegrityError,
33 InterfaceError, InternalError, NotSupportedError, OperationalError
44 )
5 from .. import defines
56
67 apilevel = '2.0'
78
1011 paramstyle = 'pyformat'
1112
1213
13 def connect(dsn=None, user=None, password=None, host=None, port=None,
14 database=None, **kwargs):
14 def connect(dsn=None, host=None,
15 user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD,
16 port=defines.DEFAULT_PORT, database=defines.DEFAULT_DATABASE,
17 **kwargs):
1518 """
1619 Create a new database connection.
1720
00 from ..client import Client
1 from .. import defines
12 from .cursor import Cursor
23 from .errors import InterfaceError
34
1213 See parameters description in
1314 :data:`~clickhouse_driver.connection.Connection`.
1415 """
15 def __init__(self, dsn=None, user=None, password=None, host=None,
16 port=None, database=None, **kwargs):
16 def __init__(self, dsn=None, host=None,
17 user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD,
18 port=defines.DEFAULT_PORT, database=defines.DEFAULT_DATABASE,
19 **kwargs):
1720 self.cursors = []
1821
1922 self.dsn = dsn
8790 self._hosts = client.connection.hosts
8891 else:
8992 client.connection.hosts = self._hosts
90 cursor = Cursor(client)
93 cursor = Cursor(client, self)
9194 self.cursors.append(cursor)
9295 return cursor
2222
2323 _states = States()
2424
25 def __init__(self, client):
25 def __init__(self, client, connection):
2626 self._client = client
27 self._connection = connection
2728 self._reset_state()
2829
2930 self.arraysize = 1
8485 """
8586 self._client.disconnect()
8687 self._state = self._states.CURSOR_CLOSED
88
89 try:
90 # cursor can be already closed
91 self._connection.cursors.remove(self)
92 except ValueError:
93 pass
8794
8895 def execute(self, operation, parameters=None):
8996 """
0 from ..util.compat import StandardError
10
21
3 class Warning(StandardError):
2 class Warning(Exception):
43 pass
54
65
7 class Error(StandardError):
6 class Error(Exception):
87 pass
98
109
0
1 DEFAULT_DATABASE = 'default'
2 DEFAULT_USER = 'default'
3 DEFAULT_PASSWORD = ''
04
15 DEFAULT_PORT = 9000
26 DEFAULT_SECURE_PORT = 9440
1519 DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO = 54420
1620 DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS = 54429
1721 DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET = 54441
22 DBMS_MIN_REVISION_WITH_OPENTELEMETRY = 54442
1823
1924 # Timeouts
2025 DBMS_DEFAULT_CONNECT_TIMEOUT_SEC = 10
3035 CLIENT_VERSION_MAJOR = 20
3136 CLIENT_VERSION_MINOR = 10
3237 CLIENT_VERSION_PATCH = 2
33 CLIENT_REVISION = 54441
38 CLIENT_REVISION = 54442
3439
3540 BUFFER_SIZE = 1048576
3641
0
1 from .util import compat
20
31
42 class ErrorCodes(object):
375373 ILLEGAL_PROJECTION_MANIPULATOR = 2002
376374
377375
378 if compat.PY3:
379 class Error(Exception):
380 code = None
381
382 def __init__(self, message=None):
383 self.message = message
384 super().__init__(message)
385
386 def __str__(self):
387 message = ' ' + self.message if self.message is not None else ''
388 return 'Code: {}.{}'.format(self.code, message)
389
390 class ServerException(Error):
391 def __init__(self, message, code=None, nested=None):
392 self.message = message
393 self.code = code
394 self.nested = nested
395 super().__init__(message)
396
397 def __str__(self):
398 nested = '\nNested: {}'.format(self.nested) if self.nested else ''
399 return 'Code: {}.{}\n{}'.format(self.code, nested, self.message)
400
401 else:
402 class Error(Exception):
403 code = None
404
405 def __init__(self, message=None):
406 self.message = message
407 super(Error, self).__init__(message)
408
409 def __unicode__(self):
410 message = ' ' + self.message if self.message is not None else ''
411 return 'Code: {}.{}'.format(self.code, message)
412
413 def __str__(self):
414 return compat.text_type(self).encode('utf-8')
415
416 class ServerException(Error):
417 def __init__(self, message, code=None, nested=None):
418 self.message = message
419 self.code = code
420 self.nested = nested
421 super(ServerException, self).__init__(message)
422
423 def __unicode__(self):
424 nested = '\nNested: {}'.format(self.nested) if self.nested else ''
425 return 'Code: {}.{}\n{}'.format(self.code, nested, self.message)
426
427 def __str__(self):
428 return compat.text_type(self).encode('utf-8')
376 class Error(Exception):
377 code = None
378
379 def __init__(self, message=None):
380 self.message = message
381 super(Error, self).__init__(message)
382
383 def __str__(self):
384 message = ' ' + self.message if self.message is not None else ''
385 return 'Code: {}.{}'.format(self.code, message)
386
387
388 class ServerException(Error):
389 def __init__(self, message, code=None, nested=None):
390 self.message = message
391 self.code = code
392 self.nested = nested
393 super(ServerException, self).__init__(message)
394
395 def __str__(self):
396 nested = '\nNested: {}'.format(self.nested) if self.nested else ''
397 return 'Code: {}.{}\n{}'.format(self.code, nested, self.message)
429398
430399
431400 class LogicalError(Error):
1212
1313 # create chunk generator for every column
1414 chunked = [
15 iter(np.array_split(c, range(0, len(c), n)) if len(c) > n else [c])
15 iter(np.array_split(c, len(c) // n) if len(c) > n else [c])
1616 for c in columns
1717 ]
1818
7070 def __iter__(self):
7171 return self
7272
73 def next(self):
73 def __next__(self):
7474 while True:
7575 packet = next(self.packet_generator)
7676 progress_packet = getattr(packet, 'progress', None)
8181 )
8282 else:
8383 self.store(packet)
84
85 # For Python 3.
86 __next__ = next
8784
8885 def get_result(self):
8986 # Read all progress packets.
110107 def __iter__(self):
111108 return self
112109
113 def next(self):
110 def __next__(self):
114111 packet = next(self.packet_generator)
115112 block = getattr(packet, 'block', None)
116113 if block is None:
123120 return rv
124121 else:
125122 return block.get_rows()
126
127 # For Python 3.
128 __next__ = next
0
1 class OpenTelemetryTraceContext(object):
2 traceparent_tpl = 'xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx'
3 translation = str.maketrans('1234567890abcdef', 'xxxxxxxxxxxxxxxx')
4
5 def __init__(self, traceparent, tracestate):
6 # xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx
7 # ^ ^ ^ ^
8 # version trace_id span_id flags
9
10 self.trace_id = None # UUID
11 self.span_id = None # UInt64
12 self.tracestate = tracestate # String
13 self.trace_flags = None # UInt8
14
15 if traceparent is not None:
16 self.parse_traceparent(traceparent)
17
18 super(OpenTelemetryTraceContext, self).__init__()
19
20 def parse_traceparent(self, traceparent):
21 traceparent = traceparent.lower()
22
23 if len(traceparent) != len(self.traceparent_tpl):
24 raise ValueError('unexpected length {}, expected {}'.format(
25 len(traceparent), len(self.traceparent_tpl)
26 ))
27
28 if traceparent.translate(self.translation) != self.traceparent_tpl:
29 raise ValueError(
30 'Malformed traceparant header: {}'.format(traceparent)
31 )
32
33 parts = traceparent.split('-')
34 version = int(parts[0], 16)
35 if version != 0:
36 raise ValueError(
37 'unexpected version {}, expected 00'.format(parts[0])
38 )
39
40 self.trace_id = (int(parts[1][16:], 16) << 64) + int(parts[1][:16], 16)
41 self.span_id = int(parts[2], 16)
42 self.trace_flags = int(parts[3], 16)
7272 def __iter__(self):
7373 return self
7474
75 def next(self):
75 def __next__(self):
7676 while True:
7777 packet = next(self.packet_generator)
7878 progress_packet = getattr(packet, 'progress', None)
8383 )
8484 else:
8585 self.store(packet)
86
87 # For Python 3.
88 __next__ = next
8986
9087 def get_result(self):
9188 # Read all progress packets.
112109 def __iter__(self):
113110 return self
114111
115 def next(self):
112 def __next__(self):
116113 packet = next(self.packet_generator)
117114 block = getattr(packet, 'block', None)
118115 if block is None:
125122 return rv
126123 else:
127124 return block.get_rows()
128
129 # For Python 3.
130 __next__ = next
131125
132126
133127 class QueryInfo(object):
0 from ..util.compat import asbool
0 from ..util.helpers import asbool
11 from ..varint import write_varint
22 from ..writer import write_binary_str
33
+0
-42
clickhouse_driver/util/compat.py less more
0 import types
1 import sys
2
3
4 PY2 = sys.version_info[0] == 2
5 PY3 = sys.version_info[0] == 3
6
7
8 if PY3:
9 from urllib.parse import parse_qs, urlparse, unquote # noqa: F401
10
11 string_types = str,
12 integer_types = int,
13 class_types = type,
14 text_type = str
15 binary_type = bytes
16 range = range
17 StandardError = Exception
18
19 else:
20 from urlparse import parse_qs, urlparse, unquote # noqa: F401
21
22 string_types = basestring, # noqa: F821
23 integer_types = (int, long) # noqa: F821
24 class_types = (type, types.ClassType)
25 text_type = unicode # noqa: F821
26 binary_type = str
27 range = xrange # noqa: F821
28 StandardError = StandardError
29
30
31 # from paste.deploy.converters
32 def asbool(obj):
33 if isinstance(obj, string_types):
34 obj = obj.strip().lower()
35 if obj in ['true', 'yes', 'on', 'y', 't', '1']:
36 return True
37 elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
38 return False
39 else:
40 raise ValueError('String is not true/false: %r' % obj)
41 return bool(obj)
00 from datetime import date, datetime
11 from enum import Enum
22 from uuid import UUID
3
4 from .compat import text_type, string_types
53
64
75 escape_chars_map = {
2826 elif isinstance(item, date):
2927 return "'%s'" % item.strftime('%Y-%m-%d')
3028
31 elif isinstance(item, string_types):
29 elif isinstance(item, str):
3230 return "'%s'" % ''.join(escape_chars_map.get(c, c) for c in item)
3331
3432 elif isinstance(item, list):
35 return "[%s]" % ', '.join(text_type(escape_param(x)) for x in item)
33 return "[%s]" % ', '.join(str(escape_param(x)) for x in item)
3634
3735 elif isinstance(item, tuple):
38 return "(%s)" % ', '.join(text_type(escape_param(x)) for x in item)
36 return "(%s)" % ', '.join(str(escape_param(x)) for x in item)
3937
4038 elif isinstance(item, Enum):
4139 return escape_param(item.value)
4141 if not any(item):
4242 break
4343 yield item
44
45
46 # from paste.deploy.converters
47 def asbool(obj):
48 if isinstance(obj, str):
49 obj = obj.strip().lower()
50 if obj in ['true', 'yes', 'on', 'y', 't', '1']:
51 return True
52 elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
53 return False
54 else:
55 raise ValueError('String is not true/false: %r' % obj)
56 return bool(obj)
00 import struct
11
22 from .varint import write_varint
3 from .util import compat
43
54
65 MAX_UINT64 = (1 << 64) - 1
76 MAX_INT64 = (1 << 63) - 1
87
98
10 if compat.PY3:
11 def _byte(b):
12 return bytes((b, ))
13 else:
14 _byte = chr
9 def _byte(b):
10 return bytes((b, ))
1511
1612
1713 def write_binary_str(text, buf):
44
55 Clickhouse-driver is designed to communicate with ClickHouse server from Python over native protocol.
66
7 ClickHouse server provider two protocols for communication: HTTP protocol and Native (TCP) protocol.
7 ClickHouse server provides two protocols for communication:
8
9 * HTTP protocol (port 8123 by default);
10 * Native (TCP) protocol (port 9000 by default).
811
912 Each protocol has own advantages and disadvantages. Here we focus on advantages of native protocol:
1013
1518 Gzip compression is used in HTTP protocol.
1619 * Query profile info is available over native protocol. We can read rows before limit metric for example.
1720
21 Once again: clickhouse-driver uses native protocol (port 9000).
1822
1923 There is an asynchronous wrapper for clickhouse-driver: aioch. It's available `here <https://github.com/mymarilyn/aioch>`_.
2024
4953 .. toctree::
5054 :maxdepth: 2
5155
56 development
5257 changelog
5358 license
5459 contributing
0 .. _development:
1
2 Development
3 ===========
4
5 Test configuration
6 ------------------
7
8 In ``setup.cfg`` you can find ClickHouse server port, credentials, logging
9 level and another options than can be tuned during local testing.
10
11 Running tests locally
12 ---------------------
13
14 Install desired Python version with system package manager/pyenv/another manager.
15
16 ClickHouse on host machine
17 ^^^^^^^^^^^^^^^^^^^^^^^^^^
18
19 Install desired versions of ``clickhouse-server`` and ``clickhouse-client`` on
20 your machine.
21
22 Run tests:
23
24 .. code-block:: bash
25
26 python setup.py test
27
28 ClickHouse in docker
29 ^^^^^^^^^^^^^^^^^^^^
30
31 Create container desired version of ``clickhouse-server``:
32
33 .. code-block:: bash
34
35 docker run --rm -e "TZ=Europe/Moscow" -p 127.0.0.1:9000:9000 --name test-clickhouse-server yandex/clickhouse-server:$VERSION
36
37 Create container with the same version of ``clickhouse-client``:
38
39 .. code-block:: bash
40
41 docker run --rm --entrypoint "/bin/sh" --name test-clickhouse-client --link test-clickhouse-server:clickhouse-server yandex/clickhouse-client:$VERSION -c 'while :; do sleep 1; done'
42
43 Create ``clickhouse-client`` script on your host machine:
44
45 .. code-block:: bash
46
47 echo -e '#!/bin/bash\n\ndocker exec -e "`env | grep ^TZ=`" test-clickhouse-client clickhouse-client "$@"' | sudo tee /usr/local/bin/clickhouse-client > /dev/null
48 sudo chmod +x /usr/local/bin/clickhouse-client
49
50 After it container ``test-clickhouse-client`` will communicate with
51 ``test-clickhouse-server`` transparently from host machine.
52
53 Set ``host=clickhouse-server`` in ``setup.cfg``.
54
55 Add entry in hosts file:
56
57 .. code-block:: bash
58
59 echo '127.0.0.1 clickhouse-server' | sudo tee -a /etc/hosts > /dev/null
60
61 Set ``TZ=UTC`` and run tests:
62
63 .. code-block:: bash
64
65 export TZ=UTC
66 python setup.py test
4646 >>> settings = {'max_threads': 2}
4747 >>> client = Client('localhost', settings=settings)
4848
49 Each setting can be overridden in an `execute` statement:
49 Each setting can be overridden in an ``execute``, ``execute_with_progress`` and
50 ``execute_iter`` statement:
5051
5152 .. code-block:: python
5253
6364 Native protocol supports two types of compression: `LZ4 <http://www.lz4.org/>`_ and
6465 `ZSTD <https://facebook.github.io/zstd/>`_. When compression is enabled compressed data
6566 should be hashed using `CityHash algorithm <https://github.com/google/cityhash>`_.
66 Additional packages should be install in order by enable compression suport, see :ref:`installation-pypi`.
67 Additional packages should be installed in order by enable compression support, see :ref:`installation-pypi`.
6768 Enabled client-side compression can save network traffic.
6869
6970 Client with compression support can be constructed as follows:
350351 >>> print(cursor.fetchall())
351352
352353
353 NumPy arrays support
354 NumPy/Pandas support
354355 --------------------
355356
356357 *New in version 0.1.6.*
375376 * Date/DateTime('timezone')/DateTime64('timezone')
376377 * String/FixedString(N)
377378 * LowCardinality(T)
378
379 NumPy arrays are not used when reading nullable columns and columns of
380 unsupported types.
379 * Nullable(T)
381380
382381 Direct loading into NumPy arrays increases performance and lowers memory
383382 requirements on large amounts of rows.
422421 ... )
423422 >>> client.insert_dataframe('INSERT INTO test VALUES', df)
424423 >>> 10000
424
425 Starting from version 0.2.2 nullable columns are also supported. Keep in mind
426 that nullable columns have ``object`` dtype. For convenience ``np.nan`` and
427 ``None`` is supported as ``NULL`` values for inserting. But only ``None`` is
428 returned after selecting for ``NULL`` values.
429
430 .. code-block:: python
431
432 >>> client = Client('localhost', settings={'use_numpy': True})
433 >>> client.execute(
434 ... 'CREATE TABLE test ('
435 ... 'a Nullable(Int64),
436 ... 'b Nullable(Float64),
437 ... 'c Nullable(String)'
438 ... ') Engine = Memory'
439 ... )
440 >>> []
441 >>> df = pd.DataFrame({
442 ... 'a': [1, None, None],
443 ... 'b': [1.0, None, np.nan],
444 ... 'c': ['a', None, np.nan],
445 ... }, dtype=object)
446 >>> client.insert_dataframe('INSERT INTO test VALUES', df)
447 3
448 >>> client.query_dataframe('SELECT * FROM test')
449 a b c
450 0 1 1 a
451 1 None None None
452 2 None NaN None
453
454 It's important to specify `dtype` during dataframe creation:
455
456 .. code-block:: python
457
458 >>> bad_df = pd.DataFrame({
459 ... 'a': [1, None, None],
460 ... 'b': [1.0, None, np.nan],
461 ... 'c': ['a', None, np.nan],
462 ... })
463 >>> bad_df
464 a b c
465 0 1.0 1.0 a
466 1 NaN NaN None
467 2 NaN NaN NaN
468 >>> good_df = pd.DataFrame({
469 ... 'a': [1, None, None],
470 ... 'b': [1.0, None, np.nan],
471 ... 'c': ['a', None, np.nan],
472 ... }, dtype=object)
473 >>> good_df
474 a b c
475 0 1 1 a
476 1 None None None
477 2 None NaN NaN
478
479 As you can see float column ``b`` in ``bad_df`` has two ``NaN`` values.
480 But ``NaN`` and ``None`` is not the same for float point numbers.
481 ``NaN`` is ``float('nan')`` where ``None`` is representing ``NULL``.
482
483 Automatic disposal
484 ------------------
485
486 *New in version 0.2.2.*
487
488 Each Client instance can be used as a context manager:
489
490 .. code-block:: python
491
492 >>> with Client('localhost') as client:
493 >>> client.execute('SELECT 1')
494
495
496 Upon exit, any established connection to the ClickHouse server will be closed
497 automatically.
55 Python Version
66 --------------
77
8 Clickhouse-driver supports Python 3.4 and newer, Python 2.7, and PyPy.
8 Clickhouse-driver supports Python 3.4 and newer and PyPy.
99
1010 Build Dependencies
1111 ------------------
2020
2121 By default there are wheels for Linux, Mac OS X and Windows.
2222
23 Packages for Linux and Mac OS X are available for python: 2.7, 3.4 -- 3.9.
23 Packages for Linux and Mac OS X are available for python: 3.4 -- 3.9.
2424
25 Packages for Windows are available for python: 2.7, 3.5 -- 3.9.
25 Packages for Windows are available for python: 3.5 -- 3.9.
2626
2727 Dependencies
2828 ------------
5454 ... {'date': date.today(), 'a': 1, 'b': 2}
5555 ... )
5656 [('2018-10-21', 3)]
57
58 Percent symbols in inlined constants should be doubled if you mix constants
59 with ``%`` symbol and ``%(x)s`` parameters.
60
61 .. code-block:: python
62
63 >>> client.execute(
64 ... "SELECT 'test' like '%%es%%', %(x)s",
65 ... {'x': 1}
66 ... )
5767
5868 Customisation ``SELECT`` output with ``FORMAT`` clause is not supported.
5969
66 The following ClickHouse types are supported by clickhouse-driver:
77
88
9 [U]Int8/16/32/64
10 ----------------
9 [U]Int8/16/32/64/128/256
10 ------------------------
1111
1212 INSERT types: :class:`int`, :class:`long`.
1313
2222 SELECT type: :class:`float`.
2323
2424
25 Date
26 ----
25 Date/Date32
26 -----------
27
28 *Date32 support is new in version 0.2.2.*
2729
2830 INSERT types: :class:`~datetime.date`, :class:`~datetime.datetime`.
2931
3032 SELECT type: :class:`~datetime.date`.
3133
32 Only values after the beginning of the epoch (1970-01-01) are supported.
3334
3435 DateTime('timezone')/DateTime64('timezone')
3536 -------------------------------------------
4950 You can cast DateTime column to integers if you are facing performance issues when selecting large amount of rows.
5051
5152 Due to Python's current limitations minimal DateTime64 resolution is one microsecond.
52
53 Only values after the beginning of the epoch (1970-01-01) are supported.
5453
5554
5655 String/FixedString(N)
126125 >>> client.execute('SELECT * FROM test')
127126 [('foo',), ('bar',), ('foo',)]
128127
129 For Python 2.7 `enum34 <https://pypi.org/project/enum34>`_ package is used.
130
131128 Currently clickhouse-driver can't handle empty enum value due to Python's `Enum` mechanics.
132129 Enum member name must be not empty. See `issue`_ and `workaround`_.
133130
188185
189186 SELECT type: :class:`~decimal.Decimal`.
190187
188 Supported subtypes:
189
190 * Decimal(P, S).
191 * Decimal32(S).
192 * Decimal64(S).
193 * Decimal128(S).
194 * Decimal256(S). *New in version 0.2.1.*
191195
192196 IPv4/IPv6
193197 ---------
237241 [(IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), (IPv6Address('12ff::1'),), (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),)]
238242 >>>
239243
240 For Python 2.7 `ipaddress <https://pypi.org/project/ipaddress>`_ package is used.
241
242244
243245 LowCardinality(T)
244246 -----------------
323325 client.execute('INSERT INTO test_nested VALUES', [
324326 (['a', 'b', 'c'], [100, 200, 300]),
325327 ])
328
329 Map(key, value)
330 ------------------
331
332 *New in version 0.2.1.*
333
334 INSERT types: :class:`dict`.
335
336 SELECT type: :class:`dict`.
44 user=default
55 password=
66 compression=lz4,lz4hc,zstd
7 client=clickhouse-client
78
89 [log]
910 level=ERROR
1212 USE_CYTHON = True
1313
1414 USE_NUMPY = bool(os.getenv('USE_NUMPY', False))
15 CYTHON_TRACE = bool(os.getenv('CYTHON_TRACE', False))
1516
1617
1718 here = os.path.abspath(os.path.dirname(__file__))
4647 ['clickhouse_driver/bufferedwriter' + ext]
4748 ),
4849 Extension(
50 'clickhouse_driver.columns.largeint',
51 ['clickhouse_driver/columns/largeint' + ext]
52 ),
53 Extension(
4954 'clickhouse_driver.varint',
5055 ['clickhouse_driver/varint' + ext]
5156 )
5257 ]
5358
5459 if USE_CYTHON:
55 extensions = cythonize(
56 extensions, compiler_directives={'language_level': '3'}
57 )
60 compiler_directives = {'language_level': '3'}
61 if CYTHON_TRACE:
62 compiler_directives['linetrace'] = True
63
64 extensions = cythonize(extensions, compiler_directives=compiler_directives)
5865
5966 tests_require = [
6067 'nose',
61 'mock',
68 'parameterized',
6269 'freezegun',
63 'lz4<=3.0.1',
70 'lz4<=3.0.1; implementation_name=="pypy"',
71 'lz4; implementation_name!="pypy"',
6472 'zstd',
6573 'clickhouse-cityhash>=1.0.2.1'
6674 ]
100108
101109
102110 'Programming Language :: SQL',
103 'Programming Language :: Python :: 2.7',
104111 'Programming Language :: Python :: 3',
105112 'Programming Language :: Python :: 3.4',
106113 'Programming Language :: Python :: 3.5',
124131 'Documentation': 'https://clickhouse-driver.readthedocs.io',
125132 },
126133 packages=find_packages('.', exclude=['tests*']),
127 python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
134 python_requires='>=3.4.*, <4',
128135 install_requires=[
129136 'pytz',
130 'enum34; python_version<"3.4"',
131 'ipaddress; python_version<"3.4"',
132 'tzlocal<3.0'
137 'tzlocal'
133138 ],
134139 ext_modules=extensions,
135140 extras_require={
136 'lz4': ['lz4<=3.0.1', 'clickhouse-cityhash>=1.0.2.1'],
141 'lz4': [
142 'lz4<=3.0.1; implementation_name=="pypy"',
143 'lz4; implementation_name!="pypy"',
144 'clickhouse-cityhash>=1.0.2.1'
145 ],
137146 'zstd': ['zstd', 'clickhouse-cityhash>=1.0.2.1'],
138147 'numpy': ['numpy>=1.12.0', 'pandas>=0.24.0']
139148 },
11
22 from tests.testcase import BaseTestCase
33 from clickhouse_driver import errors
4 from tests.util import require_server_version
45
56
67 class ArrayTestCase(BaseTestCase):
104105 inserted = self.client.execute(query)
105106 self.assertEqual(inserted, data)
106107
108 def test_multidimensional(self):
109 columns = "a Array(Array(Array(Nullable(String))))"
110 data = [([[['str1_1', 'str1_2', None], [None]],
111 [['str1_3', 'str1_4', None], [None]]], ),
112 ([[['str2_1', 'str2_2', None], [None]]], ),
113 ([[['str3_1', 'str3_2', None], [None]]],)]
114 with self.create_table(columns):
115 self.client.execute(
116 'INSERT INTO test (a) VALUES', data
117 )
118
119 query = 'SELECT * FROM test'
120 inserted = self.emit_cli(query)
121 self.assertEqual(
122 inserted,
123 '[[[\'str1_1\',\'str1_2\',NULL],[NULL]],'
124 '[[\'str1_3\',\'str1_4\',NULL],[NULL]]]\n'
125 '[[[\'str2_1\',\'str2_2\',NULL],[NULL]]]\n'
126 '[[[\'str3_1\',\'str3_2\',NULL],[NULL]]]\n'
127 )
128
129 inserted = self.client.execute(query)
130 self.assertEqual(inserted, data)
131
107132 def test_empty_nested(self):
108133 columns = "a Array(Array(Array(Int32))), b Array(Array(Array(Int32)))"
109134 data = [
219244
220245 inserted = self.client.execute(query)
221246 self.assertEqual(inserted, data)
247
248 @require_server_version(19, 16, 13)
249 def test_tuple_array(self):
250 columns = 'a Array(Tuple(Int32))'
251 data = [([], )]
252
253 with self.create_table(columns):
254 self.client.execute(
255 'INSERT INTO test (a) VALUES', data
256 )
257
258 query = 'SELECT * FROM test'
259 inserted = self.emit_cli(query)
260 self.assertEqual(
261 inserted, "[]\n"
262 )
263
264 inserted = self.client.execute(query)
265 self.assertEqual(inserted, data)
00 import os
11 from datetime import date, datetime
2 from unittest.mock import patch
23
34 from freezegun import freeze_time
4 from mock import patch
55
66 from tests.testcase import BaseTestCase
77
3333 inserted = self.emit_cli(query)
3434 self.assertEqual(inserted, '2015-06-06\n')
3535
36 def test_wrong_datetime_insert(self):
36 def test_wrong_date_insert(self):
3737 with self.create_table('a Date'):
38 wrongTime = date(5555, 1, 1)
39 nullTime = date(1, 1, 1)
40 self.client.execute(
41 'INSERT INTO test (a) VALUES', [(wrongTime, ), (nullTime, )]
42 )
38 data = [
39 (date(5555, 1, 1), ),
40 (date(1, 1, 1), ),
41 (date(2149, 6, 7), )
42 ]
43 self.client.execute('INSERT INTO test (a) VALUES', data)
4344 query = 'SELECT * FROM test'
4445 inserted = self.emit_cli(query)
4546 expected = (
46 '1970-01-01\n1970-01-01\n' if self.server_version > (20, 7, 2)
47 else '0000-00-00\n0000-00-00\n'
47 3*'1970-01-01\n' if self.server_version > (20, 7, 2)
48 else 3*'0000-00-00\n'
4849 )
4950 self.assertEqual(inserted, expected)
51
52 def test_boundaries(self):
53 extended_date = self.server_version > (21, 4)
54
55 with self.create_table('a Date'):
56 data = [
57 (date(1970, 1, 1), ),
58 ((date(2149, 6, 6) if extended_date else date(2106, 2, 7)), )
59 ]
60 self.client.execute('INSERT INTO test (a) VALUES', data)
61
62 query = 'SELECT * FROM test'
63 inserted = self.emit_cli(query)
64 if extended_date:
65 expected = '1970-01-01\n2149-06-06\n'
66 else:
67 if self.server_version > (20, 7, 2):
68 expected = '1970-01-01\n2106-02-07\n'
69 else:
70 expected = '0000-00-00\n2106-02-07\n'
71 self.assertEqual(inserted, expected)
72
73 inserted = self.client.execute(query)
74 self.assertEqual(inserted, data)
75
76
77 class Date32TestCase(BaseTestCase):
78 required_server_version = (21, 9)
79
80 def test_wrong_date_insert(self):
81 with self.create_table('a Date32'):
82 data = [
83 (date(5555, 1, 1), ),
84 (date(1, 1, 1), ),
85 (date(2284, 1, 1), )
86 ]
87 self.client.execute('INSERT INTO test (a) VALUES', data)
88 query = 'SELECT * FROM test'
89 inserted = self.emit_cli(query)
90 self.assertEqual(inserted, '1970-01-01\n1970-01-01\n1970-01-01\n')
91
92 def test_boundaries(self):
93 with self.create_table('a Date32'):
94 data = [(date(1925, 1, 1), ), (date(2283, 11, 11), )]
95 self.client.execute('INSERT INTO test (a) VALUES', data)
96
97 query = 'SELECT * FROM test'
98 inserted = self.emit_cli(query)
99 self.assertEqual(inserted, '1925-01-01\n2283-11-11\n')
100
101 inserted = self.client.execute(query)
102 self.assertEqual(inserted, data)
11 from datetime import date, datetime
22 import os
33 from time import tzset
4
5 from mock import patch
4 from unittest.mock import patch
5
66 from pytz import timezone, utc, UnknownTimeZoneError
77 import tzlocal
88
133133 query = 'SELECT toUInt32(a) FROM test ORDER BY a'
134134 inserted = self.emit_cli(query)
135135 self.assertEqual(inserted, '0\n1\n1500000000\n4294967295\n')
136
137 @require_server_version(21, 4)
138 def test_insert_datetime64_extended_range(self):
139 with self.create_table('a DateTime64(0)'):
140 self.client.execute(
141 'INSERT INTO test (a) VALUES',
142 [(-1420077600, ), (-1420077599, ),
143 (0, ), (1, ),
144 (9877248000, )]
145 )
146
147 query = 'SELECT toInt64(a), a FROM test'
148 inserted = self.emit_cli(query)
149 self.assertEqual(
150 inserted,
151 '-1420077600\t1925-01-01 00:00:00\n'
152 '-1420077599\t1925-01-01 00:00:01\n'
153 '0\t1970-01-01 03:00:00\n'
154 '1\t1970-01-01 03:00:01\n'
155 '9877248000\t2282-12-31 03:00:00\n'
156 )
157 query = 'SELECT a FROM test ORDER BY a'
158 inserted = self.client.execute(query)
159 self.assertEqual(
160 inserted, [
161 (datetime(1925, 1, 1, 0, 0, 0), ),
162 (datetime(1925, 1, 1, 0, 0, 1), ),
163 (datetime(1970, 1, 1, 3, 0, 0), ),
164 (datetime(1970, 1, 1, 3, 0, 1), ),
165 (datetime(2282, 12, 31, 3, 0, 0), )
166 ]
167 )
168
169 @require_server_version(21, 4)
170 def test_insert_datetime64_extended_range_pure_ints_out_of_range(self):
171 with self.create_table('a DateTime64(0)'):
172 self.client.execute(
173 'INSERT INTO test (a) VALUES',
174 [(0, ), (1, ), (-2**63, ), (2**63-1, )]
175 )
176
177 query = 'SELECT toInt64(a) FROM test ORDER BY a'
178 inserted = self.emit_cli(query)
179 self.assertEqual(
180 inserted,
181 '-9223372036854775808\n0\n1\n9223372036854775807\n'
182 )
136183
137184
138185 class DateTimeTimezonesTestCase(BaseDateTimeTestCase):
77 class DecimalTestCase(BaseTestCase):
88 required_server_version = (18, 12, 13)
99 stable_support_version = (18, 14, 9)
10 trailing_zeros_version = (21, 9)
1011
1112 def client_kwargs(self, version):
1213 if version < self.stable_support_version:
2425 )
2526 query = 'SELECT * FROM test'
2627 inserted = self.emit_cli(query)
27 self.assertEqual(inserted, '300.42000\n300.42000\n-300.00000\n')
28 if self.server_version < self.trailing_zeros_version:
29 expected = '300.42000\n300.42000\n-300.00000\n'
30 else:
31 expected = '300.42\n300.42\n-300\n'
32 self.assertEqual(inserted, expected)
2833 inserted = self.client.execute(query)
2934 self.assertEqual(inserted, [
3035 (Decimal('300.42'), ),
141146
142147 query = 'SELECT * FROM test'
143148 inserted = self.emit_cli(query)
144 self.assertEqual(inserted, '300.420\n\\N\n')
149 if self.server_version < self.trailing_zeros_version:
150 expected = '300.420\n\\N\n'
151 else:
152 expected = '300.42\n\\N\n'
153 self.assertEqual(inserted, expected)
145154
146155 inserted = self.client.execute(query)
147156 self.assertEqual(inserted, [(Decimal('300.42'), ), (None, ), ])
176185 )
177186
178187 self.assertIn('Column a', str(e.exception))
188
189 def test_preserve_precision(self):
190 data = [(1.66, ), (1.15, )]
191
192 with self.create_table('a Decimal(18, 2)'):
193 self.client.execute('INSERT INTO test (a) VALUES', data)
194 query = 'SELECT * FROM test'
195 inserted = self.emit_cli(query)
196 self.assertEqual(inserted, '1.66\n1.15\n')
197 inserted = self.client.execute(query)
198 self.assertEqual(inserted, [
199 (Decimal('1.66'), ),
200 (Decimal('1.15'), )
201 ])
202
203 def test_precision_one_sign_after_point(self):
204 data = [(1.6, ), (1.0, ), (12312.0, ), (999999.6, )]
205
206 with self.create_table('a Decimal(8, 1)'):
207 self.client.execute('INSERT INTO test (a) VALUES', data)
208 query = 'SELECT * FROM test'
209 inserted = self.emit_cli(query)
210 if self.server_version < self.trailing_zeros_version:
211 expected = '1.6\n1.0\n12312.0\n999999.6\n'
212 else:
213 expected = '1.6\n1\n12312\n999999.6\n'
214 self.assertEqual(inserted, expected)
215 inserted = self.client.execute(query)
216 self.assertEqual(inserted, [
217 (Decimal('1.6'),),
218 (Decimal('1.0'),),
219 (Decimal('12312.0'),),
220 (Decimal('999999.6'),)
221 ])
222
223
224 class Decimal256TestCase(BaseTestCase):
225 required_server_version = (18, 12, 13)
226
227 def cli_client_kwargs(self):
228 return {'allow_experimental_bigint_types': 1}
229
230 @require_server_version(20, 9, 2)
231 def test_decimal256(self):
232 data = [
233 (1.66, ),
234 (1.15, ),
235 # 300.42 + (1 << 200)
236 (Decimal('1606938044258990275541962092341162602522202993782792835301676.42'), ), # noqa: E501
237 (Decimal('-1606938044258990275541962092341162602522202993782792835301676.42'), ) # noqa: E501
238 ]
239
240 with self.create_table('a Decimal256(2)'):
241 self.client.execute('INSERT INTO test (a) VALUES', data)
242 query = 'SELECT * FROM test'
243 inserted = self.emit_cli(query)
244 self.assertEqual(
245 inserted,
246 '1.66\n'
247 '1.15\n'
248 '1606938044258990275541962092341162602522202993782792835301676.42\n' # noqa: E501
249 '-1606938044258990275541962092341162602522202993782792835301676.42\n' # noqa: E501
250 )
251 inserted = self.client.execute(query)
252 self.assertEqual(inserted, [
253 (Decimal('1.66'), ),
254 (Decimal('1.15'), ),
255 (Decimal('1606938044258990275541962092341162602522202993782792835301676.42'), ), # noqa: E501
256 (Decimal('-1606938044258990275541962092341162602522202993782792835301676.42'), ) # noqa: E501
257 ])
22
33 from tests.testcase import BaseTestCase
44 from clickhouse_driver import errors
5 from clickhouse_driver.util.compat import text_type
65
76
87 class FixedStringTestCase(BaseTestCase):
117116
118117 inserted = self.client.execute(query, settings=settings)
119118 self.assertEqual(inserted, data)
120 self.assertIsInstance(inserted[0][0], text_type)
121 self.assertIsInstance(inserted[1][0], text_type)
119 self.assertIsInstance(inserted[0][0], str)
120 self.assertIsInstance(inserted[1][0], str)
122121
123122 def test_not_supported_types(self):
124123 datas = [
00 from tests.testcase import BaseTestCase
11 from clickhouse_driver import errors
2 from tests.util import require_server_version
23
34
45 class IntTestCase(BaseTestCase):
125126
126127 inserted = self.client.execute(query)
127128 self.assertEqual(inserted, data)
129
130
131 class BigIntTestCase(BaseTestCase):
132 required_server_version = (20, 8, 2)
133
134 def cli_client_kwargs(self):
135 return {'allow_experimental_bigint_types': 1}
136
137 def test_int128(self):
138 with self.create_table('a Int128'):
139 data = [
140 (-170141183460469231731687303715884105728, ),
141 (-111111111111111111111111111111111111111, ),
142 (123, ),
143 (111111111111111111111111111111111111111, ),
144 (170141183460469231731687303715884105727, )
145 ]
146 self.client.execute('INSERT INTO test (a) VALUES', data)
147
148 query = 'SELECT * FROM test'
149 inserted = self.emit_cli(query)
150 self.assertEqual(
151 inserted,
152 '-170141183460469231731687303715884105728\n'
153 '-111111111111111111111111111111111111111\n'
154 '123\n'
155 '111111111111111111111111111111111111111\n'
156 '170141183460469231731687303715884105727\n'
157 )
158
159 inserted = self.client.execute(query)
160 self.assertEqual(inserted, data)
161
162 @require_server_version(21, 6)
163 def test_uint128(self):
164 with self.create_table('a UInt128'):
165 data = [
166 (0, ),
167 (123, ),
168 (340282366920938463463374607431768211455, )
169 ]
170 self.client.execute('INSERT INTO test (a) VALUES', data)
171
172 query = 'SELECT * FROM test'
173 inserted = self.emit_cli(query)
174 self.assertEqual(
175 inserted,
176 '0\n'
177 '123\n'
178 '340282366920938463463374607431768211455\n'
179 )
180
181 inserted = self.client.execute(query)
182 self.assertEqual(inserted, data)
183
184 def test_int256(self):
185 with self.create_table('a Int256'):
186 data = [
187 (-57896044618658097711785492504343953926634992332820282019728792003956564819968, ), # noqa: E501
188 (-11111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501
189 (123, ),
190 (11111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501
191 (57896044618658097711785492504343953926634992332820282019728792003956564819967, ) # noqa: E501
192 ]
193 self.client.execute('INSERT INTO test (a) VALUES', data)
194
195 query = 'SELECT * FROM test'
196 inserted = self.emit_cli(query)
197 self.assertEqual(
198 inserted,
199 '-57896044618658097711785492504343953926634992332820282019728792003956564819968\n' # noqa: E501
200 '-11111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501
201 '123\n'
202 '11111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501
203 '57896044618658097711785492504343953926634992332820282019728792003956564819967\n' # noqa: E501
204 )
205
206 inserted = self.client.execute(query)
207 self.assertEqual(inserted, data)
208
209 def test_uint256(self):
210 with self.create_table('a UInt256'):
211 data = [
212 (0, ),
213 (123, ),
214 (111111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501
215 (115792089237316195423570985008687907853269984665640564039457584007913129639935, ) # noqa: E501
216 ]
217 self.client.execute('INSERT INTO test (a) VALUES', data)
218
219 query = 'SELECT * FROM test'
220 inserted = self.emit_cli(query)
221 self.assertEqual(
222 inserted,
223 '0\n'
224 '123\n'
225 '111111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501
226 '115792089237316195423570985008687907853269984665640564039457584007913129639935\n' # noqa: E501
227 )
228
229 inserted = self.client.execute(query)
230 self.assertEqual(inserted, data)
0 from tests.testcase import BaseTestCase
1
2
3 class MapTestCase(BaseTestCase):
4 required_server_version = (21, 1, 2)
5 # TODO: detect stable version
6 stable_support_version = (22, 14, 9)
7
8 def client_kwargs(self, version):
9 if version < self.stable_support_version:
10 return {'settings': {'allow_experimental_map_type': True}}
11
12 def cli_client_kwargs(self):
13 if self.stable_support_version > self.server_version:
14 return {'allow_experimental_map_type': 1}
15
16 def _sorted_dicts(self, text):
17 items = [
18 ('{' + ','.join(sorted(x.strip('{}\n').split(','))) + '}')
19 for x in text.strip('\n').split('\n')
20 ]
21 return '\n'.join(items) + '\n'
22
23 def test_simple(self):
24 with self.create_table('a Map(String, UInt64)'):
25 data = [
26 ({},),
27 ({'key1': 1}, ),
28 ({'key1': 2, 'key2': 20}, ),
29 ({'key1': 3, 'key2': 30, 'key3': 50}, )
30 ]
31 self.client.execute('INSERT INTO test (a) VALUES', data)
32 query = 'SELECT * FROM test'
33 inserted = self.emit_cli(query)
34 self.assertEqual(
35 self._sorted_dicts(inserted),
36 "{}\n"
37 "{'key1':1}\n"
38 "{'key1':2,'key2':20}\n"
39 "{'key1':3,'key2':30,'key3':50}\n"
40 )
41 inserted = self.client.execute(query)
42 self.assertEqual(inserted, data)
43
44 # def test_nullable(self):
45 # with self.create_table('a Map(Nullable(String), Nullable(UInt64))'):
46 # data = [
47 # ({},),
48 # ({None: None},),
49 # ({'key1': 1}, )
50 # ]
51 # self.client.execute('INSERT INTO test (a) VALUES', data)
52 # query = 'SELECT * FROM test'
53 # inserted = self.emit_cli(query)
54 # self.assertEqual(
55 # inserted,
56 # "{}\n"
57 # "{NULL:NULL}\n"
58 # "{'key1':1}\n"
59 # )
60 # inserted = self.client.execute(query)
61 # self.assertEqual(inserted, data)
62 #
63 # def test_low_cardinality(self):
64 # columns = 'a Map(LowCardinality(String), LowCardinality(UInt64))'
65 # with self.create_table(columns):
66 # data = [
67 # ({'key1': 1}, ),
68 # ({'key1': 1}, ),
69 # ({'key1': 1}, )
70 # ]
71 # self.client.execute('INSERT INTO test (a) VALUES', data)
72 # query = 'SELECT * FROM test'
73 # inserted = self.emit_cli(query)
74 # self.assertEqual(
75 # inserted,
76 # "{'key1':1}\n"
77 # "{'key1':1}\n"
78 # "{'key1':1}\n"
79 # )
80 # inserted = self.client.execute(query)
81 # self.assertEqual(inserted, data)
82
83 def test_array(self):
84 columns = 'a Map(String, Array(UInt64))'
85 with self.create_table(columns):
86 data = [
87 ({'key1': []}, ),
88 ({'key2': [1, 2, 3]}, ),
89 ({'key3': [1, 1, 1, 1]}, )
90 ]
91 self.client.execute('INSERT INTO test (a) VALUES', data)
92 query = 'SELECT * FROM test'
93 inserted = self.emit_cli(query)
94 self.assertEqual(
95 inserted,
96 "{'key1':[]}\n"
97 "{'key2':[1,2,3]}\n"
98 "{'key3':[1,1,1,1]}\n"
99 )
100 inserted = self.client.execute(query)
101 self.assertEqual(inserted, data)
22
33 from tests.testcase import BaseTestCase
44 from clickhouse_driver import errors
5 from clickhouse_driver.util.compat import text_type
65
76
87 class StringTestCase(BaseTestCase):
102101
103102 inserted = self.client.execute(query, settings=settings)
104103 self.assertEqual(inserted, data)
105 self.assertIsInstance(inserted[0][0], text_type)
106 self.assertIsInstance(inserted[1][0], text_type)
104 self.assertIsInstance(inserted[0][0], str)
105 self.assertIsInstance(inserted[1][0], str)
107106
108107 def test_not_supported_types(self):
109108 datas = [
00 from contextlib import contextmanager
1 from datetime import datetime
1 from datetime import datetime, date
22 import os
33 from time import tzset
4
5 from mock import patch
4 from unittest.mock import patch
65
76 try:
87 import numpy as np
7574 self.assertArraysEqual(
7675 inserted[1], self.make_numpy_d64ns(['2012-10-25T14:07:19'])
7776 )
77
78 def test_nullable_date(self):
79 with self.create_table('a Nullable(Date)'):
80 data = [
81 np.array([None, date(2012, 10, 25), None, date(2017, 6, 23)],
82 dtype=object)
83 ]
84 self.client.execute(
85 'INSERT INTO test (a) VALUES', data, columnar=True
86 )
87
88 query = 'SELECT * FROM test'
89 inserted = self.emit_cli(query)
90 self.assertEqual(
91 inserted, '\\N\n2012-10-25\n\\N\n2017-06-23\n'
92 )
93
94 inserted = self.client.execute(query, columnar=True)
95 self.assertArraysEqual(inserted[0], data[0])
96 self.assertEqual(inserted[0].dtype, object)
97
98 def test_nullable_datetime(self):
99 with self.create_table('a Nullable(DateTime)'):
100 data = [
101 np.array([
102 None, datetime(2012, 10, 25, 14, 7, 19),
103 None, datetime(2017, 6, 23, 19, 10, 15)
104 ], dtype=object)
105 ]
106 self.client.execute(
107 'INSERT INTO test (a) VALUES', data, columnar=True
108 )
109
110 query = 'SELECT * FROM test'
111 inserted = self.emit_cli(query)
112 self.assertEqual(
113 inserted,
114 '\\N\n2012-10-25 14:07:19\n\\N\n2017-06-23 19:10:15\n'
115 )
116
117 inserted = self.client.execute(query, columnar=True)
118
119 self.assertArraysEqual(inserted[0], data[0])
120 self.assertEqual(inserted[0].dtype, object)
78121
79122 def test_handle_errors_from_tzlocal(self):
80123 with patch('tzlocal.get_localzone') as mocked_get_localzone:
0 from parameterized import parameterized
1
02 try:
13 import numpy as np
24 except ImportError:
1012
1113 def check_result(self, rv, col_type):
1214 self.assertArraysEqual(rv[0], np.array(range(self.n)))
13 self.assertIsInstance(rv[0][0], (col_type, ))
15 self.assertEqual(rv[0].dtype, col_type)
1416
1517 def get_query(self, ch_type):
1618 with self.create_table('a {}'.format(ch_type)):
4749
4850 inserted = self.client.execute(query, columnar=True)
4951 self.assertArraysEqual(inserted[0], data[0])
52
53 @parameterized.expand(['Float32', 'Float64'])
54 def test_nullable(self, float_type):
55 with self.create_table('a Nullable({})'.format(float_type)):
56 data = [np.array([np.nan, 0.5, None, 1.5], dtype=object)]
57 self.client.execute(
58 'INSERT INTO test (a) VALUES', data, columnar=True
59 )
60
61 query = 'SELECT * FROM test'
62 inserted = self.emit_cli(query)
63 self.assertEqual(inserted, 'nan\n0.5\n\\N\n1.5\n')
64
65 inserted = self.client.execute(query, columnar=True)
66 self.assertArraysEqual(
67 inserted[0].astype(str), data[0].astype(str)
68 )
69 self.assertEqual(inserted[0].dtype, object)
70
71 def test_nan(self):
72 with self.create_table('a Float32'):
73 data = [np.array([float('nan'), 0.5], dtype=np.float32)]
74 self.client.execute(
75 'INSERT INTO test (a) VALUES', data, columnar=True
76 )
77
78 query = 'SELECT * FROM test'
79 inserted = self.emit_cli(query)
80 self.assertEqual(inserted, 'nan\n0.5\n')
81
82 inserted = self.client.execute(query, columnar=True)
83 self.assertArraysEqual(
84 inserted[0].astype(str), data[0].astype(str)
85 )
86 self.assertEqual(inserted[0].dtype, np.float32)
1010
1111 def check_result(self, rv, col_type):
1212 self.assertArraysEqual(rv[0], np.array(range(self.n)))
13 self.assertIsInstance(rv[0][0], (col_type, ))
13 self.assertEqual(rv[0].dtype, col_type)
1414
1515 def get_query(self, ch_type):
1616 with self.create_table('a {}'.format(ch_type)):
5757 def test_uint64(self):
5858 rv = self.get_query('UInt64')
5959 self.check_result(rv, np.uint64)
60
61 def test_insert_nan_into_non_nullable(self):
62 with self.create_table('a Int32'):
63 data = [
64 np.array([123, np.nan], dtype=object)
65 ]
66 self.client.execute(
67 'INSERT INTO test (a) VALUES', data, columnar=True
68 )
69
70 query = 'SELECT * FROM test'
71 inserted = self.emit_cli(query)
72 self.assertEqual(
73 inserted,
74 '123\n0\n'
75 )
76
77 inserted = self.client.execute(query, columnar=True)
78 self.assertArraysEqual(inserted[0], np.array([123, 0]))
79 self.assertEqual(inserted[0].dtype, np.int32)
80
81 def test_nullable(self):
82 with self.create_table('a Nullable(Int32)'):
83 data = [np.array([2, None, 4, None, 8])]
84 self.client.execute(
85 'INSERT INTO test (a) VALUES', data, columnar=True
86 )
87
88 query = 'SELECT * FROM test'
89 inserted = self.emit_cli(query)
90 self.assertEqual(inserted, '2\n\\N\n4\n\\N\n8\n')
91
92 inserted = self.client.execute(query, columnar=True)
93 self.assertArraysEqual(inserted[0], data[0])
94 self.assertEqual(inserted[0].dtype, object)
22 except ImportError:
33 np = None
44
5 try:
6 import pandas as pd
7 except ImportError:
8 pd = None
9
10
511 from tests.numpy.testcase import NumpyBaseTestCase
612
713 # from decimal import Decimal
1521 if self.server_version >= self.stable_support_version:
1622 return {'allow_suspicious_low_cardinality_types': 1}
1723
24 def check_result(self, inserted, data):
25 self.assertArraysEqual(inserted[0], data[0])
26 self.assertIsInstance(inserted[0], pd.Categorical)
27
1828 def test_uint8(self):
1929 with self.create_table('a LowCardinality(UInt8)'):
2030 data = [np.array(range(255))]
3040 )
3141
3242 inserted = self.client.execute(query, columnar=True)
33 self.assertArraysEqual(inserted[0], data[0])
43 self.check_result(inserted, data)
3444
3545 def test_int8(self):
3646 with self.create_table('a LowCardinality(Int8)'):
4858 )
4959
5060 inserted = self.client.execute(query, columnar=True)
51 self.assertArraysEqual(inserted[0], data[0])
52
53 # def test_nullable_int8(self):
54 # with self.create_table('a LowCardinality(Nullable(Int8))'):
55 # data = [(None, ), (-1, ), (0, ), (1, ), (None, )]
56 # self.client.execute('INSERT INTO test (a) VALUES', data[0])
57 #
58 # query = 'SELECT * FROM test'
59 # inserted = self.emit_cli(query)
60 # self.assertEqual(inserted, '\\N\n-1\n0\n1\n\\N\n')
61 #
62 # inserted = self.client.execute(query)
63 # self.assertEqual(inserted, data[0])
61 self.check_result(inserted, data)
62
63 def test_nullable_int8(self):
64 with self.create_table('a LowCardinality(Nullable(Int8))'):
65 data = [np.array([None, -1, 0, 1, None], dtype=object)]
66 self.client.execute(
67 'INSERT INTO test (a) VALUES', data, columnar=True
68 )
69
70 query = 'SELECT * FROM test'
71 inserted = self.emit_cli(query)
72 self.assertEqual(inserted, '\\N\n-1\n0\n1\n\\N\n')
73
74 inserted = self.client.execute(query, columnar=True)
75 self.assertArraysEqual(
76 inserted[0].astype(str),
77 pd.Categorical(data[0]).astype(str)
78 )
79 self.assertIsInstance(inserted[0], pd.Categorical)
6480
6581 def test_date(self):
6682 with self.create_table('a LowCardinality(Date)'):
7187
7288 query = 'SELECT * FROM test'
7389 inserted = self.client.execute(query, columnar=True)
74 self.assertArraysEqual(inserted[0], data[0])
90 self.check_result(inserted, data)
7591
7692 def test_float(self):
7793 with self.create_table('a LowCardinality(Float)'):
8298
8399 query = 'SELECT * FROM test'
84100 inserted = self.client.execute(query, columnar=True)
85 self.assertArraysEqual(inserted[0], data[0])
101 self.check_result(inserted, data)
86102
87103 # def test_decimal(self):
88104 # with self.create_table('a LowCardinality(Float)'):
134150 )
135151
136152 inserted = self.client.execute(query, columnar=True)
137 self.assertArraysEqual(inserted[0], data[0])
138
139 # def test_fixed_string(self):
140 # with self.create_table('a LowCardinality(FixedString(12))'):
141 # data = [
142 # ('test', ), ('low', ), ('cardinality', ),
143 # ('test', ), ('test', ), ('', )
144 # ]
145 # self.client.execute('INSERT INTO test (a) VALUES', data[0])
146 #
147 # query = 'SELECT * FROM test'
148 # inserted = self.emit_cli(query)
149 # self.assertEqual(
150 # inserted,
151 # 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
152 # 'low\\0\\0\\0\\0\\0\\0\\0\\0\\0\n'
153 # 'cardinality\\0\n'
154 # 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
155 # 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
156 # '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n'
157 # )
158 #
159 # inserted = self.client.execute(query)
160 # self.assertEqual(inserted, data[0])
161 #
162 # def test_nullable_string(self):
163 # with self.create_table('a LowCardinality(Nullable(String))'):
164 # data = [
165 # ('test', ), ('', ), (None, )
166 # ]
167 # self.client.execute('INSERT INTO test (a) VALUES', data[0])
168 #
169 # query = 'SELECT * FROM test'
170 # inserted = self.emit_cli(query)
171 # self.assertEqual(
172 # inserted,
173 # 'test\n\n\\N\n'
174 # )
175 #
176 # inserted = self.client.execute(query)
177 # self.assertEqual(inserted, data[0])
153 self.check_result(inserted, data)
154
155 def test_insert_nan_string_into_non_nullable(self):
156 with self.create_table('a LowCardinality(String)'):
157 data = [
158 np.array(['test', None], dtype=object)
159 ]
160 self.client.execute(
161 'INSERT INTO test (a) VALUES', data, columnar=True
162 )
163
164 query = 'SELECT * FROM test'
165 inserted = self.emit_cli(query)
166 self.assertEqual(
167 inserted,
168 'test\n\n'
169 )
170
171 inserted = self.client.execute(query, columnar=True)
172 self.check_result(inserted, [np.array(['test', ''])])
173
174 def test_fixed_string(self):
175 with self.create_table('a LowCardinality(FixedString(12))'):
176 data = [
177 np.array(['test', 'low', 'cardinality', 'test', 'test', ''])
178 ]
179 self.client.execute(
180 'INSERT INTO test (a) VALUES', data, columnar=True
181 )
182
183 query = 'SELECT * FROM test'
184 inserted = self.emit_cli(query)
185 self.assertEqual(
186 inserted,
187 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
188 'low\\0\\0\\0\\0\\0\\0\\0\\0\\0\n'
189 'cardinality\\0\n'
190 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
191 'test\\0\\0\\0\\0\\0\\0\\0\\0\n'
192 '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n'
193 )
194
195 inserted = self.client.execute(query, columnar=True)
196 self.check_result(inserted, data)
197
198 def test_nullable_string(self):
199 with self.create_table('a LowCardinality(Nullable(String))'):
200 data = [
201 np.array(['test', '', None], dtype=object)
202 ]
203 self.client.execute(
204 'INSERT INTO test (a) VALUES', data, columnar=True
205 )
206
207 query = 'SELECT * FROM test'
208 inserted = self.emit_cli(query)
209 self.assertEqual(
210 inserted,
211 'test\n\n\\N\n'
212 )
213
214 inserted = self.client.execute(query, columnar=True)
215 self.assertArraysEqual(
216 inserted[0].astype(str), pd.Categorical(data[0]).astype(str)
217 )
218 self.assertIsInstance(inserted[0], pd.Categorical)
0 try:
1 import numpy as np
2 except ImportError:
3 np = None
4
5 try:
6 import pandas as pd
7 except ImportError:
8 pd = None
9
10 from tests.numpy.testcase import NumpyBaseTestCase
11 from clickhouse_driver import errors
12
13 ErrorCodes = errors.ErrorCodes
14
15
16 class NullableTestCase(NumpyBaseTestCase):
17 def test_simple(self):
18 columns = 'a Nullable(Int32)'
19
20 data = [np.array([3, None, 2], dtype=object)]
21 with self.create_table(columns):
22 self.client.execute(
23 'INSERT INTO test (a) VALUES', data, columnar=True
24 )
25
26 query = 'SELECT * FROM test'
27 inserted = self.emit_cli(query)
28 self.assertEqual(
29 inserted, '3\n\\N\n2\n'
30 )
31
32 inserted = self.client.execute(query, columnar=True)
33 self.assertArraysEqual(inserted[0], data[0])
34 self.assertEqual(inserted[0].dtype, object)
35
36 def test_simple_dataframe(self):
37 columns = (
38 'a Int64, '
39 'b Nullable(Float64), '
40 'c Nullable(String), '
41 'd Nullable(Int64)'
42 )
43
44 df = pd.DataFrame({
45 'a': [1, 2, 3],
46 'b': [1.0, None, np.nan],
47 'c': ['a', None, np.nan],
48 'd': [1, None, None],
49 }, dtype=object)
50 expected = pd.DataFrame({
51 'a': np.array([1, 2, 3], dtype=np.int64),
52 'b': np.array([1.0, None, np.nan], dtype=object),
53 'c': np.array(['a', None, None], dtype=object),
54 'd': np.array([1, None, None], dtype=object),
55 })
56
57 with self.create_table(columns):
58 rv = self.client.insert_dataframe('INSERT INTO test VALUES', df)
59 self.assertEqual(rv, 3)
60 df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a')
61 self.assertTrue(expected.equals(df2))
1919 rv = self.client.execute(query, columnar=True)
2020
2121 self.assertArraysEqual(rv[0], data)
22 self.assertIsInstance(rv[0][0], (object, ))
22 self.assertNotEqual(rv[0].dtype, object)
23 self.assertIsInstance(rv[0][1], (np.str_, ))
24
25 def test_nullable(self):
26 with self.create_table('a Nullable(String)'):
27 data = [np.array([np.nan, 'test', None, 'nullable'], dtype=object)]
28 self.client.execute(
29 'INSERT INTO test (a) VALUES', data, columnar=True
30 )
31
32 query = 'SELECT * FROM test'
33 inserted = self.emit_cli(query)
34 self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n')
35
36 inserted = self.client.execute(query, columnar=True)
37 self.assertArraysEqual(
38 inserted[0], [np.array([None, 'test', None, 'nullable'])]
39 )
40 self.assertEqual(inserted[0].dtype, object)
2341
2442
2543 class ByteStringTestCase(NumpyBaseTestCase):
3856 rv = self.client.execute(query, columnar=True)
3957
4058 self.assertArraysEqual(rv[0], data)
41 self.assertIsInstance(rv[0][0], (object, ))
59 self.assertNotEqual(rv[0].dtype, object)
60 self.assertIsInstance(rv[0][0], (np.bytes_, ))
61
62 def test_nullable(self):
63 with self.create_table('a Nullable(String)'):
64 data = [
65 np.array([np.nan, b'test', None, b'nullable'], dtype=object)
66 ]
67 self.client.execute(
68 'INSERT INTO test (a) VALUES', data, columnar=True
69 )
70
71 query = 'SELECT * FROM test'
72 inserted = self.emit_cli(query)
73 self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n')
74
75 inserted = self.client.execute(query, columnar=True)
76 self.assertArraysEqual(
77 inserted[0], [np.array([None, b'test', None, b'nullable'])]
78 )
79 self.assertEqual(inserted[0].dtype, object)
4280
4381
4482 class FixedStringTestCase(NumpyBaseTestCase):
5593 rv = self.client.execute(query, columnar=True)
5694
5795 self.assertArraysEqual(rv[0], data)
58 self.assertIsInstance(rv[0][0], (object, ))
96 self.assertNotEqual(rv[0].dtype, object)
97 self.assertIsInstance(rv[0][0], (np.str_, ))
98
99 def test_nullable(self):
100 with self.create_table('a Nullable(FixedString(10))'):
101 data = [np.array([np.nan, 'test', None, 'nullable'], dtype=object)]
102 self.client.execute(
103 'INSERT INTO test (a) VALUES', data, columnar=True
104 )
105
106 query = 'SELECT * FROM test'
107 inserted = self.emit_cli(query)
108 self.assertEqual(
109 inserted,
110 '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n'
111 )
112
113 inserted = self.client.execute(query, columnar=True)
114 self.assertArraysEqual(
115 inserted[0], [np.array([None, 'test', None, 'nullable'])]
116 )
117 self.assertEqual(inserted[0].dtype, object)
59118
60119
61120 class ByteFixedStringTestCase(NumpyBaseTestCase):
74133 rv = self.client.execute(query, columnar=True)
75134
76135 self.assertArraysEqual(rv[0], data)
77 self.assertIsInstance(rv[0][0], (object, ))
136 self.assertNotEqual(rv[0].dtype, object)
137 self.assertIsInstance(rv[0][0], (np.bytes_, ))
138
139 def test_nullable(self):
140 with self.create_table('a Nullable(FixedString(10))'):
141 data = [np.array([
142 np.nan,
143 b'test\x00\x00\x00\x00\x00\x00',
144 None,
145 b'nullable\x00\x00'
146 ], dtype=object)]
147
148 self.client.execute(
149 'INSERT INTO test (a) VALUES', data, columnar=True
150 )
151
152 query = 'SELECT * FROM test'
153 inserted = self.emit_cli(query)
154 self.assertEqual(
155 inserted,
156 '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n'
157 )
158
159 inserted = self.client.execute(query, columnar=True)
160 self.assertArraysEqual(
161 inserted[0], [np.array([None, b'test', None, b'nullable'])]
162 )
163 self.assertEqual(inserted[0].dtype, object)
119119 df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a')
120120 self.assertTrue(df.equals(df2))
121121
122 def test_insert_transposed(self):
122 def test_insert_chunking(self):
123 with self.create_table('a Int64'):
124 rv = self.client.execute(
125 'INSERT INTO test VALUES', [np.array(range(3))], columnar=True,
126 settings={'insert_block_size': 1}
127 )
128 self.assertEqual(rv, 3)
129
130 def test_insert_not_ordered_columns(self):
123131 n = 10
124132 df = pd.DataFrame({
125 'a': range(n),
126 'b': [float(x) for x in range(n)]
127 })
133 'b': range(n),
134 'a': [str(x) for x in range(n)]
135 })[['b', 'a']]
128136
129 with self.create_table('a Int64, b Float64'):
137 with self.create_table('a String, b Float64'):
130138 rv = self.client.insert_dataframe(
131 'INSERT INTO test VALUES', df.transpose(), transpose=False
139 'INSERT INTO test (a, b) VALUES', df
132140 )
133141 self.assertEqual(rv, n)
134 df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a')
135 self.assertTrue(df.equals(df2))
136142
137143
138144 class NoNumPyTestCase(BaseTestCase):
0 try:
1 import numpy as np
2 except ImportError:
3 np = None
4
05 from tests.numpy.util import check_numpy
16 from tests.testcase import BaseTestCase
27
00 import types
1
2 from mock import patch
1 from unittest.mock import patch
32
43 from clickhouse_driver.errors import ServerException
5 from tests.testcase import BaseTestCase
4 from tests.testcase import BaseTestCase, file_config
65 from tests.util import capture_logging
76
87
212211 # Test all packets of INSERT query are consumed.
213212 rv = self.client.execute('SELECT 1', settings=settings)
214213 self.assertEqual(rv, [(1, )])
214
215 def test_logs_with_compression(self):
216 compression = 'lz4'
217 supported_compressions = (
218 file_config.get('db', 'compression').split(',')
219 )
220
221 if compression not in supported_compressions:
222 self.skipTest(
223 'Compression {} is not supported'.format(compression)
224 )
225
226 with self.created_client(compression='lz4') as client:
227 with capture_logging('clickhouse_driver.log', 'INFO') as buffer:
228 settings = {'send_logs_level': 'debug'}
229 query = 'SELECT 1'
230 client.execute(query, settings=settings)
231 self.assertIn(query, buffer.getvalue())
00 import socket
1 from unittest import TestCase
1 from unittest import TestCase, mock
22
3 import mock
43 from clickhouse_driver.bufferedreader import BufferedSocketReader
54
65
00 import ssl
1 from unittest import TestCase
21
32 from clickhouse_driver import Client
43 from clickhouse_driver.compression.lz4 import Compressor as LZ4Compressor
65 from clickhouse_driver.compression.zstd import Compressor as ZSTDCompressor
76 from clickhouse_driver.protocol import Compression
87 from tests.numpy.util import check_numpy
8 from tests.testcase import TestCase
99
1010
1111 class ClientFromUrlTestCase(TestCase):
162162 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5'
163163 })
164164
165 def test_ssl_key_cert(self):
166 base_url = (
167 'clickhouses://host?'
168 'verify=true&'
169 'ssl_version=PROTOCOL_SSLv23&'
170 'ca_certs=/tmp/certs&'
171 'ciphers=HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5&'
172 )
173 base_expected = {
174 'ssl_version': ssl.PROTOCOL_SSLv23,
175 'ca_certs': '/tmp/certs',
176 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5'
177 }
178
179 c = Client.from_url(
180 base_url +
181 'keyfile=/tmp/client.key&'
182 'certfile=/tmp/client.cert'
183 )
184 expected = base_expected.copy()
185 expected.update({
186 'keyfile': '/tmp/client.key',
187 'certfile': '/tmp/client.cert'
188 })
189 self.assertEqual(c.connection.ssl_options, expected)
190
191 c = Client.from_url(
192 base_url +
193 'certfile=/tmp/client.cert'
194 )
195 expected = base_expected.copy()
196 expected.update({
197 'certfile': '/tmp/client.cert'
198 })
199 self.assertEqual(c.connection.ssl_options, expected)
200
165201 def test_alt_hosts(self):
166202 c = Client.from_url('clickhouse://host?alt_hosts=host2:1234')
167203 self.assertHostsEqual(c, [('host', 9000), ('host2', 1234)])
190226 def test_use_numpy(self):
191227 c = Client.from_url('clickhouse://host?use_numpy=true')
192228 self.assertTrue(c.connection.context.client_settings['use_numpy'])
229
230 def test_opentelemetry(self):
231 c = Client.from_url(
232 'clickhouse://host?opentelemetry_traceparent='
233 '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00'
234 )
235 self.assertEqual(
236 c.connection.context.client_settings['opentelemetry_traceparent'],
237 '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00'
238 )
239 self.assertEqual(
240 c.connection.context.client_settings['opentelemetry_tracestate'],
241 ''
242 )
243
244 c = Client.from_url(
245 'clickhouse://host?opentelemetry_traceparent='
246 '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00&'
247 'opentelemetry_tracestate=state'
248 )
249 self.assertEqual(
250 c.connection.context.client_settings['opentelemetry_traceparent'],
251 '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00'
252 )
253 self.assertEqual(
254 c.connection.context.client_settings['opentelemetry_tracestate'],
255 'state'
256 )
00 # coding: utf-8
11 import socket
2
3 from mock import patch
42 from io import BytesIO
3 from unittest.mock import patch
54
65 from clickhouse_driver import errors
76 from clickhouse_driver.client import Client
2423
2524
2625 class ConnectTestCase(BaseTestCase):
26 def unexpected_packet_message(self, expected, got):
27 return (
28 'Code: 102. Unexpected packet from server {}:{} '
29 '(expected {}, got {})'
30 ).format(self.host, self.port, expected, got)
31
2732 def test_exception_on_hello_packet(self):
2833 with self.created_client(user='wrong_user') as client:
2934 with self.assertRaises(errors.ServerException) as e:
102107 # Emulate Exception packet on ping.
103108 mocked_fin.read_one.return_value = 2
104109
105 with self.assertRaises(errors.UnexpectedPacketFromServerError):
110 error = errors.UnexpectedPacketFromServerError
111 with self.assertRaises(error) as e:
106112 self.client.execute('SELECT 1')
113
114 self.assertEqual(
115 str(e.exception),
116 self.unexpected_packet_message('Pong', 'Exception')
117 )
107118
108119 def test_eof_on_receive_packet(self):
109120 self.client.execute('SELECT 1')
165176 self.assertEqual(self.n_calls, 1)
166177
167178 client.disconnect()
179
180 def test_remember_current_database(self):
181 with self.created_client() as client:
182 client.execute(' USE system ; ')
183 client.disconnect()
184
185 rv = client.execute('SELECT currentDatabase()')
186 self.assertEqual(rv, [('system', )])
187
188 def test_context_manager(self):
189 with self.created_client() as c:
190 c.execute('SELECT 1')
191 self.assertTrue(c.connection.connected)
192 self.assertFalse(c.connection.connected)
193
194 def test_unknown_packet(self):
195 self.client.execute('SELECT 1')
196
197 with patch('clickhouse_driver.connection.read_varint') as read_mock, \
198 patch.object(self.client.connection, 'force_connect'):
199 read_mock.return_value = 42
200
201 with self.assertRaises(errors.UnknownPacketFromServerError) as e:
202 self.client.execute('SELECT 1')
203
204 self.assertEqual(
205 str(e.exception),
206 'Code: 100. Unknown packet 42 from server {}:{}'.format(
207 self.host, self.port
208 )
209 )
210
211 def test_unknown_packet_on_connect(self):
212 with patch('clickhouse_driver.connection.read_varint') as read_mock:
213 read_mock.return_value = 42
214
215 error = errors.UnexpectedPacketFromServerError
216 with self.assertRaises(error) as e:
217 self.client.execute('SELECT 1')
218
219 msg = self.unexpected_packet_message(
220 'Hello or Exception', 'Unknown packet'
221 )
222 self.assertEqual(str(e.exception), msg)
168223
169224
170225 class FakeBufferedReader(BufferedReader):
00 import types
11 from contextlib import contextmanager
22 import socket
3
4 from mock import patch
3 from unittest.mock import patch
54
65 from clickhouse_driver import connect
76 from clickhouse_driver.dbapi import (
6564 self.assertEqual(cursor.fetchall(), [(1, )])
6665 connection.close()
6766
67 def test_connect_default_params(self):
68 connection = connect(host=self.host)
69 cursor = connection.cursor()
70
71 rv = cursor.execute('SELECT 1')
72 self.assertIsNone(rv)
73 self.assertEqual(cursor.fetchall(), [(1, )])
74 connection.close()
75
6876 def test_execute_fetchone(self):
6977 with self.created_cursor() as cursor:
7078 cursor.execute('SELECT number FROM system.numbers LIMIT 4')
195203 # once with host == 'wrong_host'.
196204 self.assertEqual(self.n_calls, 1)
197205
206 def test_remove_cursor_from_connection_on_closing(self):
207 with self.created_connection() as connection:
208 self.assertEqual(len(connection.cursors), 0)
209 cur = connection.cursor()
210 self.assertEqual(len(connection.cursors), 1)
211 cur.close()
212 self.assertEqual(len(connection.cursors), 0)
213
198214
199215 class StreamingTestCase(DBAPITestCaseBase):
200216 def test_fetchone(self):
1313 }]
1414 rv = self.client.execute('SELECT * FROM test', external_tables=tables)
1515 self.assertEqual(rv, [(100, [2, 4, 6, 8]), (500, [1, 3, 5, 7])])
16
17 def test_send_empty_table(self):
18 tables = [{
19 'name': 'test',
20 'structure': [('x', 'Int32')],
21 'data': []
22 }]
23 rv = self.client.execute('SELECT * FROM test', external_tables=tables)
24 self.assertEqual(rv, [])
25
26 def test_send_empty_table_structure(self):
27 tables = [{
28 'name': 'test',
29 'structure': [],
30 'data': []
31 }]
32 with self.assertRaises(ValueError) as e:
33 self.client.execute('SELECT * FROM test', external_tables=tables)
34
35 self.assertIn('Empty table "test" structure', str(e.exception))
0 from tests.testcase import BaseTestCase
1 from tests.util import capture_logging
2
3
4 class OpenTelemetryTestCase(BaseTestCase):
5 required_server_version = (20, 11, 2)
6
7 def test_server_logs(self):
8 tracestate = 'tracestate'
9 traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'
10
11 settings = {
12 'opentelemetry_tracestate': tracestate,
13 'opentelemetry_traceparent': traceparent
14
15 }
16 with self.created_client(settings=settings) as client:
17 with capture_logging('clickhouse_driver.log', 'INFO') as buffer:
18 settings = {'send_logs_level': 'trace'}
19 query = 'SELECT 1'
20 client.execute(query, settings=settings)
21 value = buffer.getvalue()
22 self.assertIn('OpenTelemetry', value)
23 self.assertIn('1af7651916cd43dd8448eb211c80319c', value)
24
25 def test_no_tracestate(self):
26 traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'
27
28 settings = {
29 'opentelemetry_traceparent': traceparent
30
31 }
32 with self.created_client(settings=settings) as client:
33 with capture_logging('clickhouse_driver.log', 'INFO') as buffer:
34 settings = {'send_logs_level': 'trace'}
35 query = 'SELECT 1'
36 client.execute(query, settings=settings)
37 value = buffer.getvalue()
38 self.assertIn('OpenTelemetry', value)
39 self.assertIn('1af7651916cd43dd8448eb211c80319c', value)
40
41 def test_bad_traceparent(self):
42 settings = {'opentelemetry_traceparent': 'bad'}
43 with self.created_client(settings=settings) as client:
44 with self.assertRaises(ValueError) as e:
45 client.execute('SELECT 1')
46
47 self.assertEqual(
48 str(e.exception),
49 'unexpected length 3, expected 55'
50 )
51
52 traceparent = '00-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-yyyyyyyyyyyyyyyy-01'
53 settings = {'opentelemetry_traceparent': traceparent}
54 with self.created_client(settings=settings) as client:
55 with self.assertRaises(ValueError) as e:
56 client.execute('SELECT 1')
57
58 self.assertEqual(
59 str(e.exception),
60 'Malformed traceparant header: {}'.format(traceparent)
61 )
62
63 def test_bad_traceparent_version(self):
64 settings = {
65 'opentelemetry_traceparent':
66 '01-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-01'
67 }
68 with self.created_client(settings=settings) as client:
69 with self.assertRaises(ValueError) as e:
70 client.execute('SELECT 1')
71
72 self.assertEqual(
73 str(e.exception),
74 'unexpected version 01, expected 00'
75 )
0 import configparser
01 from contextlib import contextmanager
12 import subprocess
23 from unittest import TestCase
34
45 from clickhouse_driver.client import Client
5 from clickhouse_driver.util import compat
66 from tests import log
77 from tests.util import skip_by_server_version
8
9
10 if compat.PY3:
11 import configparser
12 else:
13 import ConfigParser as configparser
148
159
1610 file_config = configparser.ConfigParser()
2418 required_server_version = None
2519 server_version = None
2620
21 clickhouse_client_binary = file_config.get('db', 'client')
2722 host = file_config.get('db', 'host')
2823 port = file_config.getint('db', 'port')
2924 database = file_config.get('db', 'database')
4035 database = cls.database
4136
4237 args = [
43 'clickhouse-client',
38 cls.clickhouse_client_binary,
4439 '--database', database,
4540 '--host', cls.host,
4641 '--port', str(cls.port),
7368 client_kwargs.update(kwargs)
7469 return Client(self.host, **client_kwargs)
7570
76 @contextmanager
7771 def created_client(self, **kwargs):
78 client = self._create_client(**kwargs)
79
80 try:
81 yield client
82 finally:
83 client.disconnect()
72 return self._create_client(**kwargs)
8473
8574 @classmethod
8675 def setUpClass(cls):