pax_global_header00006660000000000000000000000064142067674040014524gustar00rootroot0000000000000052 comment=5a3d1bf99629df890d879cad9915f9bf01ea9a81 python-clickhouse-driver-0.2.3/000077500000000000000000000000001420676740400164675ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/.coveragerc000066400000000000000000000000731420676740400206100ustar00rootroot00000000000000[run] plugins = Cython.Coverage source = clickhouse_driver python-clickhouse-driver-0.2.3/.flake8000066400000000000000000000004611420676740400176430ustar00rootroot00000000000000[flake8] filename = *.py, *.pyx per-file-ignores = clickhouse_driver/columns/largeint.pyx: E225, E226, E227, E999 clickhouse_driver/bufferedreader.pyx: E225, E226, E227, E999 clickhouse_driver/bufferedwriter.pyx: E225, E226, E227, E999 clickhouse_driver/varint.pyx: E225, E226, E227, E999 python-clickhouse-driver-0.2.3/.github/000077500000000000000000000000001420676740400200275ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/.github/ISSUE_TEMPLATE/000077500000000000000000000000001420676740400222125ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000007661420676740400247150ustar00rootroot00000000000000--- name: Bug report about: Create a report to help us improve title: '' labels: '' assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Minimal piece of Python code that reproduces the problem. **Expected behavior** A clear and concise description of what you expected to happen. **Versions** - Version of package with the problem. - ClickHouse server version. Version can be obtained by running `SELECT version()` query. - Python version. python-clickhouse-driver-0.2.3/.github/workflows/000077500000000000000000000000001420676740400220645ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/.github/workflows/actions.yml000066400000000000000000000244231420676740400242540ustar00rootroot00000000000000on: [push, pull_request] name: build jobs: tests: runs-on: ubuntu-20.04 strategy: matrix: use-numpy: - 0 python-version: - "3.5" - "3.6" - "3.7" - "3.8" - "3.9" - "3.10" - "pypy-3.6" - "pypy-3.7" clickhouse-version: - 21.12.3.32 - 21.9.3.30 - 21.9.3.30 - 21.4.6.55 - 21.3.10.1 - 21.2.10.48 - 21.1.9.41 - 20.11.2.1 - 20.10.2.20 - 20.9.3.45 - 20.8.4.11 - 20.7.4.11 - 20.6.8.5 - 20.5.5.74 - 20.4.9.110 - 20.3.20.6 - 19.16.17.80 - 19.15.3.6 - 19.9.2.4 # allow_suspicious_low_cardinality_types - 19.8.3.8 # SimpleAggregateFunction - 19.3.3 - 18.12.17 include: - clickhouse-version: 20.3.20.6 use-numpy: 1 python-version: 3.8 name: ${{ matrix.python-version }} CH=${{ matrix.clickhouse-version }} NUMPY=${{ matrix.use-numpy }} steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: x64 # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Install flake8 run: | pip install --upgrade pip setuptools wheel pip install flake8 flake8-print - name: Run flake8 run: flake8 - name: Start ClickHouse server and client containers run: | echo "VERSION=${{ matrix.clickhouse-version }}" > tests/.env docker-compose -f tests/docker-compose.yml up -d - name: Setup clickhouse-client proxy for docker run: | # Faking clickhouse-client real communication with container via docker exec. 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 sudo chmod +x /usr/local/bin/clickhouse-client # Overriding setup.cfg. Set host=clickhouse-server sed -i 's/^host=localhost$/host=clickhouse-server/' setup.cfg # Make host think that clickhouse-server is localhost echo '127.0.0.1 clickhouse-server' | sudo tee /etc/hosts > /dev/null - name: Build cython extensions with tracing run: CYTHON_TRACE=1 python setup.py build_ext --define CYTHON_TRACE if: ${{ !contains(matrix.python-version, 'pypy') }} - name: Install requirements run: | # Newer coveralls do not work with github actions. pip install 'coveralls<3.0.0' pip install cython python testsrequire.py python setup.py develop # Limit each test time execution. pip install pytest-timeout env: USE_NUMPY: ${{ matrix.use-numpy }} - name: Run tests run: coverage run -m py.test --timeout=10 -v timeout-minutes: 5 env: # Set initial TZ for docker exec -e "`env | grep ^TZ`" TZ: UTC - name: Upload coverage run: coveralls env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_PARALLEL: true COVERALLS_FLAG_NAME: ${{ matrix.python-version }} CH=${{ matrix.clickhouse-version }} NUMPY=${{ matrix.use-numpy }} coveralls-finished: name: Indicate completion to coveralls.io needs: tests runs-on: ubuntu-latest steps: - name: Finished uses: coverallsapp/github-action@1.1.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true valgrind: name: Valgrind check needs: tests runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.8 architecture: x64 - name: Install valgrind run: sudo apt-get install -y valgrind # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Start ClickHouse server and client containers run: | echo "VERSION=$VERSION" > tests/.env docker-compose -f tests/docker-compose.yml up -d env: VERSION: 20.3.7.46 - name: Setup clickhouse-client proxy for docker run: | # Faking clickhouse-client real communication with container via docker exec. 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 sudo chmod +x /usr/local/bin/clickhouse-client # Overriding setup.cfg. Set host=clickhouse-server sed -i 's/^host=localhost$/host=clickhouse-server/' setup.cfg # Make host think that clickhouse-server is localhost echo '127.0.0.1 clickhouse-server' | sudo tee /etc/hosts > /dev/null - name: Install requirements run: | python testsrequire.py python setup.py develop env: USE_NUMPY: 1 - name: Run tests under valgrind run: valgrind --error-exitcode=1 --suppressions=valgrind.supp py.test -v env: # Set initial TZ for docker exec -e "`env | grep ^TZ`" TZ: UTC USE_NUMPY: 1 PYTHONMALLOC: malloc wheels-linux: name: Wheels for Linux needs: valgrind runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.8 architecture: x64 # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Install cibuildwheel run: | pip install --upgrade pip setuptools pip install cython cibuildwheel==$VERSION env: VERSION: 2.2.2 - name: Build wheels run: cibuildwheel --output-dir wheelhouse env: CIBW_BUILD: '*p3*' CIBW_BEFORE_BUILD: pip install cython - uses: ncipollo/release-action@v1 name: Upload wheels if: ${{ github.ref_type == 'tag' }} with: artifacts: "wheelhouse/*" allowUpdates: true draft: true tag: Linux token: ${{ secrets.GITHUB_TOKEN }} wheels-macos: name: Wheels for OS X needs: valgrind runs-on: macos-10.15 steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.8 architecture: x64 # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Install cibuildwheel run: | pip install --upgrade pip setuptools pip install cython cibuildwheel==$VERSION env: VERSION: 2.2.2 - name: Build wheels run: cibuildwheel --output-dir wheelhouse env: CIBW_BUILD: '*p3*' CIBW_BEFORE_BUILD: pip install cython - uses: ncipollo/release-action@v1 name: Upload wheels if: ${{ github.ref_type == 'tag' }} with: artifacts: "wheelhouse/*" allowUpdates: true draft: true tag: OS X token: ${{ secrets.GITHUB_TOKEN }} wheels-windows: name: Wheels for Windows needs: valgrind runs-on: windows-2019 steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.8 architecture: x64 # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Install cibuildwheel run: | pip install cibuildwheel==$env:VERSION env: VERSION: 2.2.2 - name: Build wheels run: cibuildwheel --output-dir wheelhouse env: CIBW_BUILD: '*p3*' CIBW_BEFORE_BUILD: pip install cython - uses: ncipollo/release-action@v1 name: Upload wheels if: ${{ github.ref_type == 'tag' }} with: artifacts: "wheelhouse/*" allowUpdates: true draft: true tag: Windows token: ${{ secrets.GITHUB_TOKEN }} wheels-linux-non-x86: name: Wheels for Linux non-x86 needs: valgrind runs-on: ubuntu-20.04 strategy: matrix: arch: - aarch64 - ppc64le - s390x steps: - uses: actions/checkout@v2.1.0 # - name: Login to Docker Hub # uses: docker/login-action@v1 # with: # username: ${{ secrets.DOCKER_HUB_USERNAME }} # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.8 architecture: x64 - name: Set up QEMU id: qemu uses: docker/setup-qemu-action@v1.2.0 with: image: tonistiigi/binfmt:latest platforms: all - name: Install cibuildwheel run: | pip install --upgrade pip setuptools pip install cibuildwheel==$VERSION env: VERSION: 2.2.2 - name: Build wheels run: cibuildwheel --output-dir wheelhouse env: CIBW_BUILD: '*p3*' CIBW_BEFORE_BUILD: pip install cython CIBW_ARCHS: ${{ matrix.arch }} - uses: ncipollo/release-action@v1 name: Upload wheels if: ${{ github.ref_type == 'tag' }} with: artifacts: "wheelhouse/*" allowUpdates: true draft: true tag: Linux non-x86 token: ${{ secrets.GITHUB_TOKEN }} python-clickhouse-driver-0.2.3/CHANGELOG.md000066400000000000000000000507131420676740400203060ustar00rootroot00000000000000# Changelog ## Unreleased ### Added - `tzlocal`>=4.0 support. Pull request [#263](https://github.com/mymarilyn/clickhouse-driver/pull/263) by [azat](https://github.com/azat). - `quota_key` support. - Wheels for Python 3.10. - Bool type. Pull request [#279](https://github.com/mymarilyn/clickhouse-driver/pull/279) by [adrian17](https://github.com/adrian17). - Nested type with `flatten_nested=0`. Pull request [#285](https://github.com/mymarilyn/clickhouse-driver/pull/285) by [spff](https://github.com/spff). ### Fixed - Handle partially consumed query. Solves issue [#117](https://github.com/mymarilyn/clickhouse-driver/issues/117). - Fallback to generic columns when NumPy support is not implemented for column type. Solves issue [#254](https://github.com/mymarilyn/clickhouse-driver/issues/254). - Broken ZSTD decompression. Solves issue [#269](https://github.com/mymarilyn/clickhouse-driver/issues/269). - External tables passing with NumPy. Solves issue [#267](https://github.com/mymarilyn/clickhouse-driver/issues/267). - Consider tzinfo for datetime parameters substitution. Solves issue [#268](https://github.com/mymarilyn/clickhouse-driver/issues/268). - Do not use NumPy columns inside generic columns. Solves issue [#272](https://github.com/mymarilyn/clickhouse-driver/issues/272). - Decimal128 and Decimal256 types_check. Solves issue [#274](https://github.com/mymarilyn/clickhouse-driver/issues/274). - Insertion using `execute` in DB API. Solves issue [#179](https://github.com/mymarilyn/clickhouse-driver/issues/179). Pull request [#276](https://github.com/mymarilyn/clickhouse-driver/pull/276) by [nnseva](https://github.com/nnseva). - Variables cannot be declared with `cpdef` in Cython 3. Pull request [#281](https://github.com/mymarilyn/clickhouse-driver/pull/281) by [ym](https://github.com/ym). ### Changed - Switch from nose test runner to pytest. - Migrate from Travis CI to GitHub Actions. ## [0.2.2] - 2021-09-24 ### Added - DateTime64 extended range. Pull request [#222](https://github.com/mymarilyn/clickhouse-driver/pull/222) by [0x4ec7](https://github.com/0x4ec7). - 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). - OpenTelemetry support. Solves issue [#230](https://github.com/mymarilyn/clickhouse-driver/issues/230). - `tzlocal`>=3.0 support. - Date32 type. - NumPy Nullable(T) support. ### Fixed - Boxing on DataFrames INSERT. - Empty external tables sending. Solves issue [#240](https://github.com/mymarilyn/clickhouse-driver/issues/240). - Create error message before disconnect. Pull request [#247](https://github.com/mymarilyn/clickhouse-driver/pull/247) by [NikiforovG](https://github.com/NikiforovG). - Writing explicit NumPy `NaN` values. Solves issue [#249](https://github.com/mymarilyn/clickhouse-driver/issues/249). - UInt128 INSERTing. Solves issue [#251](https://github.com/mymarilyn/clickhouse-driver/issues/251). - Large DataFrames chunking. Solves issue [#243](https://github.com/mymarilyn/clickhouse-driver/issues/243). - Allow arbitrary DataFrame columns order on INSERT. Solves issue [#245](https://github.com/mymarilyn/clickhouse-driver/issues/245). ### Changed - Protocol version bumped to 54442. - Unpin `lz4` for CPython. Pin `lz4`<=3.0.1 only for PyPy. ### Removed - `transpose` parameter from `insert_dataframe`. ## [0.2.1] - 2021-06-02 ### Added - Linux wheels for AArch64. Pull request [#197](https://github.com/mymarilyn/clickhouse-driver/pull/197) by [odidev](https://github.com/odidev). - [U]Int28/256 types. - Decimal256 type. - Code coverage for cython code. - Map type. - Support for private key/certificate file. Pull request [#219](https://github.com/mymarilyn/clickhouse-driver/pull/219) by [alexole](https://github.com/alexole). ### Fixed - Empty Array(Tuple(T)) writing. Solves issue [#177](https://github.com/mymarilyn/clickhouse-driver/issues/177). - Preserve Decimal precision on INSERT. Solves issue [#192](https://github.com/mymarilyn/clickhouse-driver/issues/192). - Remove closed cursors from connection. Solves issue [#194](https://github.com/mymarilyn/clickhouse-driver/issues/194). - DB API connect with default params. - Fix log blocks handling. Solves issue [#203](https://github.com/mymarilyn/clickhouse-driver/issues/203). - 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). - Use last database after reconnect. Solves issue [#205](https://github.com/mymarilyn/clickhouse-driver/issues/205). - Decimal(N, 1) handling. Pull request [#210](https://github.com/mymarilyn/clickhouse-driver/pull/210) by [raw0w](https://github.com/raw0w). ### Changed - Decimal128 performance increased (up to 25% compared to 0.2.0 release). ### Removed - Python 2.7 support. ## [0.2.0] - 2020-12-14 ### Added - NumPy reading/writing for columns: Float32/64, [U]Int8/16/32/64, Date/DateTime(‘timezone’)/DateTime64(‘timezone’), String/FixedString(N), LowCardinality(T). Merge [Arturus's](https://github.com/Arturus/clickhouse-driver) fork. - pandas DataFrame reading/writing. - Ability to mark all settings as important to fail on unknown settings on sever side. - SSL SNI support. Solves issue [#172](https://github.com/mymarilyn/clickhouse-driver/issues/172). - Wheels for Python 3.9 and PyPy. - Remember last successful host on connection. Solves issue [#168](https://github.com/mymarilyn/clickhouse-driver/issues/168). ### Fixed - Server logs displaying on INSERT. - Make exceptions picklable. Pull request [#169](https://github.com/mymarilyn/clickhouse-driver/pull/169) by [azat](https://github.com/azat). - Enum type deserializing when it wrapped in SimpleAggregateFunction. Pull request [#170](https://github.com/mymarilyn/clickhouse-driver/pull/170) by [flyAwayGG](https://github.com/flyAwayGG). - Pin major `tzlocal` version. Solves issue [#166](https://github.com/mymarilyn/clickhouse-driver/issues/166). ### Changed - String and DateTime columns writing optimization. - Array columns reading/writing optimization. - Chunking optimization for large lists/tuples. - Protocol version bumped to 54441. ## [0.1.5] - 2020-09-19 ### Added - Do not require settings declaration if server support setting-as-string. Pull request [#142](https://github.com/mymarilyn/clickhouse-driver/pull/142) by [azat](https://github.com/azat). - `host_name` in logs. Pull request [#144](https://github.com/mymarilyn/clickhouse-driver/pull/144) by [azat](https://github.com/azat). - Cursor attribute `columns_with_types` to DB API. Issue [#149](https://github.com/mymarilyn/clickhouse-driver/issues/149). - Cursor method `set_query_id` to DB API. Issue [#152](https://github.com/mymarilyn/clickhouse-driver/issues/152). ### Fixed - Connection error messages formatting. - `Client.from_url` credentials unquoting. Issue [#146](https://github.com/mymarilyn/clickhouse-driver/issues/146). - Empty nested array handling. Pull request [#161](https://github.com/mymarilyn/clickhouse-driver/pull/161) by [dourvaris](https://github.com/dourvaris). - `read_varint` overflow. Issue [#163](https://github.com/mymarilyn/clickhouse-driver/issues/163). - Malformed reads/writes in `BufferedReader`. This addresses [CVE-2020-26759](https://nvd.nist.gov/vuln/detail/CVE-2020-26759). ### Changed - 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). ## [0.1.4] - 2020-06-13 ### Added - Tuple type. - Custom String column encoding. - Settings update to v20.4.1.2742 server version. Pull request [#133](https://github.com/mymarilyn/clickhouse-driver/pull/133) by [azat](https://github.com/azat). - Settings update to v20.5.1.3657 server version. Pull request [#141](https://github.com/mymarilyn/clickhouse-driver/pull/141) by [azat](https://github.com/azat). - Unsupported server versions to documentation. - Performance section to documentation. - Python 3.9 in Travis CI build matrix. ### Fixed - Reading/writing Array(Tuple). - 20.x server version support. - Settings mutation in `execute`. - Slow columnar results returning (`columnar=True`). - Segfault on passing not encoded strings during `INSERT` into ByteString column. ### Changed - Miscellaneous read/write optimizations - Protocol version bumped to 54429. ## [0.1.3] - 2020-02-21 ### Added - Python DB API 2.0. - Multiple hosts support on connection errors. - Insert columnar data support. Pull request [#122](https://github.com/mymarilyn/clickhouse-driver/pull/122) by [Anexen](https://github.com/Anexen). - Wheels for Python 3.8. - DateTime64 type. - Settings update to v20.2.1.2201 server version. Pull request [#123](https://github.com/mymarilyn/clickhouse-driver/pull/123) by [azat](https://github.com/azat). ### Fixed - `Client.from_url` settings detection. - Close socket on `KeyboardInterrupt` while running query. - Null handling in LowCardinality columns. ### Changed - Protocol version bumped to 54421. - Increased speed (up to 20-30% compared to 0.1.2 release) on heavy `SELECT` and `INSERT` queries. Pull request [#122](https://github.com/mymarilyn/clickhouse-driver/pull/122) by [Anexen](https://github.com/Anexen). - Memory consumption decreased (up to 20% compared to 0.1.2 release). Pull request [#122](https://github.com/mymarilyn/clickhouse-driver/pull/122) by [Anexen](https://github.com/Anexen). ## [0.1.2] - 2019-10-18 ### Added - Settings update to 19.16.1 server version. Pull request [#111](https://github.com/mymarilyn/clickhouse-driver/pull/111) by [azat](https://github.com/azat). - Python 3.8 in Travis CI build matrix. - Returning inserted rows count on `INSERT` queries with data. Returning rows count from `INSERT FROM SELECT` is not supported. ### Fixed - Exposing `columnar` parameter to `execute_with_progress`. Pull request [#108](https://github.com/mymarilyn/clickhouse-driver/pull/108) by [igorbb](https://github.com/igorbb). - LowCardinality tests. Pull request [#112](https://github.com/mymarilyn/clickhouse-driver/pull/112) by [azat](https://github.com/azat). ### Changed - Increased speed (up to 5 times compared to 0.1.1 release) of `INSERT` queries. - Date/DateTime columns selecting and inserting optimizations. ## [0.1.1] - 2019-09-20 ### Added - `Client.from_url` method that creates client configured from the given URL. ### Fixed - If source column was timezone-aware values from DateTime column are returned with timezone now. - Handling zero bytes in the middle of FixedString column. Issue [#104](https://github.com/mymarilyn/clickhouse-driver/issues/104). ## [0.1.0] - 2019-08-07 ### Added - SimpleAggregateFunction type. Pull request [#95](https://github.com/mymarilyn/clickhouse-driver/pull/95) by [azat](https://github.com/azat). ### Changed - Increased speed (5-6 times compared to 0.0.20 release) of `SELECT` queries with large amount of strings. - Package is distributed in source and binary forms now. Compilation from source is required for platforms without wheels. ### Fixed - Elapsed time calculation on INSERT. - Dependencies environment markers for poetry in `setup.py`. Pull request [#96](https://github.com/mymarilyn/clickhouse-driver/pull/96) by [nitoqq](https://github.com/nitoqq). ## [0.0.20] - 2019-06-02 ### Added - LowCardinality(T) type. - Access for processed rows, bytes and elapsed time of the last executed query. - Allow to insert `datetime` into Date column. Pull request [#75](https://github.com/mymarilyn/clickhouse-driver/pull/75) by [gle4er](https://github.com/gle4er). - 'max_partitions_per_insert_block' setting. Pull request [#85](https://github.com/mymarilyn/clickhouse-driver/pull/85) by [mhsekhavat](https://github.com/mhsekhavat). ### Fixed - Fallback for user name if it's not defined. Pull request [#87](https://github.com/mymarilyn/clickhouse-driver/pull/87) by [wawaka](https://github.com/wawaka). ## [0.0.19] - 2019-03-31 ### Added - IPv4/IPv6 types. Pull request [#73](https://github.com/mymarilyn/clickhouse-driver/pull/73) by [AchilleAsh](https://github.com/AchilleAsh). ### Fixed - String enums escaping. ## [0.0.18] - 2019-02-19 ### Fixed - Strings mishandling read from buffer. Pull request [#72](https://github.com/mymarilyn/clickhouse-driver/pull/72) by [mitsuhiko](https://github.com/mitsuhiko). ## [0.0.17] - 2019-01-09 ### Added - Server logs displaying. - Documentation on Read the Docs: https://clickhouse-driver.readthedocs.io ### Changed - Protocol version bumped to 54406. ### Fixed - INSERT generators support as data parameter. - INSERT null value on ByteString column. Pull request [#65](https://github.com/mymarilyn/clickhouse-driver/pull/65) by [vivienm](https://github.com/vivienm). - Integer types support in FloatColumn. - Handle quotes and equation signs in Enum options. Pull request [#67](https://github.com/mymarilyn/clickhouse-driver/pull/67) by [sochi](https://github.com/sochi). ## [0.0.16] - 2018-10-09 ### Added - Option to access profile info about the last executed query. Pull request [#57](https://github.com/mymarilyn/clickhouse-driver/pull/57) by [vanzi](https://github.com/vanzi). - Decimal type. - Settings update to 18.14.2 server version. ### Changed - String column read/write optimizations. - Protocol version bumped to 54401. ### Fixed - Client settings are not mutable now. ## [0.0.15] - 2018-09-26 ### Fixed - Unpin `clickhouse-cityhash` dependency. ## [0.0.14] - 2018-08-16 ### Added - Block by block results streaming. ## [0.0.13] - 2018-07-26 ### Fixed - Revert pull request [#45](https://github.com/mymarilyn/clickhouse-driver/pull/45) by [shotInLeg](https://github.com/shotInLeg) due to `INSERT FROM SELECT` breaking. ## [0.0.12] - 2018-07-25 ### Added - Allow for access of final progress stats. Pull request [#41](https://github.com/mymarilyn/clickhouse-driver/pull/41) by [alex-hofsteede](https://github.com/alex-hofsteede). - Supplying raw integers in DateTime columns. Pull request [#42](https://github.com/mymarilyn/clickhouse-driver/pull/42) by [wawaka](https://github.com/wawaka). ### Fixed - Pip install in editable mode. ### Changed - Raise ValueError instead of timeout for INSERT queries without params. Pull request [#45](https://github.com/mymarilyn/clickhouse-driver/pull/45) by [shotInLeg](https://github.com/shotInLeg). ## [0.0.11] - 2018-06-03 ### Added - Timezone support in DateTime type. - Python 3.7 and PyPy in Travis CI build matrix. - Direct bytes support in FixedString. Pull request [#26](https://github.com/mymarilyn/clickhouse-driver/pull/26) by [lidalei](https://github.com/lidalei). ### Removed - Python 3.3 support. ## [0.0.10] - 2018-03-14 ### Added - Server version specific tests. - Nothing type. - Travis CI build matrix. ### Fixed - Possible IndexError in packet types string representation. Pull request [#28](https://github.com/mymarilyn/clickhouse-driver/pull/28) by [WouldYouKindly](https://github.com/WouldYouKindly). - Do not use timezone in Date columns. Issue [#29](https://github.com/mymarilyn/clickhouse-driver/issues/29). - Approximate rows to read calculation in `execute_with_progress`. Pull request [#30](https://github.com/mymarilyn/clickhouse-driver/pull/30) by [b1naryth1ef](https://github.com/b1naryth1ef). ### Changed - List and Tuple types rendering in parameters substitution. Pull request [#27](https://github.com/mymarilyn/clickhouse-driver/pull/27) by [silentsokolov](https://github.com/silentsokolov). ## [0.0.9] - 2018-01-17 ### Added - Interval type. Pull request [#16](https://github.com/mymarilyn/clickhouse-driver/pull/16) by [kszucs](https://github.com/kszucs). ### Fixed - Raise EOFError when no data is read in `_read_one` in Python 3. - SSL file descriptors closing in Python 2.7. ### Changed - Log level for normal operations raised to DEBUG. Pull request [#17](https://github.com/mymarilyn/clickhouse-driver/pull/17) by [kmatt](https://github.com/kmatt). ### Removed - Drop Python 3.2 support due to lz4 issues. ## [0.0.8] - 2017-10-23 ### Added - Parameters substitution for SELECT queries. - SSL support. ### Fixed - Columnar result returning from multiple blocks. Columns must be concatenated. - Settings logger was root. - Reading/writing Array(String) NotImplementedError raise. - IPv6 support issue [#12](https://github.com/mymarilyn/clickhouse-driver/issues/12). ## [0.0.7] - 2017-10-12 ### Added - Configurable logging level in tests. - Full error codes list. - Force check clickhouse-cityhash is installed if compression is used. - `Client` can be directly imported from package. - `insert_block_size` parameter - maximum rows in block (default is 1048576). - Columnar result returning (`columnar=True`). Pull request [#11](https://github.com/mymarilyn/clickhouse-driver/pull/11) by [kszucs](https://github.com/kszucs). - Tunable types check (`types_check=True`). Off by default. ### Changed - Handling only socket-related errors on ping. Errors are logged with `WARNING` level. - Client is created per one test. - Sending/receiving data speed significantly increased. ### Fixed - Version detection in setup.py. - Error handling on socket.shutdown. - Install `enum34` only if required. - `clickhouse-cityhash` import issue [#10](https://github.com/mymarilyn/clickhouse-driver/issues/10). ### Removed - QuickLZ support - six dependency ## [0.0.6] - 2017-09-19 ### Added - UUID type. - Query limits settings. - Code coverage. - ClickHouse server and driver version upped to 54276. - Changelog. - Added column name to `TypeMismatchError`. - Query progress information. - Version of package. ### Fixed - socket.timeout error handling on connect. ## [0.0.5] - 2017-07-16 ### Added - Nullable(T) type. - Return data from TOTALS and EXTREMES packets. - Query settings. - query_id execution option. - NULL type. - Raise exception on SELECT queries. ### Changed - Small columns refactoring. - `clickhouse-client` in tests moved to docker. ## [0.0.4] - 2017-06-15 ### Added - FixedString(N) type. - Enum8/16 types. - Array(T) type. - External data for query processing - Raise UnknownTypeError for unsupported columns. ### Changed - Socket connect timeout fix. ## [0.0.3] - 2017-05-24 ### Added - QuickLZ, LZ4/LZ4HC, ZSTD compressions. - Support old servers without BlockInfo. - Travis CI. - flake8 syntax check. ## 0.0.2 - 2017-05-16 ### Added - [U]Int8/16/32/64 types. - Date/DateTime types. - String types. [Unreleased]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.3...HEAD [0.2.3]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.2...0.2.3 [0.2.2]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.1...0.2.2 [0.2.1]: https://github.com/mymarilyn/clickhouse-driver/compare/0.2.0...0.2.1 [0.2.0]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.5...0.2.0 [0.1.5]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.4...0.1.5 [0.1.4]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.3...0.1.4 [0.1.3]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.2...0.1.3 [0.1.2]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.1...0.1.2 [0.1.1]: https://github.com/mymarilyn/clickhouse-driver/compare/0.1.0...0.1.1 [0.1.0]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.20...0.1.0 [0.0.20]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.19...0.0.20 [0.0.19]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.18...0.0.19 [0.0.18]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.17...0.0.18 [0.0.17]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.16...0.0.17 [0.0.16]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.15...0.0.16 [0.0.15]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.14...0.0.15 [0.0.14]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.13...0.0.14 [0.0.13]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.12...0.0.13 [0.0.12]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.11...0.0.12 [0.0.11]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.10...0.0.11 [0.0.10]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.9...0.0.10 [0.0.9]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.8...0.0.9 [0.0.8]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.7...0.0.8 [0.0.7]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.6...0.0.7 [0.0.6]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.5...0.0.6 [0.0.5]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.4...0.0.5 [0.0.4]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.3...0.0.4 [0.0.3]: https://github.com/mymarilyn/clickhouse-driver/compare/0.0.2...0.0.3 python-clickhouse-driver-0.2.3/CONTRIBUTING.rst000066400000000000000000000007301420676740400211300ustar00rootroot00000000000000How to Contribute ================= #. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. #. Fork `the repository `_ on GitHub to start making your changes to the **master** branch (or branch off of it). #. Write a test which shows that the bug was fixed or that the feature works as expected. #. Send a pull request and bug the maintainer until it gets merged and published. python-clickhouse-driver-0.2.3/LICENSE000066400000000000000000000021671420676740400175020ustar00rootroot00000000000000This is the MIT license: http://www.opensource.org/licenses/mit-license.php Copyright (c) 2017 by Konstantin Lebedev. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. python-clickhouse-driver-0.2.3/MANIFEST.in000066400000000000000000000000521420676740400202220ustar00rootroot00000000000000recursive-include clickhouse_driver *.pyx python-clickhouse-driver-0.2.3/README.rst000066400000000000000000000076561420676740400201740ustar00rootroot00000000000000ClickHouse Python Driver ======================== .. image:: https://img.shields.io/pypi/v/clickhouse-driver.svg :target: https://pypi.org/project/clickhouse-driver .. image:: https://coveralls.io/repos/github/mymarilyn/clickhouse-driver/badge.svg?branch=master :target: https://coveralls.io/github/mymarilyn/clickhouse-driver?branch=master .. image:: https://img.shields.io/pypi/l/clickhouse-driver.svg :target: https://pypi.org/project/clickhouse-driver .. image:: https://img.shields.io/pypi/pyversions/clickhouse-driver.svg :target: https://pypi.org/project/clickhouse-driver .. image:: https://img.shields.io/pypi/dm/clickhouse-driver.svg :target: https://pypi.org/project/clickhouse-driver .. image:: https://github.com/mymarilyn/clickhouse-driver/actions/workflows/actions.yml/badge.svg :target: https://github.com/mymarilyn/clickhouse-driver/actions/workflows/actions.yml ClickHouse Python Driver with native (TCP) interface support. Asynchronous wrapper is available here: https://github.com/mymarilyn/aioch Features ======== - External data for query processing. - Query settings. - Compression support. - TLS support. - Types support: * Float32/64 * [U]Int8/16/32/64/128/256 * Date/Date32/DateTime('timezone')/DateTime64('timezone') * String/FixedString(N) * Enum8/16 * Array(T) * Nullable(T) * Bool * UUID * Decimal * IPv4/IPv6 * LowCardinality(T) * SimpleAggregateFunction(F, T) * Tuple(T1, T2, ...) * Nested * Map(key, value) - Query progress information. - Block by block results streaming. - Reading query profile info. - Receiving server logs. - Multiple hosts support. - Python DB API 2.0 specification support. - Optional NumPy arrays support. Documentation ============= Documentation is available at https://clickhouse-driver.readthedocs.io. Usage ===== There are two ways to communicate with server: - using pure Client; - using DB API. Pure Client example: .. code-block:: python >>> from clickhouse_driver import Client >>> >>> client = Client('localhost') >>> >>> client.execute('SHOW TABLES') [('test',)] >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute('CREATE TABLE test (x Int32) ENGINE = Memory') [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [{'x': 100}] ... ) 1 >>> client.execute('INSERT INTO test (x) VALUES', [[200]]) 1 >>> client.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 3} ... ) [] >>> client.execute('SELECT sum(x) FROM test') [(303,)] DB API example: .. code-block:: python >>> from clickhouse_driver import connect >>> >>> conn = connect('clickhouse://localhost') >>> cursor = conn.cursor() >>> >>> cursor.execute('SHOW TABLES') >>> cursor.fetchall() [('test',)] >>> cursor.execute('DROP TABLE IF EXISTS test') >>> cursor.fetchall() [] >>> cursor.execute('CREATE TABLE test (x Int32) ENGINE = Memory') >>> cursor.fetchall() [] >>> cursor.executemany( ... 'INSERT INTO test (x) VALUES', ... [{'x': 100}] ... ) >>> cursor.rowcount 1 >>> cursor.executemany('INSERT INTO test (x) VALUES', [[200]]) >>> cursor.rowcount 1 >>> cursor.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 3} ... ) >>> cursor.rowcount 0 >>> cursor.execute('SELECT sum(x) FROM test') >>> cursor.fetchall() [(303,)] License ======= ClickHouse Python Driver is distributed under the `MIT license `_. python-clickhouse-driver-0.2.3/clickhouse_driver/000077500000000000000000000000001420676740400221735ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/__init__.py000066400000000000000000000002361420676740400243050ustar00rootroot00000000000000 from .client import Client from .dbapi import connect VERSION = (0, 2, 3) __version__ = '.'.join(str(x) for x in VERSION) __all__ = ['Client', 'connect'] python-clickhouse-driver-0.2.3/clickhouse_driver/block.py000066400000000000000000000141071420676740400236420ustar00rootroot00000000000000from .reader import read_varint, read_binary_uint8, read_binary_int32 from .varint import write_varint from .writer import write_binary_uint8, write_binary_int32 from .columns import nestedcolumn class BlockInfo(object): is_overflows = False bucket_num = -1 def write(self, buf): # Set of pairs (`FIELD_NUM`, value) in binary form. Then 0. write_varint(1, buf) write_binary_uint8(self.is_overflows, buf) write_varint(2, buf) write_binary_int32(self.bucket_num, buf) write_varint(0, buf) def read(self, buf): while True: field_num = read_varint(buf) if not field_num: break if field_num == 1: self.is_overflows = bool(read_binary_uint8(buf)) elif field_num == 2: self.bucket_num = read_binary_int32(buf) class BaseBlock(object): def __init__(self, columns_with_types=None, data=None, info=None, types_check=False): self.columns_with_types = columns_with_types or [] self.types_check = types_check self.info = info or BlockInfo() self.data = self.normalize(data or []) super(BaseBlock, self).__init__() def normalize(self, data): return data @property def num_columns(self): raise NotImplementedError @property def num_rows(self): raise NotImplementedError def get_columns(self): raise NotImplementedError def get_rows(self): raise NotImplementedError def get_column_by_index(self, index): raise NotImplementedError def transposed(self): return list(zip(*self.data)) class ColumnOrientedBlock(BaseBlock): def normalize(self, data): if not data: return [] self._check_number_of_columns(data) self._check_all_columns_equal_length(data) return data @property def num_columns(self): return len(self.data) @property def num_rows(self): return len(self.data[0]) if self.num_columns else 0 def get_columns(self): return self.data def get_rows(self): return self.transposed() def get_column_by_index(self, index): return self.data[index] def _check_number_of_columns(self, data): expected_row_len = len(self.columns_with_types) got = len(data) if expected_row_len != got: msg = 'Expected {} columns, got {}'.format(expected_row_len, got) raise ValueError(msg) def _check_all_columns_equal_length(self, data): expected = len(data[0]) for column in data: got = len(column) if got != expected: msg = 'Expected {} rows, got {}'.format(expected, got) raise ValueError(msg) class RowOrientedBlock(BaseBlock): dict_row_types = (dict, ) tuple_row_types = (list, tuple) supported_row_types = dict_row_types + tuple_row_types def normalize(self, data): if not data: return [] # Guessing about whole data format by first row. first_row = data[0] if self.types_check: self._check_row_type(first_row) if isinstance(first_row, dict): self._mutate_dicts_to_rows(data) else: self._check_rows(data) return data @property def num_columns(self): if self.columns_with_types is not None: return len(self.columns_with_types) return len(self.data[0]) if self.num_rows else 0 @property def num_rows(self): return len(self.data) def get_columns(self): return self.transposed() def get_rows(self): return self.data def get_column_by_index(self, index): return [row[index] for row in self.data] def _mutate_dicts_to_rows(self, data): check_row_type = False if self.types_check: check_row_type = self._check_dict_row_type return self._pure_mutate_dicts_to_rows( data, self.columns_with_types, check_row_type, ) def _pure_mutate_dicts_to_rows( self, data, columns_with_types, check_row_type, ): columns_with_cwt = [] for name, type_ in columns_with_types: cwt = None if type_.startswith('Nested'): cwt = nestedcolumn.get_columns_with_types(type_) columns_with_cwt.append((name, cwt)) for i, row in enumerate(data): if check_row_type: check_row_type(row) new_data = [] for name, cwt in columns_with_cwt: if cwt is None: new_data.append(row[name]) else: new_data.append(self._pure_mutate_dicts_to_rows( row[name], cwt, check_row_type )) data[i] = new_data # return for recursion return data def _check_rows(self, data): expected_row_len = len(self.columns_with_types) got = len(data[0]) if expected_row_len != got: msg = 'Expected {} columns, got {}'.format(expected_row_len, got) raise ValueError(msg) if self.types_check: check_row_type = self._check_tuple_row_type for row in data: check_row_type(row) def _check_row_type(self, row): if not isinstance(row, self.supported_row_types): raise TypeError( 'Unsupported row type: {}. dict, list or tuple is expected.' .format(type(row)) ) def _check_tuple_row_type(self, row): if not isinstance(row, self.tuple_row_types): raise TypeError( 'Unsupported row type: {}. list or tuple is expected.' .format(type(row)) ) def _check_dict_row_type(self, row): if not isinstance(row, self.dict_row_types): raise TypeError( 'Unsupported row type: {}. dict is expected.' .format(type(row)) ) python-clickhouse-driver-0.2.3/clickhouse_driver/blockstreamprofileinfo.py000066400000000000000000000013101420676740400273030ustar00rootroot00000000000000from .reader import read_binary_uint8 from .varint import read_varint class BlockStreamProfileInfo(object): def __init__(self): self.rows = 0 self.blocks = 0 self.bytes = 0 self.applied_limit = False # bool self.rows_before_limit = 0 self.calculated_rows_before_limit = 0 # bool super(BlockStreamProfileInfo, self).__init__() def read(self, fin): self.rows = read_varint(fin) self.blocks = read_varint(fin) self.bytes = read_varint(fin) self.applied_limit = bool(read_binary_uint8(fin)) self.rows_before_limit = read_varint(fin) self.calculated_rows_before_limit = bool(read_binary_uint8(fin)) python-clickhouse-driver-0.2.3/clickhouse_driver/bufferedreader.c000066400000000000000000015717571420676740400253330ustar00rootroot00000000000000/* Generated by Cython 0.29.21 */ /* BEGIN: Cython Metadata { "distutils": { "depends": [], "name": "clickhouse_driver.bufferedreader", "sources": [ "clickhouse_driver/bufferedreader.pyx" ] }, "module_name": "clickhouse_driver.bufferedreader" } END: Cython Metadata */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else #define CYTHON_ABI "0_29_21" #define CYTHON_HEX_VERSION 0x001D15F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #define __PYX_COMMA , #ifndef HAVE_LONG_LONG #if PY_VERSION_HEX >= 0x02070000 #define HAVE_LONG_LONG #endif #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #if PY_VERSION_HEX < 0x03050000 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #undef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #undef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 1 #undef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 0 #undef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 0 #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) #define CYTHON_USE_PYTYPE_LOOKUP 1 #endif #if PY_MAJOR_VERSION < 3 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 #endif #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #if PY_VERSION_HEX < 0x030300F0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #elif !defined(CYTHON_USE_UNICODE_WRITER) #define CYTHON_USE_UNICODE_WRITER 1 #endif #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #ifndef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 1 #endif #ifndef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 1 #endif #ifndef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) #endif #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #ifndef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) #endif #endif #if !defined(CYTHON_FAST_PYCCALL) #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) #endif #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #undef SHIFT #undef BASE #undef MASK #ifdef SIZEOF_VOID_P enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; #endif #endif #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_cpp_attribute #define __has_cpp_attribute(x) 0 #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif #ifndef CYTHON_MAYBE_UNUSED_VAR # if defined(__cplusplus) template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } # else # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) # endif #endif #ifndef CYTHON_NCP_UNUSED # if CYTHON_COMPILING_IN_CPYTHON # define CYTHON_NCP_UNUSED # else # define CYTHON_NCP_UNUSED CYTHON_UNUSED # endif #endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifdef _MSC_VER #ifndef _MSC_STDINT_H_ #if _MSC_VER < 1300 typedef unsigned char uint8_t; typedef unsigned int uint32_t; #else typedef unsigned __int8 uint8_t; typedef unsigned __int32 uint32_t; #endif #endif #else #include #endif #ifndef CYTHON_FALLTHROUGH #if defined(__cplusplus) && __cplusplus >= 201103L #if __has_cpp_attribute(fallthrough) #define CYTHON_FALLTHROUGH [[fallthrough]] #elif __has_cpp_attribute(clang::fallthrough) #define CYTHON_FALLTHROUGH [[clang::fallthrough]] #elif __has_cpp_attribute(gnu::fallthrough) #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] #endif #endif #ifndef CYTHON_FALLTHROUGH #if __has_attribute(fallthrough) #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) #else #define CYTHON_FALLTHROUGH #endif #endif #if defined(__clang__ ) && defined(__apple_build_version__) #if __apple_build_version__ < 7000000 #undef CYTHON_FALLTHROUGH #define CYTHON_FALLTHROUGH #endif #endif #endif #ifndef CYTHON_INLINE #if defined(__clang__) #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) #elif defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif #ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif #ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #ifndef METH_STACKLESS #define METH_STACKLESS 0 #endif #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) #ifndef METH_FASTCALL #define METH_FASTCALL 0x80 #endif typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames); #else #define __Pyx_PyCFunctionFast _PyCFunctionFast #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) #define PyObject_Realloc(p) PyMem_Realloc(p) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 #define PyMem_RawMalloc(n) PyMem_Malloc(n) #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) #define PyMem_RawFree(p) PyMem_Free(p) #endif #if CYTHON_COMPILING_IN_PYSTON #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) #else #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) #endif #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #elif PY_VERSION_HEX >= 0x03060000 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() #elif PY_VERSION_HEX >= 0x03000000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #else #define __Pyx_PyThreadState_Current _PyThreadState_Current #endif #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) #include "pythread.h" #define Py_tss_NEEDS_INIT 0 typedef int Py_tss_t; static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { *key = PyThread_create_key(); return 0; } static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); *key = Py_tss_NEEDS_INIT; return key; } static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { PyObject_Free(key); } static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { return *key != Py_tss_NEEDS_INIT; } static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { PyThread_delete_key(*key); *key = Py_tss_NEEDS_INIT; } static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { return PyThread_set_key_value(*key, value); } static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { return PyThread_get_key_value(*key); } #endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else #define __Pyx_PyDict_NewPresized(n) PyDict_New() #endif #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) #else #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) #else #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 #define PyUnicode_1BYTE_KIND 1 #define PyUnicode_2BYTE_KIND 2 #define PyUnicode_4BYTE_KIND 4 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #endif #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)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) #define PyObject_ASCII(o) PyObject_Repr(o) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #if PY_VERSION_HEX >= 0x030900A4 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) #else #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) #endif #if CYTHON_ASSUME_SAFE_MACROS #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) #else #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) #endif #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #if CYTHON_USE_ASYNC_SLOTS #if PY_VERSION_HEX >= 0x030500B1 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #else #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #endif #else #define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef __Pyx_PyAsyncMethodsStruct typedef struct { unaryfunc am_await; unaryfunc am_aiter; unaryfunc am_anext; } __Pyx_PyAsyncMethodsStruct; #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) #define __Pyx_truncl trunc #else #define __Pyx_truncl truncl #endif #define __PYX_MARK_ERR_POS(f_index, lineno) \ { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } #define __PYX_ERR(f_index, lineno, Ln_error) \ { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #define __PYX_HAVE__clickhouse_driver__bufferedreader #define __PYX_HAVE_API__clickhouse_driver__bufferedreader /* Early includes */ #include #include #include "pythread.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) #define CYTHON_WITHOUT_ASSERTIONS #endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_uchar_cast(c) ((unsigned char)c) #define __Pyx_long_cast(x) ((long)x) #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ (sizeof(type) < sizeof(Py_ssize_t)) ||\ (sizeof(type) > sizeof(Py_ssize_t) &&\ likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX) &&\ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ v == (type)PY_SSIZE_T_MIN))) ||\ (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { return (size_t) i < (size_t) limit; } #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) #elif SIZEOF_INT >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) #elif defined (_MSC_VER) #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) #define __Pyx_sst_abs(value) __builtin_llabs(value) #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); #define __Pyx_PySequence_Tuple(obj)\ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_ASSUME_SAFE_MACROS #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) #else #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) #endif #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } static PyObject *__pyx_m = NULL; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_cython_runtime = NULL; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "clickhouse_driver/bufferedreader.pyx", "stringsource", "type.pxd", "bool.pxd", "complex.pxd", }; /*--- Type declarations ---*/ struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader; struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader; struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader; /* "clickhouse_driver/bufferedreader.pyx":10 * * * cdef class BufferedReader(object): # <<<<<<<<<<<<<< * cdef public unsigned long long position, current_buffer_size * cdef public bytearray buffer */ struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader { PyObject_HEAD unsigned PY_LONG_LONG position; unsigned PY_LONG_LONG current_buffer_size; PyObject *buffer; }; /* "clickhouse_driver/bufferedreader.pyx":229 * * * cdef class BufferedSocketReader(BufferedReader): # <<<<<<<<<<<<<< * cdef object sock * */ struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader __pyx_base; PyObject *sock; }; /* "clickhouse_driver/bufferedreader.pyx":243 * * * cdef class CompressedBufferedReader(BufferedReader): # <<<<<<<<<<<<<< * cdef object read_block * */ struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader __pyx_base; PyObject *read_block; }; /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil)\ if (acquire_gil) {\ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ PyGILState_Release(__pyx_gilstate_save);\ } else {\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_XDECREF(tmp);\ } while (0) #define __Pyx_DECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) /* PyObjectGetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* PyCFunctionFastCall.proto */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); #else #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) #endif /* PyFunctionFastCall.proto */ #if CYTHON_FAST_PYCALL #define __Pyx_PyFunction_FastCall(func, args, nargs)\ __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); #else #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) #endif #define __Pyx_BUILD_ASSERT_EXPR(cond)\ (sizeof(char [1 - 2*!(cond)]) - 1) #ifndef Py_MEMBER_SIZE #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) #endif static size_t __pyx_pyframe_localsplus_offset = 0; #include "frameobject.h" #define __Pxy_PyFrame_Initialize_Offsets()\ ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) #define __Pyx_PyFrame_GetLocalsplus(frame)\ (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) #endif /* PyObjectCall.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif /* PyObjectCallMethO.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); #endif /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyObjectCallNoArg.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #else #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif /* PyThreadStateGet.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type #else #define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_assign #define __Pyx_PyErr_Occurred() PyErr_Occurred() #endif /* PyErrFetchRestore.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) #else #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #endif #else #define __Pyx_PyErr_Clear() PyErr_Clear() #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) #endif /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /* GetItemIntByteArray.proto */ #define __Pyx_GetItemInt_ByteArray(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "bytearray index out of range"), -1)) static CYTHON_INLINE int __Pyx_GetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, int wraparound, int boundscheck); /* PyObjectCall2Args.proto */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /* IncludeStringH.proto */ #include /* decode_c_string_utf16.proto */ static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) { int byteorder = 0; return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); } static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) { int byteorder = -1; return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); } static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) { int byteorder = 1; return PyUnicode_DecodeUTF16(s, size, errors, &byteorder); } /* decode_c_string.proto */ static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); /* GetTopmostException.proto */ #if CYTHON_USE_EXC_INFO_STACK static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); #endif /* SaveResetException.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); #else #define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) #endif /* PyErrExceptionMatches.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); #else #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) #endif /* GetException.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #else static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); #endif /* GetAttr.proto */ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /* GetAttr3.proto */ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /* PyDictVersioning.proto */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ (version_var) = __PYX_GET_DICT_VERSION(dict);\ (cache_var) = (value); #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ (VAR) = __pyx_dict_cached_value;\ } else {\ (VAR) = __pyx_dict_cached_value = (LOOKUP);\ __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ }\ } static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); #else #define __PYX_GET_DICT_VERSION(dict) (0) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); #endif /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS #define __Pyx_GetModuleGlobalName(var, name) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } #define __Pyx_GetModuleGlobalNameUncached(var, name) {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); #endif /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /* ImportFrom.proto */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ __Pyx_GetItemInt_Generic(o, to_py_func(i)))) #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); /* HasAttr.proto */ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /* CallNextTpTraverse.proto */ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse); /* CallNextTpClear.proto */ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc); /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr #endif /* PyObject_GenericGetAttr.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr #endif /* PyObjectGetAttrStrNoError.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); /* SetupReduce.proto */ static int __Pyx_setup_reduce(PyObject* type_obj); /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) #else static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); #endif /* CodeObjectCache.proto */ typedef struct { PyCodeObject* code_object; int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); /* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntFromPy.proto */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* FastTypeChecks.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); #else #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /* Module declarations from 'cpython.version' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.type' */ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'libc.string' */ /* Module declarations from 'libc.stdio' */ /* Module declarations from 'cpython.object' */ /* Module declarations from 'cpython.ref' */ /* Module declarations from 'cpython.exc' */ /* Module declarations from 'cpython.module' */ /* Module declarations from 'cpython.mem' */ /* Module declarations from 'cpython.tuple' */ /* Module declarations from 'cpython.list' */ /* Module declarations from 'cpython.sequence' */ /* Module declarations from 'cpython.mapping' */ /* Module declarations from 'cpython.iterator' */ /* Module declarations from 'cpython.number' */ /* Module declarations from 'cpython.int' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; /* Module declarations from 'cpython.long' */ /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.complex' */ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.string' */ /* Module declarations from 'cpython.unicode' */ /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ /* Module declarations from 'cpython.function' */ /* Module declarations from 'cpython.method' */ /* Module declarations from 'cpython.weakref' */ /* Module declarations from 'cpython.getargs' */ /* Module declarations from 'cpython.pythread' */ /* Module declarations from 'cpython.pystate' */ /* Module declarations from 'cpython.cobject' */ /* Module declarations from 'cpython.oldbuffer' */ /* Module declarations from 'cpython.set' */ /* Module declarations from 'cpython.buffer' */ /* Module declarations from 'cpython.bytes' */ /* Module declarations from 'cpython.pycapsule' */ /* Module declarations from 'cpython' */ /* Module declarations from 'cpython.bytearray' */ /* Module declarations from 'clickhouse_driver.bufferedreader' */ static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader = 0; static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader = 0; static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader = 0; static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *, PyObject *); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedSocketReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *, PyObject *); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_CompressedBufferedReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "clickhouse_driver.bufferedreader" extern int __pyx_module_is_main_clickhouse_driver__bufferedreader; int __pyx_module_is_main_clickhouse_driver__bufferedreader = 0; /* Implementation of 'clickhouse_driver.bufferedreader' */ static PyObject *__pyx_builtin_super; static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_object; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_UnicodeDecodeError; static PyObject *__pyx_builtin_EOFError; static const char __pyx_k_new[] = "__new__"; static const char __pyx_k_dict[] = "__dict__"; static const char __pyx_k_init[] = "__init__"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_read[] = "read"; static const char __pyx_k_sock[] = "sock"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_range[] = "range"; static const char __pyx_k_super[] = "super"; static const char __pyx_k_utf_8[] = "utf-8"; static const char __pyx_k_encode[] = "encode"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_length[] = "length"; static const char __pyx_k_object[] = "object"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_update[] = "update"; static const char __pyx_k_bufsize[] = "bufsize"; static const char __pyx_k_n_items[] = "n_items"; static const char __pyx_k_EOFError[] = "EOFError"; static const char __pyx_k_encoding[] = "encoding"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_pyx_type[] = "__pyx_type"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_pyx_state[] = "__pyx_state"; static const char __pyx_k_recv_into[] = "recv_into"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_read_block[] = "read_block"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_BufferedReader[] = "BufferedReader"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_read_into_buffer[] = "read_into_buffer"; static const char __pyx_k_UnicodeDecodeError[] = "UnicodeDecodeError"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; static const char __pyx_k_BufferedSocketReader[] = "BufferedSocketReader"; static const char __pyx_k_CompressedBufferedReader[] = "CompressedBufferedReader"; static const char __pyx_k_pyx_unpickle_BufferedReader[] = "__pyx_unpickle_BufferedReader"; static const char __pyx_k_read_fixed_strings_as_bytes[] = "read_fixed_strings_as_bytes"; static const char __pyx_k_pyx_unpickle_BufferedSocketRea[] = "__pyx_unpickle_BufferedSocketReader"; static const char __pyx_k_pyx_unpickle_CompressedBuffere[] = "__pyx_unpickle_CompressedBufferedReader"; static const char __pyx_k_Incompatible_checksums_s_vs_0x18[] = "Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))"; static const char __pyx_k_Incompatible_checksums_s_vs_0x2a[] = "Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))"; static const char __pyx_k_Incompatible_checksums_s_vs_0xef[] = "Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))"; static const char __pyx_k_Unexpected_EOF_while_reading_byt[] = "Unexpected EOF while reading bytes"; static const char __pyx_k_clickhouse_driver_bufferedreader[] = "clickhouse_driver.bufferedreader"; static PyObject *__pyx_n_s_BufferedReader; static PyObject *__pyx_n_s_BufferedSocketReader; static PyObject *__pyx_n_s_CompressedBufferedReader; static PyObject *__pyx_n_s_EOFError; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x18; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x2a; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xef; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_kp_u_Unexpected_EOF_while_reading_byt; static PyObject *__pyx_n_s_UnicodeDecodeError; static PyObject *__pyx_n_s_bufsize; static PyObject *__pyx_n_s_clickhouse_driver_bufferedreader; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_encoding; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_init; static PyObject *__pyx_n_s_length; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_n_items; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_new; static PyObject *__pyx_n_s_object; static PyObject *__pyx_n_s_pickle; static PyObject *__pyx_n_s_pyx_PickleError; static PyObject *__pyx_n_s_pyx_checksum; static PyObject *__pyx_n_s_pyx_result; static PyObject *__pyx_n_s_pyx_state; static PyObject *__pyx_n_s_pyx_type; static PyObject *__pyx_n_s_pyx_unpickle_BufferedReader; static PyObject *__pyx_n_s_pyx_unpickle_BufferedSocketRea; static PyObject *__pyx_n_s_pyx_unpickle_CompressedBuffere; static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_read; static PyObject *__pyx_n_s_read_block; static PyObject *__pyx_n_s_read_fixed_strings_as_bytes; static PyObject *__pyx_n_s_read_into_buffer; static PyObject *__pyx_n_s_recv_into; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_sock; static PyObject *__pyx_kp_s_stringsource; static PyObject *__pyx_n_s_super; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_update; static PyObject *__pyx_kp_u_utf_8; static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_bufsize); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_2read_into_buffer(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_unread); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6read_one(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_n_items, PyObject *__pyx_v_encoding); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_10read_fixed_strings_as_bytes(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, Py_ssize_t __pyx_v_length); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_12read_fixed_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, Py_ssize_t __pyx_v_length, PyObject *__pyx_v_encoding); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_4__del__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_14__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_16__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self, PyObject *__pyx_v_sock, PyObject *__pyx_v_bufsize); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_2read_into_buffer(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self, PyObject *__pyx_v_read_block, PyObject *__pyx_v_bufsize); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_2read_into_buffer(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_2__pyx_unpickle_BufferedSocketReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_4__pyx_unpickle_CompressedBufferedReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedReader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedSocketReader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_CompressedBufferedReader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_25411819; static PyObject *__pyx_int_44607813; static PyObject *__pyx_int_251251440; static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__2; static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__6; static PyObject *__pyx_codeobj__3; static PyObject *__pyx_codeobj__5; static PyObject *__pyx_codeobj__7; /* Late includes */ /* "clickhouse_driver/bufferedreader.pyx":14 * cdef public bytearray buffer * * def __init__(self, bufsize): # <<<<<<<<<<<<<< * self.buffer = bytearray(bufsize) * */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_bufsize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bufsize,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 14, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); } __pyx_v_bufsize = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 14, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedreader.pyx":15 * * def __init__(self, bufsize): * self.buffer = bytearray(bufsize) # <<<<<<<<<<<<<< * * self.position = 0 */ __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_v_bufsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->buffer); __Pyx_DECREF(__pyx_v_self->buffer); __pyx_v_self->buffer = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":17 * self.buffer = bytearray(bufsize) * * self.position = 0 # <<<<<<<<<<<<<< * self.current_buffer_size = 0 * */ __pyx_v_self->position = 0; /* "clickhouse_driver/bufferedreader.pyx":18 * * self.position = 0 * self.current_buffer_size = 0 # <<<<<<<<<<<<<< * * super(BufferedReader, self).__init__() */ __pyx_v_self->current_buffer_size = 0; /* "clickhouse_driver/bufferedreader.pyx":20 * self.current_buffer_size = 0 * * super(BufferedReader, self).__init__() # <<<<<<<<<<<<<< * * def read_into_buffer(self): */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self)); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":14 * cdef public bytearray buffer * * def __init__(self, bufsize): # <<<<<<<<<<<<<< * self.buffer = bytearray(bufsize) * */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":22 * super(BufferedReader, self).__init__() * * def read_into_buffer(self): # <<<<<<<<<<<<<< * raise NotImplementedError * */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_into_buffer (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_2read_into_buffer(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_2read_into_buffer(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_into_buffer", 0); /* "clickhouse_driver/bufferedreader.pyx":23 * * def read_into_buffer(self): * raise NotImplementedError # <<<<<<<<<<<<<< * * def read(self, unsigned long long unread): */ __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0); __PYX_ERR(0, 23, __pyx_L1_error) /* "clickhouse_driver/bufferedreader.pyx":22 * super(BufferedReader, self).__init__() * * def read_into_buffer(self): # <<<<<<<<<<<<<< * raise NotImplementedError * */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_into_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":25 * raise NotImplementedError * * def read(self, unsigned long long unread): # <<<<<<<<<<<<<< * # When the buffer is large enough bytes read are almost * # always hit the buffer. */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_arg_unread); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_arg_unread) { unsigned PY_LONG_LONG __pyx_v_unread; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read (wrapper)", 0); assert(__pyx_arg_unread); { __pyx_v_unread = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_arg_unread); if (unlikely((__pyx_v_unread == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((unsigned PY_LONG_LONG)__pyx_v_unread)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_unread) { unsigned PY_LONG_LONG __pyx_v_next_position; unsigned PY_LONG_LONG __pyx_v_t; char *__pyx_v_buffer_ptr; unsigned PY_LONG_LONG __pyx_v_read_bytes; PyObject *__pyx_v_rv = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; unsigned PY_LONG_LONG __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; unsigned PY_LONG_LONG __pyx_t_6; unsigned PY_LONG_LONG __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read", 0); /* "clickhouse_driver/bufferedreader.pyx":28 * # When the buffer is large enough bytes read are almost * # always hit the buffer. * cdef unsigned long long next_position = unread + self.position # <<<<<<<<<<<<<< * if next_position < self.current_buffer_size: * t = self.position */ __pyx_v_next_position = (__pyx_v_unread + __pyx_v_self->position); /* "clickhouse_driver/bufferedreader.pyx":29 * # always hit the buffer. * cdef unsigned long long next_position = unread + self.position * if next_position < self.current_buffer_size: # <<<<<<<<<<<<<< * t = self.position * self.position = next_position */ __pyx_t_1 = ((__pyx_v_next_position < __pyx_v_self->current_buffer_size) != 0); if (__pyx_t_1) { /* "clickhouse_driver/bufferedreader.pyx":30 * cdef unsigned long long next_position = unread + self.position * if next_position < self.current_buffer_size: * t = self.position # <<<<<<<<<<<<<< * self.position = next_position * return bytes(self.buffer[t:self.position]) */ __pyx_t_2 = __pyx_v_self->position; __pyx_v_t = __pyx_t_2; /* "clickhouse_driver/bufferedreader.pyx":31 * if next_position < self.current_buffer_size: * t = self.position * self.position = next_position # <<<<<<<<<<<<<< * return bytes(self.buffer[t:self.position]) * */ __pyx_v_self->position = __pyx_v_next_position; /* "clickhouse_driver/bufferedreader.pyx":32 * t = self.position * self.position = next_position * return bytes(self.buffer[t:self.position]) # <<<<<<<<<<<<<< * * cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) */ __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_self->buffer == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 32, __pyx_L1_error) } __pyx_t_3 = PySequence_GetSlice(__pyx_v_self->buffer, __pyx_v_t, __pyx_v_self->position); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":29 * # always hit the buffer. * cdef unsigned long long next_position = unread + self.position * if next_position < self.current_buffer_size: # <<<<<<<<<<<<<< * t = self.position * self.position = next_position */ } /* "clickhouse_driver/bufferedreader.pyx":34 * return bytes(self.buffer[t:self.position]) * * cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) # <<<<<<<<<<<<<< * cdef unsigned long long read_bytes * rv = bytes() */ __pyx_t_4 = __pyx_v_self->buffer; __Pyx_INCREF(__pyx_t_4); __pyx_v_buffer_ptr = PyByteArray_AsString(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedreader.pyx":36 * cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) * cdef unsigned long long read_bytes * rv = bytes() # <<<<<<<<<<<<<< * * while unread > 0: */ __pyx_t_4 = __Pyx_PyObject_CallNoArg(((PyObject *)(&PyBytes_Type))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_rv = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedreader.pyx":38 * rv = bytes() * * while unread > 0: # <<<<<<<<<<<<<< * if self.position == self.current_buffer_size: * self.read_into_buffer() */ while (1) { __pyx_t_1 = ((__pyx_v_unread > 0) != 0); if (!__pyx_t_1) break; /* "clickhouse_driver/bufferedreader.pyx":39 * * while unread > 0: * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * buffer_ptr = PyByteArray_AsString(self.buffer) */ __pyx_t_1 = ((__pyx_v_self->position == __pyx_v_self->current_buffer_size) != 0); if (__pyx_t_1) { /* "clickhouse_driver/bufferedreader.pyx":40 * while unread > 0: * if self.position == self.current_buffer_size: * self.read_into_buffer() # <<<<<<<<<<<<<< * buffer_ptr = PyByteArray_AsString(self.buffer) * self.position = 0 */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read_into_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedreader.pyx":41 * if self.position == self.current_buffer_size: * self.read_into_buffer() * buffer_ptr = PyByteArray_AsString(self.buffer) # <<<<<<<<<<<<<< * self.position = 0 * */ __pyx_t_4 = __pyx_v_self->buffer; __Pyx_INCREF(__pyx_t_4); __pyx_v_buffer_ptr = PyByteArray_AsString(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedreader.pyx":42 * self.read_into_buffer() * buffer_ptr = PyByteArray_AsString(self.buffer) * self.position = 0 # <<<<<<<<<<<<<< * * read_bytes = min(unread, self.current_buffer_size - self.position) */ __pyx_v_self->position = 0; /* "clickhouse_driver/bufferedreader.pyx":39 * * while unread > 0: * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * buffer_ptr = PyByteArray_AsString(self.buffer) */ } /* "clickhouse_driver/bufferedreader.pyx":44 * self.position = 0 * * read_bytes = min(unread, self.current_buffer_size - self.position) # <<<<<<<<<<<<<< * rv += PyBytes_FromStringAndSize( * &buffer_ptr[self.position], read_bytes */ __pyx_t_2 = (__pyx_v_self->current_buffer_size - __pyx_v_self->position); __pyx_t_6 = __pyx_v_unread; if (((__pyx_t_2 < __pyx_t_6) != 0)) { __pyx_t_7 = __pyx_t_2; } else { __pyx_t_7 = __pyx_t_6; } __pyx_v_read_bytes = __pyx_t_7; /* "clickhouse_driver/bufferedreader.pyx":45 * * read_bytes = min(unread, self.current_buffer_size - self.position) * rv += PyBytes_FromStringAndSize( # <<<<<<<<<<<<<< * &buffer_ptr[self.position], read_bytes * ) */ __pyx_t_4 = PyBytes_FromStringAndSize((&(__pyx_v_buffer_ptr[__pyx_v_self->position])), __pyx_v_read_bytes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_rv, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_rv, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":48 * &buffer_ptr[self.position], read_bytes * ) * self.position += read_bytes # <<<<<<<<<<<<<< * unread -= read_bytes * */ __pyx_v_self->position = (__pyx_v_self->position + __pyx_v_read_bytes); /* "clickhouse_driver/bufferedreader.pyx":49 * ) * self.position += read_bytes * unread -= read_bytes # <<<<<<<<<<<<<< * * return rv */ __pyx_v_unread = (__pyx_v_unread - __pyx_v_read_bytes); } /* "clickhouse_driver/bufferedreader.pyx":51 * unread -= read_bytes * * return rv # <<<<<<<<<<<<<< * * def read_one(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_rv); __pyx_r = __pyx_v_rv; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":25 * raise NotImplementedError * * def read(self, unsigned long long unread): # <<<<<<<<<<<<<< * # When the buffer is large enough bytes read are almost * # always hit the buffer. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_rv); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":53 * return rv * * def read_one(self): # <<<<<<<<<<<<<< * if self.position == self.current_buffer_size: * self.read_into_buffer() */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_7read_one(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_7read_one(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_one (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6read_one(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6read_one(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { unsigned char __pyx_v_rv; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_one", 0); /* "clickhouse_driver/bufferedreader.pyx":54 * * def read_one(self): * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * self.position = 0 */ __pyx_t_1 = ((__pyx_v_self->position == __pyx_v_self->current_buffer_size) != 0); if (__pyx_t_1) { /* "clickhouse_driver/bufferedreader.pyx":55 * def read_one(self): * if self.position == self.current_buffer_size: * self.read_into_buffer() # <<<<<<<<<<<<<< * self.position = 0 * */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read_into_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/bufferedreader.pyx":56 * if self.position == self.current_buffer_size: * self.read_into_buffer() * self.position = 0 # <<<<<<<<<<<<<< * * rv = self.buffer[self.position] */ __pyx_v_self->position = 0; /* "clickhouse_driver/bufferedreader.pyx":54 * * def read_one(self): * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * self.position = 0 */ } /* "clickhouse_driver/bufferedreader.pyx":58 * self.position = 0 * * rv = self.buffer[self.position] # <<<<<<<<<<<<<< * self.position += 1 * return rv */ __pyx_t_5 = __Pyx_GetItemInt_ByteArray(__pyx_v_self->buffer, __pyx_v_self->position, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 58, __pyx_L1_error) __pyx_v_rv = __pyx_t_5; /* "clickhouse_driver/bufferedreader.pyx":59 * * rv = self.buffer[self.position] * self.position += 1 # <<<<<<<<<<<<<< * return rv * */ __pyx_v_self->position = (__pyx_v_self->position + 1); /* "clickhouse_driver/bufferedreader.pyx":60 * rv = self.buffer[self.position] * self.position += 1 * return rv # <<<<<<<<<<<<<< * * def read_strings(self, unsigned long long n_items, encoding=None): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyInt_From_unsigned_char(__pyx_v_rv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":53 * return rv * * def read_one(self): # <<<<<<<<<<<<<< * if self.position == self.current_buffer_size: * self.read_into_buffer() */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_one", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":62 * return rv * * def read_strings(self, unsigned long long n_items, encoding=None): # <<<<<<<<<<<<<< * """ * Python has great overhead between function calls. */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_9read_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings[] = "\n Python has great overhead between function calls.\n We inline strings reading logic here to avoid this overhead.\n "; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_9read_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned PY_LONG_LONG __pyx_v_n_items; PyObject *__pyx_v_encoding = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_strings (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n_items,&__pyx_n_s_encoding,0}; PyObject* values[2] = {0,0}; values[1] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read_strings") < 0)) __PYX_ERR(0, 62, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 62, __pyx_L3_error) __pyx_v_encoding = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_strings", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 62, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), __pyx_v_n_items, __pyx_v_encoding); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_n_items, PyObject *__pyx_v_encoding) { PyObject *__pyx_v_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; char *__pyx_v_buffer_ptr; unsigned PY_LONG_LONG __pyx_v_right; unsigned PY_LONG_LONG __pyx_v_size; unsigned PY_LONG_LONG __pyx_v_shift; unsigned PY_LONG_LONG __pyx_v_bytes_read; unsigned PY_LONG_LONG __pyx_v_b; char *__pyx_v_c_string; unsigned PY_LONG_LONG __pyx_v_c_string_size; char *__pyx_v_c_encoding; PyObject *__pyx_v_rv = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; char *__pyx_t_5; unsigned PY_LONG_LONG __pyx_t_6; unsigned PY_LONG_LONG __pyx_t_7; unsigned PY_LONG_LONG __pyx_t_8; unsigned PY_LONG_LONG __pyx_t_9; unsigned PY_LONG_LONG __pyx_t_10; unsigned PY_LONG_LONG __pyx_t_11; PyObject *__pyx_t_12 = NULL; PyObject *__pyx_t_13 = NULL; PyObject *__pyx_t_14 = NULL; int __pyx_t_15; PyObject *__pyx_t_16 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_strings", 0); __Pyx_INCREF(__pyx_v_encoding); /* "clickhouse_driver/bufferedreader.pyx":67 * We inline strings reading logic here to avoid this overhead. * """ * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * * cdef unsigned long long i */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":71 * cdef unsigned long long i * # Buffer vars * cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) # <<<<<<<<<<<<<< * cdef unsigned long long right * # String length vars */ __pyx_t_1 = __pyx_v_self->buffer; __Pyx_INCREF(__pyx_t_1); __pyx_v_buffer_ptr = PyByteArray_AsString(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":78 * * # String for decode vars. * cdef char *c_string = NULL # <<<<<<<<<<<<<< * cdef unsigned long long c_string_size = 1024 * cdef char *c_encoding = NULL */ __pyx_v_c_string = NULL; /* "clickhouse_driver/bufferedreader.pyx":79 * # String for decode vars. * cdef char *c_string = NULL * cdef unsigned long long c_string_size = 1024 # <<<<<<<<<<<<<< * cdef char *c_encoding = NULL * if encoding: */ __pyx_v_c_string_size = 0x400; /* "clickhouse_driver/bufferedreader.pyx":80 * cdef char *c_string = NULL * cdef unsigned long long c_string_size = 1024 * cdef char *c_encoding = NULL # <<<<<<<<<<<<<< * if encoding: * encoding = encoding.encode('utf-8') */ __pyx_v_c_encoding = NULL; /* "clickhouse_driver/bufferedreader.pyx":81 * cdef unsigned long long c_string_size = 1024 * cdef char *c_encoding = NULL * if encoding: # <<<<<<<<<<<<<< * encoding = encoding.encode('utf-8') * c_encoding = encoding */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_encoding); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 81, __pyx_L1_error) if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":82 * cdef char *c_encoding = NULL * if encoding: * encoding = encoding.encode('utf-8') # <<<<<<<<<<<<<< * c_encoding = encoding * */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_encoding, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_utf_8); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_encoding, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":83 * if encoding: * encoding = encoding.encode('utf-8') * c_encoding = encoding # <<<<<<<<<<<<<< * * cdef object rv = object() */ __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_encoding); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 83, __pyx_L1_error) __pyx_v_c_encoding = __pyx_t_5; /* "clickhouse_driver/bufferedreader.pyx":81 * cdef unsigned long long c_string_size = 1024 * cdef char *c_encoding = NULL * if encoding: # <<<<<<<<<<<<<< * encoding = encoding.encode('utf-8') * c_encoding = encoding */ } /* "clickhouse_driver/bufferedreader.pyx":85 * c_encoding = encoding * * cdef object rv = object() # <<<<<<<<<<<<<< * # String for decode vars. * if c_encoding: */ __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_rv = __pyx_t_1; __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":87 * cdef object rv = object() * # String for decode vars. * if c_encoding: # <<<<<<<<<<<<<< * c_string = PyMem_Realloc(NULL, c_string_size) * */ __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":88 * # String for decode vars. * if c_encoding: * c_string = PyMem_Realloc(NULL, c_string_size) # <<<<<<<<<<<<<< * * for i in range(n_items): */ __pyx_v_c_string = ((char *)PyMem_Realloc(NULL, __pyx_v_c_string_size)); /* "clickhouse_driver/bufferedreader.pyx":87 * cdef object rv = object() * # String for decode vars. * if c_encoding: # <<<<<<<<<<<<<< * c_string = PyMem_Realloc(NULL, c_string_size) * */ } /* "clickhouse_driver/bufferedreader.pyx":90 * c_string = PyMem_Realloc(NULL, c_string_size) * * for i in range(n_items): # <<<<<<<<<<<<<< * shift = size = 0 * */ __pyx_t_6 = __pyx_v_n_items; __pyx_t_7 = __pyx_t_6; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_i = __pyx_t_8; /* "clickhouse_driver/bufferedreader.pyx":91 * * for i in range(n_items): * shift = size = 0 # <<<<<<<<<<<<<< * * # Read string size */ __pyx_v_shift = 0; __pyx_v_size = 0; /* "clickhouse_driver/bufferedreader.pyx":94 * * # Read string size * while True: # <<<<<<<<<<<<<< * if self.position == self.current_buffer_size: * self.read_into_buffer() */ while (1) { /* "clickhouse_driver/bufferedreader.pyx":95 * # Read string size * while True: * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * # `read_into_buffer` can override buffer */ __pyx_t_2 = ((__pyx_v_self->position == __pyx_v_self->current_buffer_size) != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":96 * while True: * if self.position == self.current_buffer_size: * self.read_into_buffer() # <<<<<<<<<<<<<< * # `read_into_buffer` can override buffer * buffer_ptr = PyByteArray_AsString(self.buffer) */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read_into_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":98 * self.read_into_buffer() * # `read_into_buffer` can override buffer * buffer_ptr = PyByteArray_AsString(self.buffer) # <<<<<<<<<<<<<< * self.position = 0 * */ __pyx_t_1 = __pyx_v_self->buffer; __Pyx_INCREF(__pyx_t_1); __pyx_v_buffer_ptr = PyByteArray_AsString(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":99 * # `read_into_buffer` can override buffer * buffer_ptr = PyByteArray_AsString(self.buffer) * self.position = 0 # <<<<<<<<<<<<<< * * b = buffer_ptr[self.position] */ __pyx_v_self->position = 0; /* "clickhouse_driver/bufferedreader.pyx":95 * # Read string size * while True: * if self.position == self.current_buffer_size: # <<<<<<<<<<<<<< * self.read_into_buffer() * # `read_into_buffer` can override buffer */ } /* "clickhouse_driver/bufferedreader.pyx":101 * self.position = 0 * * b = buffer_ptr[self.position] # <<<<<<<<<<<<<< * self.position += 1 * */ __pyx_v_b = (__pyx_v_buffer_ptr[__pyx_v_self->position]); /* "clickhouse_driver/bufferedreader.pyx":102 * * b = buffer_ptr[self.position] * self.position += 1 # <<<<<<<<<<<<<< * * size |= (b & 0x7f) << shift */ __pyx_v_self->position = (__pyx_v_self->position + 1); /* "clickhouse_driver/bufferedreader.pyx":104 * self.position += 1 * * size |= (b & 0x7f) << shift # <<<<<<<<<<<<<< * if b < 0x80: * break */ __pyx_v_size = (__pyx_v_size | ((__pyx_v_b & 0x7f) << __pyx_v_shift)); /* "clickhouse_driver/bufferedreader.pyx":105 * * size |= (b & 0x7f) << shift * if b < 0x80: # <<<<<<<<<<<<<< * break * */ __pyx_t_2 = ((__pyx_v_b < 0x80) != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":106 * size |= (b & 0x7f) << shift * if b < 0x80: * break # <<<<<<<<<<<<<< * * shift += 7 */ goto __pyx_L8_break; /* "clickhouse_driver/bufferedreader.pyx":105 * * size |= (b & 0x7f) << shift * if b < 0x80: # <<<<<<<<<<<<<< * break * */ } /* "clickhouse_driver/bufferedreader.pyx":108 * break * * shift += 7 # <<<<<<<<<<<<<< * * right = self.position + size */ __pyx_v_shift = (__pyx_v_shift + 7); } __pyx_L8_break:; /* "clickhouse_driver/bufferedreader.pyx":110 * shift += 7 * * right = self.position + size # <<<<<<<<<<<<<< * * if c_encoding: */ __pyx_v_right = (__pyx_v_self->position + __pyx_v_size); /* "clickhouse_driver/bufferedreader.pyx":112 * right = self.position + size * * if c_encoding: # <<<<<<<<<<<<<< * if size + 1 > c_string_size: * c_string_size = size + 1 */ __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":113 * * if c_encoding: * if size + 1 > c_string_size: # <<<<<<<<<<<<<< * c_string_size = size + 1 * c_string = PyMem_Realloc(c_string, c_string_size) */ __pyx_t_2 = (((__pyx_v_size + 1) > __pyx_v_c_string_size) != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":114 * if c_encoding: * if size + 1 > c_string_size: * c_string_size = size + 1 # <<<<<<<<<<<<<< * c_string = PyMem_Realloc(c_string, c_string_size) * if c_string is NULL: */ __pyx_v_c_string_size = (__pyx_v_size + 1); /* "clickhouse_driver/bufferedreader.pyx":115 * if size + 1 > c_string_size: * c_string_size = size + 1 * c_string = PyMem_Realloc(c_string, c_string_size) # <<<<<<<<<<<<<< * if c_string is NULL: * raise MemoryError() */ __pyx_v_c_string = ((char *)PyMem_Realloc(__pyx_v_c_string, __pyx_v_c_string_size)); /* "clickhouse_driver/bufferedreader.pyx":116 * c_string_size = size + 1 * c_string = PyMem_Realloc(c_string, c_string_size) * if c_string is NULL: # <<<<<<<<<<<<<< * raise MemoryError() * c_string[size] = 0 */ __pyx_t_2 = ((__pyx_v_c_string == NULL) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedreader.pyx":117 * c_string = PyMem_Realloc(c_string, c_string_size) * if c_string is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * c_string[size] = 0 * bytes_read = 0 */ PyErr_NoMemory(); __PYX_ERR(0, 117, __pyx_L1_error) /* "clickhouse_driver/bufferedreader.pyx":116 * c_string_size = size + 1 * c_string = PyMem_Realloc(c_string, c_string_size) * if c_string is NULL: # <<<<<<<<<<<<<< * raise MemoryError() * c_string[size] = 0 */ } /* "clickhouse_driver/bufferedreader.pyx":113 * * if c_encoding: * if size + 1 > c_string_size: # <<<<<<<<<<<<<< * c_string_size = size + 1 * c_string = PyMem_Realloc(c_string, c_string_size) */ } /* "clickhouse_driver/bufferedreader.pyx":118 * if c_string is NULL: * raise MemoryError() * c_string[size] = 0 # <<<<<<<<<<<<<< * bytes_read = 0 * */ (__pyx_v_c_string[__pyx_v_size]) = 0; /* "clickhouse_driver/bufferedreader.pyx":119 * raise MemoryError() * c_string[size] = 0 * bytes_read = 0 # <<<<<<<<<<<<<< * * # Decoding pure c strings in Cython is faster than in pure Python. */ __pyx_v_bytes_read = 0; /* "clickhouse_driver/bufferedreader.pyx":112 * right = self.position + size * * if c_encoding: # <<<<<<<<<<<<<< * if size + 1 > c_string_size: * c_string_size = size + 1 */ } /* "clickhouse_driver/bufferedreader.pyx":124 * # We need to copy it into buffer for adding null symbol at the end. * # In ClickHouse block there is no null * if right > self.current_buffer_size: # <<<<<<<<<<<<<< * if c_encoding: * memcpy(&c_string[bytes_read], &buffer_ptr[self.position], */ __pyx_t_2 = ((__pyx_v_right > __pyx_v_self->current_buffer_size) != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":125 * # In ClickHouse block there is no null * if right > self.current_buffer_size: * if c_encoding: # <<<<<<<<<<<<<< * memcpy(&c_string[bytes_read], &buffer_ptr[self.position], * self.current_buffer_size - self.position) */ __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":126 * if right > self.current_buffer_size: * if c_encoding: * memcpy(&c_string[bytes_read], &buffer_ptr[self.position], # <<<<<<<<<<<<<< * self.current_buffer_size - self.position) * else: */ (void)(memcpy((&(__pyx_v_c_string[__pyx_v_bytes_read])), (&(__pyx_v_buffer_ptr[__pyx_v_self->position])), (__pyx_v_self->current_buffer_size - __pyx_v_self->position))); /* "clickhouse_driver/bufferedreader.pyx":125 * # In ClickHouse block there is no null * if right > self.current_buffer_size: * if c_encoding: # <<<<<<<<<<<<<< * memcpy(&c_string[bytes_read], &buffer_ptr[self.position], * self.current_buffer_size - self.position) */ goto __pyx_L15; } /* "clickhouse_driver/bufferedreader.pyx":129 * self.current_buffer_size - self.position) * else: * rv = PyBytes_FromStringAndSize( # <<<<<<<<<<<<<< * &buffer_ptr[self.position], * self.current_buffer_size - self.position */ /*else*/ { /* "clickhouse_driver/bufferedreader.pyx":131 * rv = PyBytes_FromStringAndSize( * &buffer_ptr[self.position], * self.current_buffer_size - self.position # <<<<<<<<<<<<<< * ) * */ __pyx_t_1 = PyBytes_FromStringAndSize((&(__pyx_v_buffer_ptr[__pyx_v_self->position])), (__pyx_v_self->current_buffer_size - __pyx_v_self->position)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_rv, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L15:; /* "clickhouse_driver/bufferedreader.pyx":134 * ) * * bytes_read = self.current_buffer_size - self.position # <<<<<<<<<<<<<< * # Read the rest of the string. * while bytes_read != size: */ __pyx_v_bytes_read = (__pyx_v_self->current_buffer_size - __pyx_v_self->position); /* "clickhouse_driver/bufferedreader.pyx":136 * bytes_read = self.current_buffer_size - self.position * # Read the rest of the string. * while bytes_read != size: # <<<<<<<<<<<<<< * self.position = size - bytes_read * */ while (1) { __pyx_t_2 = ((__pyx_v_bytes_read != __pyx_v_size) != 0); if (!__pyx_t_2) break; /* "clickhouse_driver/bufferedreader.pyx":137 * # Read the rest of the string. * while bytes_read != size: * self.position = size - bytes_read # <<<<<<<<<<<<<< * * self.read_into_buffer() */ __pyx_v_self->position = (__pyx_v_size - __pyx_v_bytes_read); /* "clickhouse_driver/bufferedreader.pyx":139 * self.position = size - bytes_read * * self.read_into_buffer() # <<<<<<<<<<<<<< * # `read_into_buffer` can override buffer * buffer_ptr = PyByteArray_AsString(self.buffer) */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read_into_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":141 * self.read_into_buffer() * # `read_into_buffer` can override buffer * buffer_ptr = PyByteArray_AsString(self.buffer) # <<<<<<<<<<<<<< * # There can be not enough data in buffer. * self.position = min( */ __pyx_t_1 = __pyx_v_self->buffer; __Pyx_INCREF(__pyx_t_1); __pyx_v_buffer_ptr = PyByteArray_AsString(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":144 * # There can be not enough data in buffer. * self.position = min( * self.position, self.current_buffer_size # <<<<<<<<<<<<<< * ) * if c_encoding: */ __pyx_t_9 = __pyx_v_self->current_buffer_size; __pyx_t_10 = __pyx_v_self->position; if (((__pyx_t_9 < __pyx_t_10) != 0)) { __pyx_t_11 = __pyx_t_9; } else { __pyx_t_11 = __pyx_t_10; } /* "clickhouse_driver/bufferedreader.pyx":143 * buffer_ptr = PyByteArray_AsString(self.buffer) * # There can be not enough data in buffer. * self.position = min( # <<<<<<<<<<<<<< * self.position, self.current_buffer_size * ) */ __pyx_v_self->position = __pyx_t_11; /* "clickhouse_driver/bufferedreader.pyx":146 * self.position, self.current_buffer_size * ) * if c_encoding: # <<<<<<<<<<<<<< * memcpy( * &c_string[bytes_read], buffer_ptr, self.position */ __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":147 * ) * if c_encoding: * memcpy( # <<<<<<<<<<<<<< * &c_string[bytes_read], buffer_ptr, self.position * ) */ (void)(memcpy((&(__pyx_v_c_string[__pyx_v_bytes_read])), __pyx_v_buffer_ptr, __pyx_v_self->position)); /* "clickhouse_driver/bufferedreader.pyx":146 * self.position, self.current_buffer_size * ) * if c_encoding: # <<<<<<<<<<<<<< * memcpy( * &c_string[bytes_read], buffer_ptr, self.position */ goto __pyx_L18; } /* "clickhouse_driver/bufferedreader.pyx":151 * ) * else: * rv += PyBytes_FromStringAndSize( # <<<<<<<<<<<<<< * buffer_ptr, self.position * ) */ /*else*/ { /* "clickhouse_driver/bufferedreader.pyx":152 * else: * rv += PyBytes_FromStringAndSize( * buffer_ptr, self.position # <<<<<<<<<<<<<< * ) * bytes_read += self.position */ __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_buffer_ptr, __pyx_v_self->position); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); /* "clickhouse_driver/bufferedreader.pyx":151 * ) * else: * rv += PyBytes_FromStringAndSize( # <<<<<<<<<<<<<< * buffer_ptr, self.position * ) */ __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_rv, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_rv, __pyx_t_3); __pyx_t_3 = 0; } __pyx_L18:; /* "clickhouse_driver/bufferedreader.pyx":154 * buffer_ptr, self.position * ) * bytes_read += self.position # <<<<<<<<<<<<<< * * else: */ __pyx_v_bytes_read = (__pyx_v_bytes_read + __pyx_v_self->position); } /* "clickhouse_driver/bufferedreader.pyx":124 * # We need to copy it into buffer for adding null symbol at the end. * # In ClickHouse block there is no null * if right > self.current_buffer_size: # <<<<<<<<<<<<<< * if c_encoding: * memcpy(&c_string[bytes_read], &buffer_ptr[self.position], */ goto __pyx_L14; } /* "clickhouse_driver/bufferedreader.pyx":157 * * else: * if c_encoding: # <<<<<<<<<<<<<< * memcpy(c_string, &buffer_ptr[self.position], size) * else: */ /*else*/ { __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":158 * else: * if c_encoding: * memcpy(c_string, &buffer_ptr[self.position], size) # <<<<<<<<<<<<<< * else: * rv = PyBytes_FromStringAndSize( */ (void)(memcpy(__pyx_v_c_string, (&(__pyx_v_buffer_ptr[__pyx_v_self->position])), __pyx_v_size)); /* "clickhouse_driver/bufferedreader.pyx":157 * * else: * if c_encoding: # <<<<<<<<<<<<<< * memcpy(c_string, &buffer_ptr[self.position], size) * else: */ goto __pyx_L19; } /* "clickhouse_driver/bufferedreader.pyx":160 * memcpy(c_string, &buffer_ptr[self.position], size) * else: * rv = PyBytes_FromStringAndSize( # <<<<<<<<<<<<<< * &buffer_ptr[self.position], size * ) */ /*else*/ { /* "clickhouse_driver/bufferedreader.pyx":161 * else: * rv = PyBytes_FromStringAndSize( * &buffer_ptr[self.position], size # <<<<<<<<<<<<<< * ) * self.position = right */ __pyx_t_3 = PyBytes_FromStringAndSize((&(__pyx_v_buffer_ptr[__pyx_v_self->position])), __pyx_v_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_rv, __pyx_t_3); __pyx_t_3 = 0; } __pyx_L19:; /* "clickhouse_driver/bufferedreader.pyx":163 * &buffer_ptr[self.position], size * ) * self.position = right # <<<<<<<<<<<<<< * * if c_encoding: */ __pyx_v_self->position = __pyx_v_right; } __pyx_L14:; /* "clickhouse_driver/bufferedreader.pyx":165 * self.position = right * * if c_encoding: # <<<<<<<<<<<<<< * try: * rv = c_string[:size].decode(c_encoding) */ __pyx_t_2 = (__pyx_v_c_encoding != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":166 * * if c_encoding: * try: # <<<<<<<<<<<<<< * rv = c_string[:size].decode(c_encoding) * except UnicodeDecodeError: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14); __Pyx_XGOTREF(__pyx_t_12); __Pyx_XGOTREF(__pyx_t_13); __Pyx_XGOTREF(__pyx_t_14); /*try:*/ { /* "clickhouse_driver/bufferedreader.pyx":167 * if c_encoding: * try: * rv = c_string[:size].decode(c_encoding) # <<<<<<<<<<<<<< * except UnicodeDecodeError: * rv = PyBytes_FromStringAndSize(c_string, size) */ __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_c_string, 0, __pyx_v_size, __pyx_v_c_encoding, NULL, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 167, __pyx_L21_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_rv, __pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":166 * * if c_encoding: * try: # <<<<<<<<<<<<<< * rv = c_string[:size].decode(c_encoding) * except UnicodeDecodeError: */ } __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; goto __pyx_L28_try_end; __pyx_L21_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedreader.pyx":168 * try: * rv = c_string[:size].decode(c_encoding) * except UnicodeDecodeError: # <<<<<<<<<<<<<< * rv = PyBytes_FromStringAndSize(c_string, size) * */ __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError); if (__pyx_t_15) { __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_1, &__pyx_t_4) < 0) __PYX_ERR(0, 168, __pyx_L23_except_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(__pyx_t_4); /* "clickhouse_driver/bufferedreader.pyx":169 * rv = c_string[:size].decode(c_encoding) * except UnicodeDecodeError: * rv = PyBytes_FromStringAndSize(c_string, size) # <<<<<<<<<<<<<< * * Py_INCREF(rv) */ __pyx_t_16 = PyBytes_FromStringAndSize(__pyx_v_c_string, __pyx_v_size); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 169, __pyx_L23_except_error) __Pyx_GOTREF(__pyx_t_16); __Pyx_DECREF_SET(__pyx_v_rv, __pyx_t_16); __pyx_t_16 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L22_exception_handled; } goto __pyx_L23_except_error; __pyx_L23_except_error:; /* "clickhouse_driver/bufferedreader.pyx":166 * * if c_encoding: * try: # <<<<<<<<<<<<<< * rv = c_string[:size].decode(c_encoding) * except UnicodeDecodeError: */ __Pyx_XGIVEREF(__pyx_t_12); __Pyx_XGIVEREF(__pyx_t_13); __Pyx_XGIVEREF(__pyx_t_14); __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14); goto __pyx_L1_error; __pyx_L22_exception_handled:; __Pyx_XGIVEREF(__pyx_t_12); __Pyx_XGIVEREF(__pyx_t_13); __Pyx_XGIVEREF(__pyx_t_14); __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14); __pyx_L28_try_end:; } /* "clickhouse_driver/bufferedreader.pyx":165 * self.position = right * * if c_encoding: # <<<<<<<<<<<<<< * try: * rv = c_string[:size].decode(c_encoding) */ } /* "clickhouse_driver/bufferedreader.pyx":171 * rv = PyBytes_FromStringAndSize(c_string, size) * * Py_INCREF(rv) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, rv) * */ Py_INCREF(__pyx_v_rv); /* "clickhouse_driver/bufferedreader.pyx":172 * * Py_INCREF(rv) * PyTuple_SET_ITEM(items, i, rv) # <<<<<<<<<<<<<< * * if c_string: */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_rv); } /* "clickhouse_driver/bufferedreader.pyx":174 * PyTuple_SET_ITEM(items, i, rv) * * if c_string: # <<<<<<<<<<<<<< * PyMem_Free(c_string) * */ __pyx_t_2 = (__pyx_v_c_string != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":175 * * if c_string: * PyMem_Free(c_string) # <<<<<<<<<<<<<< * * return items */ PyMem_Free(__pyx_v_c_string); /* "clickhouse_driver/bufferedreader.pyx":174 * PyTuple_SET_ITEM(items, i, rv) * * if c_string: # <<<<<<<<<<<<<< * PyMem_Free(c_string) * */ } /* "clickhouse_driver/bufferedreader.pyx":177 * PyMem_Free(c_string) * * return items # <<<<<<<<<<<<<< * * def read_fixed_strings_as_bytes(self, Py_ssize_t n_items, */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":62 * return rv * * def read_strings(self, unsigned long long n_items, encoding=None): # <<<<<<<<<<<<<< * """ * Python has great overhead between function calls. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_16); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_rv); __Pyx_XDECREF(__pyx_v_encoding); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":179 * return items * * def read_fixed_strings_as_bytes(self, Py_ssize_t n_items, # <<<<<<<<<<<<<< * Py_ssize_t length): * cdef Py_ssize_t i */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_11read_fixed_strings_as_bytes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_11read_fixed_strings_as_bytes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { Py_ssize_t __pyx_v_n_items; Py_ssize_t __pyx_v_length; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_fixed_strings_as_bytes (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n_items,&__pyx_n_s_length,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_length)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("read_fixed_strings_as_bytes", 1, 2, 2, 1); __PYX_ERR(0, 179, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read_fixed_strings_as_bytes") < 0)) __PYX_ERR(0, 179, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_n_items = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_n_items == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 179, __pyx_L3_error) __pyx_v_length = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_length == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_fixed_strings_as_bytes", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 179, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_fixed_strings_as_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_10read_fixed_strings_as_bytes(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), __pyx_v_n_items, __pyx_v_length); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_10read_fixed_strings_as_bytes(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, Py_ssize_t __pyx_v_length) { Py_ssize_t __pyx_v_i; PyObject *__pyx_v_data = NULL; char *__pyx_v_data_ptr; PyObject *__pyx_v_items = NULL; PyObject *__pyx_v_item = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; char *__pyx_t_5; Py_ssize_t __pyx_t_6; Py_ssize_t __pyx_t_7; Py_ssize_t __pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_fixed_strings_as_bytes", 0); /* "clickhouse_driver/bufferedreader.pyx":182 * Py_ssize_t length): * cdef Py_ssize_t i * data = self.read(length * n_items) # <<<<<<<<<<<<<< * cdef char* data_ptr = PyBytes_AsString(data) * */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_length * __pyx_v_n_items)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_data = __pyx_t_1; __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":183 * cdef Py_ssize_t i * data = self.read(length * n_items) * cdef char* data_ptr = PyBytes_AsString(data) # <<<<<<<<<<<<<< * * items = PyTuple_New(n_items) */ __pyx_t_5 = PyBytes_AsString(__pyx_v_data); if (unlikely(__pyx_t_5 == ((char *)NULL))) __PYX_ERR(0, 183, __pyx_L1_error) __pyx_v_data_ptr = __pyx_t_5; /* "clickhouse_driver/bufferedreader.pyx":185 * cdef char* data_ptr = PyBytes_AsString(data) * * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * for i in range(n_items): * item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 185, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":186 * * items = PyTuple_New(n_items) * for i in range(n_items): # <<<<<<<<<<<<<< * item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) * Py_INCREF(item) */ __pyx_t_6 = __pyx_v_n_items; __pyx_t_7 = __pyx_t_6; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_i = __pyx_t_8; /* "clickhouse_driver/bufferedreader.pyx":187 * items = PyTuple_New(n_items) * for i in range(n_items): * item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) */ __pyx_t_1 = PyBytes_FromStringAndSize((&(__pyx_v_data_ptr[(__pyx_v_i * __pyx_v_length)])), __pyx_v_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_item, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":188 * for i in range(n_items): * item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * return items */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/bufferedreader.pyx":189 * item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * return items * */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/bufferedreader.pyx":190 * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) * return items # <<<<<<<<<<<<<< * * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":179 * return items * * def read_fixed_strings_as_bytes(self, Py_ssize_t n_items, # <<<<<<<<<<<<<< * Py_ssize_t length): * cdef Py_ssize_t i */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_fixed_strings_as_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data); __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":192 * return items * * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, # <<<<<<<<<<<<<< * encoding=None): * if encoding is None: */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_13read_fixed_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_13read_fixed_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { Py_ssize_t __pyx_v_n_items; Py_ssize_t __pyx_v_length; PyObject *__pyx_v_encoding = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_fixed_strings (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n_items,&__pyx_n_s_length,&__pyx_n_s_encoding,0}; PyObject* values[3] = {0,0,0}; /* "clickhouse_driver/bufferedreader.pyx":193 * * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, * encoding=None): # <<<<<<<<<<<<<< * if encoding is None: * return self.read_fixed_strings_as_bytes(n_items, length) */ values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_length)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("read_fixed_strings", 0, 2, 3, 1); __PYX_ERR(0, 192, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read_fixed_strings") < 0)) __PYX_ERR(0, 192, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_n_items = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_n_items == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 192, __pyx_L3_error) __pyx_v_length = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_length == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 192, __pyx_L3_error) __pyx_v_encoding = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("read_fixed_strings", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 192, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_fixed_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_12read_fixed_strings(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), __pyx_v_n_items, __pyx_v_length, __pyx_v_encoding); /* "clickhouse_driver/bufferedreader.pyx":192 * return items * * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, # <<<<<<<<<<<<<< * encoding=None): * if encoding is None: */ /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_12read_fixed_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, Py_ssize_t __pyx_v_length, PyObject *__pyx_v_encoding) { Py_ssize_t __pyx_v_i; Py_ssize_t __pyx_v_j; char *__pyx_v_c_encoding; PyObject *__pyx_v_data = NULL; char *__pyx_v_data_ptr; char *__pyx_v_c_string; PyObject *__pyx_v_items = NULL; PyObject *__pyx_v_item = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; int __pyx_t_8; PyObject *__pyx_t_9 = NULL; char *__pyx_t_10; Py_ssize_t __pyx_t_11; Py_ssize_t __pyx_t_12; Py_ssize_t __pyx_t_13; PyObject *__pyx_t_14 = NULL; PyObject *__pyx_t_15 = NULL; PyObject *__pyx_t_16 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_fixed_strings", 0); __Pyx_INCREF(__pyx_v_encoding); /* "clickhouse_driver/bufferedreader.pyx":194 * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, * encoding=None): * if encoding is None: # <<<<<<<<<<<<<< * return self.read_fixed_strings_as_bytes(n_items, length) * */ __pyx_t_1 = (__pyx_v_encoding == Py_None); __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedreader.pyx":195 * encoding=None): * if encoding is None: * return self.read_fixed_strings_as_bytes(n_items, length) # <<<<<<<<<<<<<< * * cdef Py_ssize_t i, j */ __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read_fixed_strings_as_bytes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_n_items); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = NULL; __pyx_t_8 = 0; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_8 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_6}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_6}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__pyx_t_7) { __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; } __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_6); __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":194 * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, * encoding=None): * if encoding is None: # <<<<<<<<<<<<<< * return self.read_fixed_strings_as_bytes(n_items, length) * */ } /* "clickhouse_driver/bufferedreader.pyx":198 * * cdef Py_ssize_t i, j * encoding = encoding.encode('utf-8') # <<<<<<<<<<<<<< * cdef char* c_encoding = encoding * data = self.read(length * n_items) */ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_encoding, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_9, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_utf_8); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_encoding, __pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":199 * cdef Py_ssize_t i, j * encoding = encoding.encode('utf-8') * cdef char* c_encoding = encoding # <<<<<<<<<<<<<< * data = self.read(length * n_items) * cdef char* data_ptr = PyBytes_AsString(data) */ __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_encoding); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L1_error) __pyx_v_c_encoding = __pyx_t_10; /* "clickhouse_driver/bufferedreader.pyx":200 * encoding = encoding.encode('utf-8') * cdef char* c_encoding = encoding * data = self.read(length * n_items) # <<<<<<<<<<<<<< * cdef char* data_ptr = PyBytes_AsString(data) * */ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = PyInt_FromSsize_t((__pyx_v_length * __pyx_v_n_items)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_9); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_data = __pyx_t_3; __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":201 * cdef char* c_encoding = encoding * data = self.read(length * n_items) * cdef char* data_ptr = PyBytes_AsString(data) # <<<<<<<<<<<<<< * * cdef char* c_string = PyMem_Malloc(length + 1) */ __pyx_t_10 = PyBytes_AsString(__pyx_v_data); if (unlikely(__pyx_t_10 == ((char *)NULL))) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_v_data_ptr = __pyx_t_10; /* "clickhouse_driver/bufferedreader.pyx":203 * cdef char* data_ptr = PyBytes_AsString(data) * * cdef char* c_string = PyMem_Malloc(length + 1) # <<<<<<<<<<<<<< * if not c_string: * raise MemoryError() */ __pyx_v_c_string = ((char *)PyMem_Malloc((__pyx_v_length + 1))); /* "clickhouse_driver/bufferedreader.pyx":204 * * cdef char* c_string = PyMem_Malloc(length + 1) * if not c_string: # <<<<<<<<<<<<<< * raise MemoryError() * c_string[length] = 0 */ __pyx_t_2 = ((!(__pyx_v_c_string != 0)) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedreader.pyx":205 * cdef char* c_string = PyMem_Malloc(length + 1) * if not c_string: * raise MemoryError() # <<<<<<<<<<<<<< * c_string[length] = 0 * */ PyErr_NoMemory(); __PYX_ERR(0, 205, __pyx_L1_error) /* "clickhouse_driver/bufferedreader.pyx":204 * * cdef char* c_string = PyMem_Malloc(length + 1) * if not c_string: # <<<<<<<<<<<<<< * raise MemoryError() * c_string[length] = 0 */ } /* "clickhouse_driver/bufferedreader.pyx":206 * if not c_string: * raise MemoryError() * c_string[length] = 0 # <<<<<<<<<<<<<< * * items = PyTuple_New(n_items) */ (__pyx_v_c_string[__pyx_v_length]) = 0; /* "clickhouse_driver/bufferedreader.pyx":208 * c_string[length] = 0 * * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * for i in range(n_items): * memcpy(c_string, &data_ptr[i * length], length) */ __pyx_t_3 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_items = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":209 * * items = PyTuple_New(n_items) * for i in range(n_items): # <<<<<<<<<<<<<< * memcpy(c_string, &data_ptr[i * length], length) * */ __pyx_t_11 = __pyx_v_n_items; __pyx_t_12 = __pyx_t_11; for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { __pyx_v_i = __pyx_t_13; /* "clickhouse_driver/bufferedreader.pyx":210 * items = PyTuple_New(n_items) * for i in range(n_items): * memcpy(c_string, &data_ptr[i * length], length) # <<<<<<<<<<<<<< * * # Get last non zero byte of string from the end. */ (void)(memcpy(__pyx_v_c_string, (&(__pyx_v_data_ptr[(__pyx_v_i * __pyx_v_length)])), __pyx_v_length)); /* "clickhouse_driver/bufferedreader.pyx":213 * * # Get last non zero byte of string from the end. * j = length - 1 # <<<<<<<<<<<<<< * while j >= 0 and not c_string[j]: * j -= 1 */ __pyx_v_j = (__pyx_v_length - 1); /* "clickhouse_driver/bufferedreader.pyx":214 * # Get last non zero byte of string from the end. * j = length - 1 * while j >= 0 and not c_string[j]: # <<<<<<<<<<<<<< * j -= 1 * */ while (1) { __pyx_t_1 = ((__pyx_v_j >= 0) != 0); if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; goto __pyx_L9_bool_binop_done; } __pyx_t_1 = ((!((__pyx_v_c_string[__pyx_v_j]) != 0)) != 0); __pyx_t_2 = __pyx_t_1; __pyx_L9_bool_binop_done:; if (!__pyx_t_2) break; /* "clickhouse_driver/bufferedreader.pyx":215 * j = length - 1 * while j >= 0 and not c_string[j]: * j -= 1 # <<<<<<<<<<<<<< * * try: */ __pyx_v_j = (__pyx_v_j - 1); } /* "clickhouse_driver/bufferedreader.pyx":217 * j -= 1 * * try: # <<<<<<<<<<<<<< * item = c_string[:j + 1].decode(c_encoding) * except UnicodeDecodeError: */ { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); __Pyx_XGOTREF(__pyx_t_14); __Pyx_XGOTREF(__pyx_t_15); __Pyx_XGOTREF(__pyx_t_16); /*try:*/ { /* "clickhouse_driver/bufferedreader.pyx":218 * * try: * item = c_string[:j + 1].decode(c_encoding) # <<<<<<<<<<<<<< * except UnicodeDecodeError: * item = PyBytes_FromStringAndSize(c_string, length) */ __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_c_string, 0, (__pyx_v_j + 1), __pyx_v_c_encoding, NULL, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 218, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedreader.pyx":217 * j -= 1 * * try: # <<<<<<<<<<<<<< * item = c_string[:j + 1].decode(c_encoding) * except UnicodeDecodeError: */ } __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; goto __pyx_L18_try_end; __pyx_L11_error:; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; /* "clickhouse_driver/bufferedreader.pyx":219 * try: * item = c_string[:j + 1].decode(c_encoding) * except UnicodeDecodeError: # <<<<<<<<<<<<<< * item = PyBytes_FromStringAndSize(c_string, length) * Py_INCREF(item) */ __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError); if (__pyx_t_8) { __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_fixed_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_9) < 0) __PYX_ERR(0, 219, __pyx_L13_except_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_9); /* "clickhouse_driver/bufferedreader.pyx":220 * item = c_string[:j + 1].decode(c_encoding) * except UnicodeDecodeError: * item = PyBytes_FromStringAndSize(c_string, length) # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) */ __pyx_t_6 = PyBytes_FromStringAndSize(__pyx_v_c_string, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 220, __pyx_L13_except_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L12_exception_handled; } goto __pyx_L13_except_error; __pyx_L13_except_error:; /* "clickhouse_driver/bufferedreader.pyx":217 * j -= 1 * * try: # <<<<<<<<<<<<<< * item = c_string[:j + 1].decode(c_encoding) * except UnicodeDecodeError: */ __Pyx_XGIVEREF(__pyx_t_14); __Pyx_XGIVEREF(__pyx_t_15); __Pyx_XGIVEREF(__pyx_t_16); __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); goto __pyx_L1_error; __pyx_L12_exception_handled:; __Pyx_XGIVEREF(__pyx_t_14); __Pyx_XGIVEREF(__pyx_t_15); __Pyx_XGIVEREF(__pyx_t_16); __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); __pyx_L18_try_end:; } /* "clickhouse_driver/bufferedreader.pyx":221 * except UnicodeDecodeError: * item = PyBytes_FromStringAndSize(c_string, length) * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/bufferedreader.pyx":222 * item = PyBytes_FromStringAndSize(c_string, length) * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * * PyMem_Free(c_string) */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/bufferedreader.pyx":224 * PyTuple_SET_ITEM(items, i, item) * * PyMem_Free(c_string) # <<<<<<<<<<<<<< * * return items */ PyMem_Free(__pyx_v_c_string); /* "clickhouse_driver/bufferedreader.pyx":226 * PyMem_Free(c_string) * * return items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/bufferedreader.pyx":192 * return items * * def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, # <<<<<<<<<<<<<< * encoding=None): * if encoding is None: */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read_fixed_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data); __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XDECREF(__pyx_v_encoding); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":11 * * cdef class BufferedReader(object): * cdef public unsigned long long position, current_buffer_size # <<<<<<<<<<<<<< * cdef public bytearray buffer * */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position___get__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.position.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_2__set__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations unsigned PY_LONG_LONG __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); __pyx_t_1 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error) __pyx_v_self->position = __pyx_t_1; /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.position.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size___get__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.current_buffer_size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_2__set__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations unsigned PY_LONG_LONG __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); __pyx_t_1 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error) __pyx_v_self->current_buffer_size = __pyx_t_1; /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.current_buffer_size.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":12 * cdef class BufferedReader(object): * cdef public unsigned long long position, current_buffer_size * cdef public bytearray buffer # <<<<<<<<<<<<<< * * def __init__(self, bufsize): */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer___get__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->buffer); __pyx_r = __pyx_v_self->buffer; goto __pyx_L0; /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_2__set__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); if (!(likely(PyByteArray_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 12, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->buffer); __Pyx_DECREF(__pyx_v_self->buffer); __pyx_v_self->buffer = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.buffer.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_5__del__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_4__del__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_4__del__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->buffer); __Pyx_DECREF(__pyx_v_self->buffer); __pyx_v_self->buffer = ((PyObject*)Py_None); /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_14__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_14__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_self->buffer); __Pyx_GIVEREF(__pyx_v_self->buffer); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self->buffer); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_v_state = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_3 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v__dict = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_4 = (__pyx_v__dict != Py_None); __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v__dict); __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = self.buffer is not None */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = self.buffer is not None # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, None), state */ /*else*/ { __pyx_t_5 = (__pyx_v_self->buffer != ((PyObject*)Py_None)); __pyx_v_use_setstate = __pyx_t_5; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, None), state * else: */ __pyx_t_5 = (__pyx_v_use_setstate != 0); if (__pyx_t_5) { /* "(tree fragment)":13 * use_setstate = self.buffer is not None * if use_setstate: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_BufferedReader); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_44607813); __Pyx_GIVEREF(__pyx_int_44607813); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_44607813); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 2, Py_None); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, None), state * else: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedReader__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_BufferedReader); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_44607813); __Pyx_GIVEREF(__pyx_int_44607813); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_44607813); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_state); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedReader__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_16__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_16__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedReader__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedReader, (type(self), 0x2a8a945, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedReader__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":232 * cdef object sock * * def __init__(self, sock, bufsize): # <<<<<<<<<<<<<< * self.sock = sock * super(BufferedSocketReader, self).__init__(bufsize) */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_sock = 0; PyObject *__pyx_v_bufsize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sock,&__pyx_n_s_bufsize,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sock)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 232, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 232, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_sock = values[0]; __pyx_v_bufsize = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 232, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedSocketReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)__pyx_v_self), __pyx_v_sock, __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self, PyObject *__pyx_v_sock, PyObject *__pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedreader.pyx":233 * * def __init__(self, sock, bufsize): * self.sock = sock # <<<<<<<<<<<<<< * super(BufferedSocketReader, self).__init__(bufsize) * */ __Pyx_INCREF(__pyx_v_sock); __Pyx_GIVEREF(__pyx_v_sock); __Pyx_GOTREF(__pyx_v_self->sock); __Pyx_DECREF(__pyx_v_self->sock); __pyx_v_self->sock = __pyx_v_sock; /* "clickhouse_driver/bufferedreader.pyx":234 * def __init__(self, sock, bufsize): * self.sock = sock * super(BufferedSocketReader, self).__init__(bufsize) # <<<<<<<<<<<<<< * * def read_into_buffer(self): */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self)); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_bufsize) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_bufsize); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 234, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":232 * cdef object sock * * def __init__(self, sock, bufsize): # <<<<<<<<<<<<<< * self.sock = sock * super(BufferedSocketReader, self).__init__(bufsize) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedSocketReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":236 * super(BufferedSocketReader, self).__init__(bufsize) * * def read_into_buffer(self): # <<<<<<<<<<<<<< * self.current_buffer_size = self.sock.recv_into(self.buffer) * */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_into_buffer (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_2read_into_buffer(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_2read_into_buffer(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; unsigned PY_LONG_LONG __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_into_buffer", 0); /* "clickhouse_driver/bufferedreader.pyx":237 * * def read_into_buffer(self): * self.current_buffer_size = self.sock.recv_into(self.buffer) # <<<<<<<<<<<<<< * * if self.current_buffer_size == 0: */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->sock, __pyx_n_s_recv_into); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->__pyx_base.buffer) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base.buffer); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_4 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->__pyx_base.current_buffer_size = __pyx_t_4; /* "clickhouse_driver/bufferedreader.pyx":239 * self.current_buffer_size = self.sock.recv_into(self.buffer) * * if self.current_buffer_size == 0: # <<<<<<<<<<<<<< * raise EOFError('Unexpected EOF while reading bytes') * */ __pyx_t_5 = ((__pyx_v_self->__pyx_base.current_buffer_size == 0) != 0); if (unlikely(__pyx_t_5)) { /* "clickhouse_driver/bufferedreader.pyx":240 * * if self.current_buffer_size == 0: * raise EOFError('Unexpected EOF while reading bytes') # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_EOFError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 240, __pyx_L1_error) /* "clickhouse_driver/bufferedreader.pyx":239 * self.current_buffer_size = self.sock.recv_into(self.buffer) * * if self.current_buffer_size == 0: # <<<<<<<<<<<<<< * raise EOFError('Unexpected EOF while reading bytes') * */ } /* "clickhouse_driver/bufferedreader.pyx":236 * super(BufferedSocketReader, self).__init__(bufsize) * * def read_into_buffer(self): # <<<<<<<<<<<<<< * self.current_buffer_size = self.sock.recv_into(self.buffer) * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedSocketReader.read_into_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_4__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position, self.sock) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_self->__pyx_base.buffer); __Pyx_GIVEREF(__pyx_v_self->__pyx_base.buffer); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self->__pyx_base.buffer); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_INCREF(__pyx_v_self->sock); __Pyx_GIVEREF(__pyx_v_self->sock); PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_self->sock); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_v_state = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_3 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v__dict = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_4 = (__pyx_v__dict != Py_None); __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v__dict); __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = self.buffer is not None or self.sock is not None */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = self.buffer is not None or self.sock is not None # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, None), state */ /*else*/ { __pyx_t_4 = (__pyx_v_self->__pyx_base.buffer != ((PyObject*)Py_None)); __pyx_t_6 = (__pyx_t_4 != 0); if (!__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L4_bool_binop_done; } __pyx_t_6 = (__pyx_v_self->sock != Py_None); __pyx_t_4 = (__pyx_t_6 != 0); __pyx_t_5 = __pyx_t_4; __pyx_L4_bool_binop_done:; __pyx_v_use_setstate = __pyx_t_5; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None or self.sock is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, None), state * else: */ __pyx_t_5 = (__pyx_v_use_setstate != 0); if (__pyx_t_5) { /* "(tree fragment)":13 * use_setstate = self.buffer is not None or self.sock is not None * if use_setstate: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_BufferedSocketRea); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_251251440); __Pyx_GIVEREF(__pyx_int_251251440); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_251251440); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 2, Py_None); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None or self.sock is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, None), state * else: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedSocketReader__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_BufferedSocketRea); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_251251440); __Pyx_GIVEREF(__pyx_int_251251440); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_251251440); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_state); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedSocketReader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketReader__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_6__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedSocketReader__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedSocketReader__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedSocketReader, (type(self), 0xef9caf0, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketReader__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedSocketReader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":246 * cdef object read_block * * def __init__(self, read_block, bufsize): # <<<<<<<<<<<<<< * self.read_block = read_block * super(CompressedBufferedReader, self).__init__(bufsize) */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_read_block = 0; PyObject *__pyx_v_bufsize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_read_block,&__pyx_n_s_bufsize,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_block)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 246, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 246, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_read_block = values[0]; __pyx_v_bufsize = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 246, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.CompressedBufferedReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)__pyx_v_self), __pyx_v_read_block, __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self, PyObject *__pyx_v_read_block, PyObject *__pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedreader.pyx":247 * * def __init__(self, read_block, bufsize): * self.read_block = read_block # <<<<<<<<<<<<<< * super(CompressedBufferedReader, self).__init__(bufsize) * */ __Pyx_INCREF(__pyx_v_read_block); __Pyx_GIVEREF(__pyx_v_read_block); __Pyx_GOTREF(__pyx_v_self->read_block); __Pyx_DECREF(__pyx_v_self->read_block); __pyx_v_self->read_block = __pyx_v_read_block; /* "clickhouse_driver/bufferedreader.pyx":248 * def __init__(self, read_block, bufsize): * self.read_block = read_block * super(CompressedBufferedReader, self).__init__(bufsize) # <<<<<<<<<<<<<< * * def read_into_buffer(self): */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self)); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_bufsize) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_bufsize); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":246 * cdef object read_block * * def __init__(self, read_block, bufsize): # <<<<<<<<<<<<<< * self.read_block = read_block * super(CompressedBufferedReader, self).__init__(bufsize) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.CompressedBufferedReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedreader.pyx":250 * super(CompressedBufferedReader, self).__init__(bufsize) * * def read_into_buffer(self): # <<<<<<<<<<<<<< * self.buffer = bytearray(self.read_block()) * self.current_buffer_size = len(self.buffer) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_3read_into_buffer(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_into_buffer (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_2read_into_buffer(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_2read_into_buffer(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_into_buffer", 0); /* "clickhouse_driver/bufferedreader.pyx":251 * * def read_into_buffer(self): * self.buffer = bytearray(self.read_block()) # <<<<<<<<<<<<<< * self.current_buffer_size = len(self.buffer) * */ __Pyx_INCREF(__pyx_v_self->read_block); __pyx_t_2 = __pyx_v_self->read_block; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->__pyx_base.buffer); __Pyx_DECREF(__pyx_v_self->__pyx_base.buffer); __pyx_v_self->__pyx_base.buffer = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/bufferedreader.pyx":252 * def read_into_buffer(self): * self.buffer = bytearray(self.read_block()) * self.current_buffer_size = len(self.buffer) # <<<<<<<<<<<<<< * * if self.current_buffer_size == 0: */ __pyx_t_2 = __pyx_v_self->__pyx_base.buffer; __Pyx_INCREF(__pyx_t_2); if (unlikely(__pyx_t_2 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 252, __pyx_L1_error) } __pyx_t_4 = PyByteArray_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 252, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_self->__pyx_base.current_buffer_size = __pyx_t_4; /* "clickhouse_driver/bufferedreader.pyx":254 * self.current_buffer_size = len(self.buffer) * * if self.current_buffer_size == 0: # <<<<<<<<<<<<<< * raise EOFError('Unexpected EOF while reading bytes') */ __pyx_t_5 = ((__pyx_v_self->__pyx_base.current_buffer_size == 0) != 0); if (unlikely(__pyx_t_5)) { /* "clickhouse_driver/bufferedreader.pyx":255 * * if self.current_buffer_size == 0: * raise EOFError('Unexpected EOF while reading bytes') # <<<<<<<<<<<<<< */ __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_EOFError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 255, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 255, __pyx_L1_error) /* "clickhouse_driver/bufferedreader.pyx":254 * self.current_buffer_size = len(self.buffer) * * if self.current_buffer_size == 0: # <<<<<<<<<<<<<< * raise EOFError('Unexpected EOF while reading bytes') */ } /* "clickhouse_driver/bufferedreader.pyx":250 * super(CompressedBufferedReader, self).__init__(bufsize) * * def read_into_buffer(self): # <<<<<<<<<<<<<< * self.buffer = bytearray(self.read_block()) * self.current_buffer_size = len(self.buffer) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.CompressedBufferedReader.read_into_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_4__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position, self.read_block) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_self->__pyx_base.buffer); __Pyx_GIVEREF(__pyx_v_self->__pyx_base.buffer); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self->__pyx_base.buffer); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_INCREF(__pyx_v_self->read_block); __Pyx_GIVEREF(__pyx_v_self->read_block); PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_self->read_block); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_v_state = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.current_buffer_size, self.position, self.read_block) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_3 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v__dict = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position, self.read_block) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_4 = (__pyx_v__dict != Py_None); __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v__dict); __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = self.buffer is not None or self.read_block is not None */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.current_buffer_size, self.position, self.read_block) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = self.buffer is not None or self.read_block is not None # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, None), state */ /*else*/ { __pyx_t_4 = (__pyx_v_self->__pyx_base.buffer != ((PyObject*)Py_None)); __pyx_t_6 = (__pyx_t_4 != 0); if (!__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L4_bool_binop_done; } __pyx_t_6 = (__pyx_v_self->read_block != Py_None); __pyx_t_4 = (__pyx_t_6 != 0); __pyx_t_5 = __pyx_t_4; __pyx_L4_bool_binop_done:; __pyx_v_use_setstate = __pyx_t_5; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None or self.read_block is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, None), state * else: */ __pyx_t_5 = (__pyx_v_use_setstate != 0); if (__pyx_t_5) { /* "(tree fragment)":13 * use_setstate = self.buffer is not None or self.read_block is not None * if use_setstate: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_CompressedBuffere); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_25411819); __Pyx_GIVEREF(__pyx_int_25411819); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_25411819); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 2, Py_None); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = self.buffer is not None or self.read_block is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, None), state * else: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_CompressedBufferedReader__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_CompressedBuffere); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_25411819); __Pyx_GIVEREF(__pyx_int_25411819); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_25411819); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_state); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.CompressedBufferedReader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedReader__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_6__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_CompressedBufferedReader__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_CompressedBufferedReader__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_CompressedBufferedReader, (type(self), 0x183c0eb, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedReader__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.CompressedBufferedReader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_BufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_BufferedReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_BufferedReader = {"__pyx_unpickle_BufferedReader", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_BufferedReader, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_BufferedReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedReader", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedReader", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BufferedReader") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedReader", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x2a8a945: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x2a8a945) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0x2a8a945: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedReader.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0x2a8a945: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = BufferedReader.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x2a, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x2a8a945: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedReader.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = BufferedReader.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2a8a945 = (buffer, current_buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_BufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; int __pyx_t_3; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] # <<<<<<<<<<<<<< * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[3]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(PyByteArray_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->buffer); __Pyx_DECREF(__pyx_v___pyx_result->buffer); __pyx_v___pyx_result->buffer = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->current_buffer_size = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->position = __pyx_t_2; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[3]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 3) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[3]) # <<<<<<<<<<<<<< */ __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[3]) */ } /* "(tree fragment)":11 * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_BufferedSocketReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_BufferedSocketReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_BufferedSocketReader = {"__pyx_unpickle_BufferedSocketReader", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_BufferedSocketReader, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_BufferedSocketReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketReader", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketReader", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BufferedSocketReader") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketReader", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedSocketReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_2__pyx_unpickle_BufferedSocketReader(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_2__pyx_unpickle_BufferedSocketReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0xef9caf0: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xef9caf0) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0xef9caf0: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketReader.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0xef9caf0: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = BufferedSocketReader.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xef, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0xef9caf0: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketReader.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = BufferedSocketReader.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedSocketReader__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0xef9caf0 = (buffer, current_buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_BufferedSocketReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedSocketReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_BufferedSocketReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; int __pyx_t_3; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] # <<<<<<<<<<<<<< * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(PyByteArray_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.buffer); __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.buffer); __pyx_v___pyx_result->__pyx_base.buffer = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.current_buffer_size = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.position = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->sock); __Pyx_DECREF(__pyx_v___pyx_result->sock); __pyx_v___pyx_result->sock = __pyx_t_1; __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 4) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) # <<<<<<<<<<<<<< */ __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ } /* "(tree fragment)":11 * __pyx_unpickle_BufferedSocketReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedSocketReader__set_state(BufferedSocketReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedSocketReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_CompressedBufferedReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_CompressedBufferedReader = {"__pyx_unpickle_CompressedBufferedReader", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_CompressedBufferedReader, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_CompressedBufferedReader(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedReader", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedReader", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_CompressedBufferedReader") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedReader", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_CompressedBufferedReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_4__pyx_unpickle_CompressedBufferedReader(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_4__pyx_unpickle_CompressedBufferedReader(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x183c0eb: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x183c0eb) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0x183c0eb: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0x183c0eb: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x18, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x183c0eb: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_CompressedBufferedReader__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x183c0eb = (buffer, current_buffer_size, position, read_block))" % __pyx_checksum) * __pyx_result = CompressedBufferedReader.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_CompressedBufferedReader", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_CompressedBufferedReader__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; int __pyx_t_3; Py_ssize_t __pyx_t_4; int __pyx_t_5; int __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] # <<<<<<<<<<<<<< * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(PyByteArray_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.buffer); __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.buffer); __pyx_v___pyx_result->__pyx_base.buffer = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.current_buffer_size = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.position = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->read_block); __Pyx_DECREF(__pyx_v___pyx_result->read_block); __pyx_v___pyx_result->read_block = __pyx_t_1; __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 4) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) # <<<<<<<<<<<<<< */ __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ } /* "(tree fragment)":11 * __pyx_unpickle_CompressedBufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedReader__set_state(CompressedBufferedReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.read_block = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_CompressedBufferedReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedReader(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *p; PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)o); p->buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedReader(PyObject *o) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif Py_CLEAR(p->buffer); (*Py_TYPE(o)->tp_free)(o); } static PyObject *__pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_position(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_1__get__(o); } static int __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_position(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); return -1; } } static PyObject *__pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_current_buffer_size(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_1__get__(o); } static int __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_current_buffer_size(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); return -1; } } static PyObject *__pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_buffer(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_1__get__(o); } static int __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_buffer(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_3__set__(o, v); } else { return __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_5__del__(o); } } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedreader_BufferedReader[] = { {"read_into_buffer", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_3read_into_buffer, METH_NOARGS, 0}, {"read", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_5read, METH_O, 0}, {"read_one", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_7read_one, METH_NOARGS, 0}, {"read_strings", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_9read_strings, METH_VARARGS|METH_KEYWORDS, __pyx_doc_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings}, {"read_fixed_strings_as_bytes", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_11read_fixed_strings_as_bytes, METH_VARARGS|METH_KEYWORDS, 0}, {"read_fixed_strings", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_13read_fixed_strings, METH_VARARGS|METH_KEYWORDS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_15__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_17__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_17clickhouse_driver_14bufferedreader_BufferedReader[] = { {(char *)"position", __pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_position, __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_position, (char *)0, 0}, {(char *)"current_buffer_size", __pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_current_buffer_size, __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_current_buffer_size, (char *)0, 0}, {(char *)"buffer", __pyx_getprop_17clickhouse_driver_14bufferedreader_14BufferedReader_buffer, __pyx_setprop_17clickhouse_driver_14bufferedreader_14BufferedReader_buffer, (char *)0, 0}, {0, 0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedreader.BufferedReader", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedReader, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedreader_BufferedReader, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_17clickhouse_driver_14bufferedreader_BufferedReader, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedReader, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedSocketReader(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *p; PyObject *o = __pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedReader(t, a, k); if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)o); p->sock = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedSocketReader(PyObject *o) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->sock); #if CYTHON_USE_TYPE_SLOTS if (PyType_IS_GC(Py_TYPE(o)->tp_base)) #endif PyObject_GC_Track(o); __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedReader(o); } static int __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_BufferedSocketReader(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)o; e = ((likely(__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)) ? ((__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_traverse) ? __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_BufferedSocketReader)); if (e) return e; if (p->sock) { e = (*v)(p->sock, a); if (e) return e; } return 0; } static int __pyx_tp_clear_17clickhouse_driver_14bufferedreader_BufferedSocketReader(PyObject *o) { PyObject* tmp; struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader *)o; if (likely(__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)) { if (__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_clear) __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_17clickhouse_driver_14bufferedreader_BufferedSocketReader); tmp = ((PyObject*)p->sock); p->sock = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedreader_BufferedSocketReader[] = { {"read_into_buffer", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_3read_into_buffer, METH_NOARGS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_5__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_7__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedreader.BufferedSocketReader", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedSocketReader), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedSocketReader, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_BufferedSocketReader, /*tp_traverse*/ __pyx_tp_clear_17clickhouse_driver_14bufferedreader_BufferedSocketReader, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedreader_BufferedSocketReader, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedSocketReader, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedreader_CompressedBufferedReader(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *p; PyObject *o = __pyx_tp_new_17clickhouse_driver_14bufferedreader_BufferedReader(t, a, k); if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)o); p->read_block = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_CompressedBufferedReader(PyObject *o) { struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->read_block); #if CYTHON_USE_TYPE_SLOTS if (PyType_IS_GC(Py_TYPE(o)->tp_base)) #endif PyObject_GC_Track(o); __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_BufferedReader(o); } static int __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_CompressedBufferedReader(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)o; e = ((likely(__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)) ? ((__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_traverse) ? __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_CompressedBufferedReader)); if (e) return e; if (p->read_block) { e = (*v)(p->read_block, a); if (e) return e; } return 0; } static int __pyx_tp_clear_17clickhouse_driver_14bufferedreader_CompressedBufferedReader(PyObject *o) { PyObject* tmp; struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *p = (struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader *)o; if (likely(__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader)) { if (__pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_clear) __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_17clickhouse_driver_14bufferedreader_CompressedBufferedReader); tmp = ((PyObject*)p->read_block); p->read_block = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedreader_CompressedBufferedReader[] = { {"read_into_buffer", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_3read_into_buffer, METH_NOARGS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_5__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_7__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedreader.CompressedBufferedReader", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedreader_CompressedBufferedReader, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_17clickhouse_driver_14bufferedreader_CompressedBufferedReader, /*tp_traverse*/ __pyx_tp_clear_17clickhouse_driver_14bufferedreader_CompressedBufferedReader, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedreader_CompressedBufferedReader, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedreader_CompressedBufferedReader, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 #if CYTHON_PEP489_MULTI_PHASE_INIT static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ static int __pyx_pymod_exec_bufferedreader(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec_bufferedreader}, {0, NULL} }; #endif static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, "bufferedreader", 0, /* m_doc */ #if CYTHON_PEP489_MULTI_PHASE_INIT 0, /* m_size */ #else -1, /* m_size */ #endif __pyx_methods /* m_methods */, #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_moduledef_slots, /* m_slots */ #else NULL, /* m_reload */ #endif NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif #ifndef CYTHON_SMALL_CODE #if defined(__clang__) #define CYTHON_SMALL_CODE #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) #define CYTHON_SMALL_CODE __attribute__((cold)) #else #define CYTHON_SMALL_CODE #endif #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_BufferedReader, __pyx_k_BufferedReader, sizeof(__pyx_k_BufferedReader), 0, 0, 1, 1}, {&__pyx_n_s_BufferedSocketReader, __pyx_k_BufferedSocketReader, sizeof(__pyx_k_BufferedSocketReader), 0, 0, 1, 1}, {&__pyx_n_s_CompressedBufferedReader, __pyx_k_CompressedBufferedReader, sizeof(__pyx_k_CompressedBufferedReader), 0, 0, 1, 1}, {&__pyx_n_s_EOFError, __pyx_k_EOFError, sizeof(__pyx_k_EOFError), 0, 0, 1, 1}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x18, __pyx_k_Incompatible_checksums_s_vs_0x18, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x18), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x2a, __pyx_k_Incompatible_checksums_s_vs_0x2a, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x2a), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0xef, __pyx_k_Incompatible_checksums_s_vs_0xef, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xef), 0, 0, 1, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, {&__pyx_kp_u_Unexpected_EOF_while_reading_byt, __pyx_k_Unexpected_EOF_while_reading_byt, sizeof(__pyx_k_Unexpected_EOF_while_reading_byt), 0, 1, 0, 0}, {&__pyx_n_s_UnicodeDecodeError, __pyx_k_UnicodeDecodeError, sizeof(__pyx_k_UnicodeDecodeError), 0, 0, 1, 1}, {&__pyx_n_s_bufsize, __pyx_k_bufsize, sizeof(__pyx_k_bufsize), 0, 0, 1, 1}, {&__pyx_n_s_clickhouse_driver_bufferedreader, __pyx_k_clickhouse_driver_bufferedreader, sizeof(__pyx_k_clickhouse_driver_bufferedreader), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, {&__pyx_n_s_encoding, __pyx_k_encoding, sizeof(__pyx_k_encoding), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_n_items, __pyx_k_n_items, sizeof(__pyx_k_n_items), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_BufferedReader, __pyx_k_pyx_unpickle_BufferedReader, sizeof(__pyx_k_pyx_unpickle_BufferedReader), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_BufferedSocketRea, __pyx_k_pyx_unpickle_BufferedSocketRea, sizeof(__pyx_k_pyx_unpickle_BufferedSocketRea), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_CompressedBuffere, __pyx_k_pyx_unpickle_CompressedBuffere, sizeof(__pyx_k_pyx_unpickle_CompressedBuffere), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1}, {&__pyx_n_s_read_block, __pyx_k_read_block, sizeof(__pyx_k_read_block), 0, 0, 1, 1}, {&__pyx_n_s_read_fixed_strings_as_bytes, __pyx_k_read_fixed_strings_as_bytes, sizeof(__pyx_k_read_fixed_strings_as_bytes), 0, 0, 1, 1}, {&__pyx_n_s_read_into_buffer, __pyx_k_read_into_buffer, sizeof(__pyx_k_read_into_buffer), 0, 0, 1, 1}, {&__pyx_n_s_recv_into, __pyx_k_recv_into, sizeof(__pyx_k_recv_into), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, {&__pyx_n_s_sock, __pyx_k_sock, sizeof(__pyx_k_sock), 0, 0, 1, 1}, {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_super = __Pyx_GetBuiltinName(__pyx_n_s_super); if (!__pyx_builtin_super) __PYX_ERR(0, 20, __pyx_L1_error) __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 23, __pyx_L1_error) __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 85, __pyx_L1_error) __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 90, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 117, __pyx_L1_error) __pyx_builtin_UnicodeDecodeError = __Pyx_GetBuiltinName(__pyx_n_s_UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) __PYX_ERR(0, 168, __pyx_L1_error) __pyx_builtin_EOFError = __Pyx_GetBuiltinName(__pyx_n_s_EOFError); if (!__pyx_builtin_EOFError) __PYX_ERR(0, 240, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "clickhouse_driver/bufferedreader.pyx":240 * * if self.current_buffer_size == 0: * raise EOFError('Unexpected EOF while reading bytes') # <<<<<<<<<<<<<< * * */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Unexpected_EOF_while_reading_byt); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 240, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* "(tree fragment)":1 * def __pyx_unpickle_BufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_tuple__2 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 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_stringsource, __pyx_n_s_pyx_unpickle_BufferedReader, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) __PYX_ERR(1, 1, __pyx_L1_error) __pyx_tuple__4 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 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_stringsource, __pyx_n_s_pyx_unpickle_BufferedSocketRea, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(1, 1, __pyx_L1_error) __pyx_tuple__6 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 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_stringsource, __pyx_n_s_pyx_unpickle_CompressedBuffere, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_int_25411819 = PyInt_FromLong(25411819L); if (unlikely(!__pyx_int_25411819)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_44607813 = PyInt_FromLong(44607813L); if (unlikely(!__pyx_int_44607813)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_251251440 = PyInt_FromLong(251251440L); if (unlikely(!__pyx_int_251251440)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ static int __Pyx_modinit_global_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); /*--- Global init code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_variable_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); /*--- Variable export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); /*--- Function export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader) < 0) __PYX_ERR(0, 10, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BufferedReader, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader) < 0) __PYX_ERR(0, 10, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader) < 0) __PYX_ERR(0, 10, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader = &__pyx_type_17clickhouse_driver_14bufferedreader_BufferedReader; __pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader.tp_base = __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader; if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader) < 0) __PYX_ERR(0, 229, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BufferedSocketReader, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader) < 0) __PYX_ERR(0, 229, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader) < 0) __PYX_ERR(0, 229, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedSocketReader = &__pyx_type_17clickhouse_driver_14bufferedreader_BufferedSocketReader; __pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader.tp_base = __pyx_ptype_17clickhouse_driver_14bufferedreader_BufferedReader; if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader) < 0) __PYX_ERR(0, 243, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CompressedBufferedReader, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader) < 0) __PYX_ERR(0, 243, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader) < 0) __PYX_ERR(0, 243, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedreader_CompressedBufferedReader = &__pyx_type_17clickhouse_driver_14bufferedreader_CompressedBufferedReader; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_type_import_code(void) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); /*--- Type import code ---*/ __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), #else sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_variable_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); /*--- Variable import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } #ifndef CYTHON_NO_PYINIT_EXPORT #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC #elif PY_MAJOR_VERSION < 3 #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" void #else #define __Pyx_PyMODINIT_FUNC void #endif #else #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" PyObject * #else #define __Pyx_PyMODINIT_FUNC PyObject * #endif #endif #if PY_MAJOR_VERSION < 3 __Pyx_PyMODINIT_FUNC initbufferedreader(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC initbufferedreader(void) #else __Pyx_PyMODINIT_FUNC PyInit_bufferedreader(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit_bufferedreader(void) #if CYTHON_PEP489_MULTI_PHASE_INIT { return PyModuleDef_Init(&__pyx_moduledef); } static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { #if PY_VERSION_HEX >= 0x030700A1 static PY_INT64_T main_interpreter_id = -1; PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); if (main_interpreter_id == -1) { main_interpreter_id = current_id; return (unlikely(current_id == -1)) ? -1 : 0; } else if (unlikely(main_interpreter_id != current_id)) #else static PyInterpreterState *main_interpreter = NULL; PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; if (!main_interpreter) { main_interpreter = current_interpreter; } else if (unlikely(main_interpreter != current_interpreter)) #endif { PyErr_SetString( PyExc_ImportError, "Interpreter change detected - this module can only be loaded into one interpreter per process."); return -1; } return 0; } 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) { PyObject *value = PyObject_GetAttrString(spec, from_name); int result = 0; if (likely(value)) { if (allow_none || value != Py_None) { result = PyDict_SetItemString(moddict, to_name, value); } Py_DECREF(value); } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); } else { result = -1; } return result; } static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { PyObject *module = NULL, *moddict, *modname; if (__Pyx_check_single_interpreter()) return NULL; if (__pyx_m) return __Pyx_NewRef(__pyx_m); modname = PyObject_GetAttrString(spec, "name"); if (unlikely(!modname)) goto bad; module = PyModule_NewObject(modname); Py_DECREF(modname); if (unlikely(!module)) goto bad; moddict = PyModule_GetDict(module); if (unlikely(!moddict)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; return module; bad: Py_XDECREF(module); return NULL; } static CYTHON_SMALL_CODE int __pyx_pymod_exec_bufferedreader(PyObject *__pyx_pyinit_module) #endif #endif { PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m) { if (__pyx_m == __pyx_pyinit_module) return 0; PyErr_SetString(PyExc_RuntimeError, "Module 'bufferedreader' has already been imported. Re-initialisation is not supported."); return -1; } #elif PY_MAJOR_VERSION >= 3 if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_bufferedreader(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pxy_PyFrame_Initialize_Offsets __Pxy_PyFrame_Initialize_Offsets(); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_m = __pyx_pyinit_module; Py_INCREF(__pyx_m); #else #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("bufferedreader", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) #endif __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_clickhouse_driver__bufferedreader) { if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "clickhouse_driver.bufferedreader")) { if (unlikely(PyDict_SetItemString(modules, "clickhouse_driver.bufferedreader", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Global type/function init code ---*/ (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); (void)__Pyx_modinit_function_export_code(); if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_variable_import_code(); (void)__Pyx_modinit_function_import_code(); /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /* "(tree fragment)":1 * def __pyx_unpickle_BufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_BufferedReader, NULL, __pyx_n_s_clickhouse_driver_bufferedreader); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BufferedReader, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":11 * __pyx_unpickle_BufferedReader__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedReader__set_state(BufferedReader __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.current_buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_BufferedSocketReader, NULL, __pyx_n_s_clickhouse_driver_bufferedreader); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BufferedSocketRea, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedReader(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_CompressedBufferedReader, NULL, __pyx_n_s_clickhouse_driver_bufferedreader); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_CompressedBuffere, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedreader.pyx":1 * from cpython cimport Py_INCREF, PyBytes_FromStringAndSize, PyBytes_AsString # <<<<<<<<<<<<<< * from cpython.bytearray cimport PyByteArray_AsString * # Using python's versions of pure c memory management functions for */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init clickhouse_driver.bufferedreader", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init clickhouse_driver.bufferedreader"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if CYTHON_PEP489_MULTI_PHASE_INIT return (__pyx_m != NULL) ? 0 : -1; #elif PY_MAJOR_VERSION >= 3 return __pyx_m; #else return; #endif } /* --- Runtime support code --- */ /* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule(modname); if (!m) goto end; p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif /* PyObjectGetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #endif /* GetBuiltinName */ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { PyErr_Format(PyExc_NameError, #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } /* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* PyCFunctionFastCall */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { PyCFunctionObject *func = (PyCFunctionObject*)func_obj; PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); int flags = PyCFunction_GET_FLAGS(func); assert(PyCFunction_Check(func)); assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); assert(nargs >= 0); assert(nargs == 0 || args != NULL); /* _PyCFunction_FastCallDict() must not be called with an exception set, because it may clear it (directly or indirectly) and so the caller loses its exception */ assert(!PyErr_Occurred()); if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); } else { return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); } } #endif /* PyFunctionFastCall */ #if CYTHON_FAST_PYCALL static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, PyObject *globals) { PyFrameObject *f; PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject **fastlocals; Py_ssize_t i; PyObject *result; assert(globals != NULL); /* XXX Perhaps we should create a specialized PyFrame_New() that doesn't take locals, but does take builtins without sanity checking them. */ assert(tstate != NULL); f = PyFrame_New(tstate, co, globals, NULL); if (f == NULL) { return NULL; } fastlocals = __Pyx_PyFrame_GetLocalsplus(f); for (i = 0; i < na; i++) { Py_INCREF(*args); fastlocals[i] = *args++; } result = PyEval_EvalFrameEx(f,0); ++tstate->recursion_depth; Py_DECREF(f); --tstate->recursion_depth; return result; } #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *argdefs = PyFunction_GET_DEFAULTS(func); PyObject *closure; #if PY_MAJOR_VERSION >= 3 PyObject *kwdefs; #endif PyObject *kwtuple, **k; PyObject **d; Py_ssize_t nd; Py_ssize_t nk; PyObject *result; assert(kwargs == NULL || PyDict_Check(kwargs)); nk = kwargs ? PyDict_Size(kwargs) : 0; if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { return NULL; } if ( #if PY_MAJOR_VERSION >= 3 co->co_kwonlyargcount == 0 && #endif likely(kwargs == NULL || nk == 0) && co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { if (argdefs == NULL && co->co_argcount == nargs) { result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); goto done; } else if (nargs == 0 && argdefs != NULL && co->co_argcount == Py_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ args = &PyTuple_GET_ITEM(argdefs, 0); result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); goto done; } } if (kwargs != NULL) { Py_ssize_t pos, i; kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) { result = NULL; goto done; } k = &PyTuple_GET_ITEM(kwtuple, 0); pos = i = 0; while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { Py_INCREF(k[i]); Py_INCREF(k[i+1]); i += 2; } nk = i / 2; } else { kwtuple = NULL; k = NULL; } closure = PyFunction_GET_CLOSURE(func); #if PY_MAJOR_VERSION >= 3 kwdefs = PyFunction_GET_KW_DEFAULTS(func); #endif if (argdefs != NULL) { d = &PyTuple_GET_ITEM(argdefs, 0); nd = Py_SIZE(argdefs); } else { d = NULL; nd = 0; } #if PY_MAJOR_VERSION >= 3 result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, kwdefs, closure); #else result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, closure); #endif Py_XDECREF(kwtuple); done: Py_LeaveRecursiveCall(); return result; } #endif #endif /* PyObjectCall */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; ternaryfunc call = func->ob_type->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCallMethO */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { PyObject *self, *result; PyCFunction cfunc; cfunc = PyCFunction_GET_FUNCTION(func); self = PyCFunction_GET_SELF(func); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = cfunc(self, arg); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCallOneArg */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_New(1); if (unlikely(!args)) return NULL; Py_INCREF(arg); PyTuple_SET_ITEM(args, 0, arg); result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, &arg, 1); } #endif if (likely(PyCFunction_Check(func))) { if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { return __Pyx_PyObject_CallMethO(func, arg); #if CYTHON_FAST_PYCCALL } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { return __Pyx_PyCFunction_FastCall(func, &arg, 1); #endif } } return __Pyx__PyObject_CallOneArg(func, arg); } #else static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_Pack(1, arg); if (unlikely(!args)) return NULL; result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } #endif /* PyObjectCallNoArg */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) #endif { if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } } return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); } #endif /* PyErrFetchRestore */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #endif /* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { __Pyx_PyThreadState_declare Py_XINCREF(type); if (!value || value == Py_None) value = NULL; else Py_INCREF(value); if (!tb || tb == Py_None) tb = NULL; else { Py_INCREF(tb); if (!PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } } if (PyType_Check(type)) { #if CYTHON_COMPILING_IN_PYPY if (!value) { Py_INCREF(Py_None); value = Py_None; } #endif PyErr_NormalizeException(&type, &value, &tb); } else { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } value = type; type = (PyObject*) Py_TYPE(type); Py_INCREF(type); if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto raise_error; } } __Pyx_PyThreadState_assign __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { PyObject* owned_instance = NULL; if (tb == Py_None) { tb = 0; } else if (tb && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto bad; } if (value == Py_None) value = 0; if (PyExceptionInstance_Check(type)) { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto bad; } value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { PyObject *instance_class = NULL; if (value && PyExceptionInstance_Check(value)) { instance_class = (PyObject*) Py_TYPE(value); if (instance_class != type) { int is_subclass = PyObject_IsSubclass(instance_class, type); if (!is_subclass) { instance_class = NULL; } else if (unlikely(is_subclass == -1)) { goto bad; } else { type = instance_class; } } } if (!instance_class) { PyObject *args; if (!value) args = PyTuple_New(0); else if (PyTuple_Check(value)) { Py_INCREF(value); args = value; } else args = PyTuple_Pack(1, value); if (!args) goto bad; owned_instance = PyObject_Call(type, args, NULL); Py_DECREF(args); if (!owned_instance) goto bad; value = owned_instance; if (!PyExceptionInstance_Check(value)) { PyErr_Format(PyExc_TypeError, "calling %R should have returned an instance of " "BaseException, not %R", type, Py_TYPE(value)); goto bad; } } } else { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto bad; } if (cause) { PyObject *fixed_cause; if (cause == Py_None) { fixed_cause = NULL; } else if (PyExceptionClass_Check(cause)) { fixed_cause = PyObject_CallObject(cause, NULL); if (fixed_cause == NULL) goto bad; } else if (PyExceptionInstance_Check(cause)) { fixed_cause = cause; Py_INCREF(fixed_cause); } else { PyErr_SetString(PyExc_TypeError, "exception causes must derive from " "BaseException"); goto bad; } PyException_SetCause(value, fixed_cause); } PyErr_SetObject(type, value); if (tb) { #if CYTHON_COMPILING_IN_PYPY PyObject *tmp_type, *tmp_value, *tmp_tb; PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); Py_INCREF(tb); PyErr_Restore(tmp_type, tmp_value, tb); Py_XDECREF(tmp_tb); #else PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } #endif } bad: Py_XDECREF(owned_instance); return; } #endif /* GetItemIntByteArray */ static CYTHON_INLINE int __Pyx_GetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, int wraparound, int boundscheck) { Py_ssize_t length; if (wraparound | boundscheck) { length = PyByteArray_GET_SIZE(string); if (wraparound & unlikely(i < 0)) i += length; if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) { return (unsigned char) (PyByteArray_AS_STRING(string)[i]); } else { PyErr_SetString(PyExc_IndexError, "bytearray index out of range"); return -1; } } else { return (unsigned char) (PyByteArray_AS_STRING(string)[i]); } } /* PyObjectCall2Args */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { PyObject *args, *result = NULL; #if CYTHON_FAST_PYCALL if (PyFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyFunction_FastCall(function, args, 2); } #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyCFunction_FastCall(function, args, 2); } #endif args = PyTuple_New(2); if (unlikely(!args)) goto done; Py_INCREF(arg1); PyTuple_SET_ITEM(args, 0, arg1); Py_INCREF(arg2); PyTuple_SET_ITEM(args, 1, arg2); Py_INCREF(function); result = __Pyx_PyObject_Call(function, args, NULL); Py_DECREF(args); Py_DECREF(function); done: return result; } /* decode_c_string */ static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, const char* encoding, const char* errors, PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { Py_ssize_t length; if (unlikely((start < 0) | (stop < 0))) { size_t slen = strlen(cstring); if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) { PyErr_SetString(PyExc_OverflowError, "c-string too long to convert to Python"); return NULL; } length = (Py_ssize_t) slen; if (start < 0) { start += length; if (start < 0) start = 0; } if (stop < 0) stop += length; } if (unlikely(stop <= start)) return __Pyx_NewRef(__pyx_empty_unicode); length = stop - start; cstring += start; if (decode_func) { return decode_func(cstring, length, errors); } else { return PyUnicode_Decode(cstring, length, encoding, errors); } } /* GetTopmostException */ #if CYTHON_USE_EXC_INFO_STACK static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate) { _PyErr_StackItem *exc_info = tstate->exc_info; while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && exc_info->previous_item != NULL) { exc_info = exc_info->previous_item; } return exc_info; } #endif /* SaveResetException */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_USE_EXC_INFO_STACK _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); *type = exc_info->exc_type; *value = exc_info->exc_value; *tb = exc_info->exc_traceback; #else *type = tstate->exc_type; *value = tstate->exc_value; *tb = tstate->exc_traceback; #endif Py_XINCREF(*type); Py_XINCREF(*value); Py_XINCREF(*tb); } static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; #if CYTHON_USE_EXC_INFO_STACK _PyErr_StackItem *exc_info = tstate->exc_info; tmp_type = exc_info->exc_type; tmp_value = exc_info->exc_value; tmp_tb = exc_info->exc_traceback; exc_info->exc_type = type; exc_info->exc_value = value; exc_info->exc_traceback = tb; #else tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; tstate->exc_type = type; tstate->exc_value = value; tstate->exc_traceback = tb; #endif Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } #endif /* PyErrExceptionMatches */ #if CYTHON_FAST_THREAD_STATE static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; icurexc_type; if (exc_type == err) return 1; if (unlikely(!exc_type)) return 0; if (unlikely(PyTuple_Check(err))) return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); } #endif /* GetException */ #if CYTHON_FAST_THREAD_STATE static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) #else static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) #endif { PyObject *local_type, *local_value, *local_tb; #if CYTHON_FAST_THREAD_STATE PyObject *tmp_type, *tmp_value, *tmp_tb; local_type = tstate->curexc_type; local_value = tstate->curexc_value; local_tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; #else PyErr_Fetch(&local_type, &local_value, &local_tb); #endif PyErr_NormalizeException(&local_type, &local_value, &local_tb); #if CYTHON_FAST_THREAD_STATE if (unlikely(tstate->curexc_type)) #else if (unlikely(PyErr_Occurred())) #endif goto bad; #if PY_MAJOR_VERSION >= 3 if (local_tb) { if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) goto bad; } #endif Py_XINCREF(local_tb); Py_XINCREF(local_type); Py_XINCREF(local_value); *type = local_type; *value = local_value; *tb = local_tb; #if CYTHON_FAST_THREAD_STATE #if CYTHON_USE_EXC_INFO_STACK { _PyErr_StackItem *exc_info = tstate->exc_info; tmp_type = exc_info->exc_type; tmp_value = exc_info->exc_value; tmp_tb = exc_info->exc_traceback; exc_info->exc_type = local_type; exc_info->exc_value = local_value; exc_info->exc_traceback = local_tb; } #else tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; tstate->exc_type = local_type; tstate->exc_value = local_value; tstate->exc_traceback = local_tb; #endif Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_SetExcInfo(local_type, local_value, local_tb); #endif return 0; bad: *type = 0; *value = 0; *tb = 0; Py_XDECREF(local_type); Py_XDECREF(local_value); Py_XDECREF(local_tb); return -1; } /* GetAttr */ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { #if CYTHON_USE_TYPE_SLOTS #if PY_MAJOR_VERSION >= 3 if (likely(PyUnicode_Check(n))) #else if (likely(PyString_Check(n))) #endif return __Pyx_PyObject_GetAttrStr(o, n); #endif return PyObject_GetAttr(o, n); } /* GetAttr3 */ static PyObject *__Pyx_GetAttr3Default(PyObject *d) { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) return NULL; __Pyx_PyErr_Clear(); Py_INCREF(d); return d; } static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { PyObject *r = __Pyx_GetAttr(o, n); return (likely(r)) ? r : __Pyx_GetAttr3Default(d); } /* PyDictVersioning */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { PyObject *dict = Py_TYPE(obj)->tp_dict; return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; } static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { PyObject **dictptr = NULL; Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; if (offset) { #if CYTHON_COMPILING_IN_CPYTHON dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); #else dictptr = _PyObject_GetDictPtr(obj); #endif } return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; } static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { PyObject *dict = Py_TYPE(obj)->tp_dict; if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) return 0; return obj_dict_version == __Pyx_get_object_dict_version(obj); } #endif /* GetModuleGlobalName */ #if CYTHON_USE_DICT_VERSIONS static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) #else static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) #endif { PyObject *result; #if !CYTHON_AVOID_BORROWED_REFS #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } else if (unlikely(PyErr_Occurred())) { return NULL; } #else result = PyDict_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } #endif #else result = PyObject_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } PyErr_Clear(); #endif return __Pyx_GetBuiltinName(name); } /* Import */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; #if PY_MAJOR_VERSION < 3 PyObject *py_import; py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) { module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; } #endif if (!module) { #if PY_MAJOR_VERSION < 3 PyObject *py_level = PyInt_FromLong(level); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, level); #endif } } bad: #if PY_MAJOR_VERSION < 3 Py_XDECREF(py_import); #endif Py_XDECREF(empty_list); Py_XDECREF(empty_dict); return module; } /* ImportFrom */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_ImportError, #if PY_MAJOR_VERSION < 3 "cannot import name %.230s", PyString_AS_STRING(name)); #else "cannot import name %S", name); #endif } return value; } /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyList_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyTuple_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS if (is_list || PyList_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; } } else if (PyTuple_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (likely(l >= 0)) { i += l; } else { if (!PyErr_ExceptionMatches(PyExc_OverflowError)) return NULL; PyErr_Clear(); } } return m->sq_item(o, i); } } #else if (is_list || PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } /* HasAttr */ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { PyObject *r; if (unlikely(!__Pyx_PyBaseString_Check(n))) { PyErr_SetString(PyExc_TypeError, "hasattr(): attribute name must be string"); return -1; } r = __Pyx_GetAttr(o, n); if (unlikely(!r)) { PyErr_Clear(); return 0; } else { Py_DECREF(r); return 1; } } /* CallNextTpTraverse */ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) { PyTypeObject* type = Py_TYPE(obj); while (type && type->tp_traverse != current_tp_traverse) type = type->tp_base; while (type && type->tp_traverse == current_tp_traverse) type = type->tp_base; if (type && type->tp_traverse) return type->tp_traverse(obj, v, a); return 0; } /* CallNextTpClear */ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) { PyTypeObject* type = Py_TYPE(obj); while (type && type->tp_clear != current_tp_clear) type = type->tp_base; while (type && type->tp_clear == current_tp_clear) type = type->tp_base; if (type && type->tp_clear) type->tp_clear(obj); } /* PyObject_GenericGetAttrNoDict */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { PyErr_Format(PyExc_AttributeError, #if PY_MAJOR_VERSION >= 3 "'%.50s' object has no attribute '%U'", tp->tp_name, attr_name); #else "'%.50s' object has no attribute '%.400s'", tp->tp_name, PyString_AS_STRING(attr_name)); #endif return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { PyObject *descr; PyTypeObject *tp = Py_TYPE(obj); if (unlikely(!PyString_Check(attr_name))) { return PyObject_GenericGetAttr(obj, attr_name); } assert(!tp->tp_dictoffset); descr = _PyType_Lookup(tp, attr_name); if (unlikely(!descr)) { return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); } Py_INCREF(descr); #if PY_MAJOR_VERSION < 3 if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) #endif { descrgetfunc f = Py_TYPE(descr)->tp_descr_get; if (unlikely(f)) { PyObject *res = f(descr, obj, (PyObject *)tp); Py_DECREF(descr); return res; } } return descr; } #endif /* PyObject_GenericGetAttr */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { return PyObject_GenericGetAttr(obj, attr_name); } return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); } #endif /* PyObjectGetAttrStrNoError */ static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) __Pyx_PyErr_Clear(); } static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { PyObject *result; #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); } #endif result = __Pyx_PyObject_GetAttrStr(obj, attr_name); if (unlikely(!result)) { __Pyx_PyObject_GetAttrStr_ClearAttributeError(); } return result; } /* SetupReduce */ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; PyObject *name_attr; name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); if (likely(name_attr)) { ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); } else { ret = -1; } if (unlikely(ret < 0)) { PyErr_Clear(); ret = 0; } Py_XDECREF(name_attr); return ret; } static int __Pyx_setup_reduce(PyObject* type_obj) { int ret = 0; PyObject *object_reduce = NULL; PyObject *object_reduce_ex = NULL; PyObject *reduce = NULL; PyObject *reduce_ex = NULL; PyObject *reduce_cython = NULL; PyObject *setstate = NULL; PyObject *setstate_cython = NULL; #if CYTHON_USE_PYTYPE_LOOKUP if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #else if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #endif #if CYTHON_USE_PYTYPE_LOOKUP object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #else object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #endif reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; if (reduce_ex == object_reduce_ex) { #if CYTHON_USE_PYTYPE_LOOKUP object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #else object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #endif reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); if (likely(reduce_cython)) { ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (reduce == object_reduce || PyErr_Occurred()) { goto __PYX_BAD; } setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); if (!setstate) PyErr_Clear(); if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); if (likely(setstate_cython)) { ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (!setstate || PyErr_Occurred()) { goto __PYX_BAD; } } PyType_Modified((PyTypeObject*)type_obj); } } goto __PYX_GOOD; __PYX_BAD: if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); ret = -1; __PYX_GOOD: #if !CYTHON_USE_PYTYPE_LOOKUP Py_XDECREF(object_reduce); Py_XDECREF(object_reduce_ex); #endif Py_XDECREF(reduce); Py_XDECREF(reduce_ex); Py_XDECREF(reduce_cython); Py_XDECREF(setstate); Py_XDECREF(setstate_cython); return ret; } /* TypeImport */ #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) goto bad; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; #endif if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { PyOS_snprintf(warning, sizeof(warning), "%s.%s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; } return (PyTypeObject *)result; bad: Py_XDECREF(result); return NULL; } #endif /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON PyObject **cython_runtime_dict; #endif if (unlikely(!__pyx_cython_runtime)) { return c_line; } __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); #if CYTHON_COMPILING_IN_CPYTHON cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); if (likely(cython_runtime_dict)) { __PYX_PY_DICT_LOOKUP_IF_MODIFIED( use_cline, *cython_runtime_dict, __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) } else #endif { PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); if (use_cline_obj) { use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; Py_DECREF(use_cline_obj); } else { PyErr_Clear(); use_cline = NULL; } } if (!use_cline) { c_line = 0; PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); } else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { c_line = 0; } __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); return c_line; } #endif /* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = start + (end - start) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } /* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; PyThreadState *tstate = __Pyx_PyThreadState_Current; if (c_line) { c_line = __Pyx_CLineForTraceback(tstate, c_line); } py_code = __pyx_find_code_object(c_line ? -c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); } py_frame = PyFrame_New( tstate, /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; __Pyx_PyFrame_SetLineNumber(py_frame, py_line); PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) { 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; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG), little, !is_unsigned); } } /* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ {\ func_type value = func_value;\ if (sizeof(target_type) < sizeof(func_type)) {\ if (unlikely(value != (func_type) (target_type) value)) {\ func_type zero = 0;\ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ return (target_type) -1;\ if (is_unsigned && unlikely(value < zero))\ goto raise_neg_overflow;\ else\ goto raise_overflow;\ }\ }\ return (target_type) value;\ } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value) { const unsigned char neg_one = (unsigned char) ((unsigned char) 0 - (unsigned char) 1), const_zero = (unsigned char) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned char) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned char) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned char) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(unsigned char) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned char) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned char), little, !is_unsigned); } } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) { 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; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (unsigned PY_LONG_LONG) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0]) case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) { 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])); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) { 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])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (unsigned PY_LONG_LONG) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, +digits[0]) case -2: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case -3: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case -4: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else unsigned PY_LONG_LONG val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (unsigned PY_LONG_LONG) -1; } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (unsigned PY_LONG_LONG) -1; val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; } /* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (long) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -3: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -4: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; } #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (int) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -3: if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -4: if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; } #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } /* FastTypeChecks */ #if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; if (a == b) return 1; } return b == &PyBaseObject_Type; } static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { PyObject *mro; if (a == b) return 1; mro = a->tp_mro; if (likely(mro)) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(mro); for (i = 0; i < n; i++) { if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) return 1; } return 0; } return __Pyx_InBases(a, b); } #if PY_MAJOR_VERSION == 2 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { PyObject *exception, *value, *tb; int res; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&exception, &value, &tb); res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } if (!res) { res = PyObject_IsSubclass(err, exc_type2); if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } } __Pyx_ErrRestore(exception, value, tb); return res; } #else static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; if (!res) { res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); } return res; } #endif static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; assert(PyExceptionClass_Check(exc_type)); n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; ip) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; if (PyObject_Hash(*t->p) == -1) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT #if !CYTHON_PEP393_ENABLED static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; } #else static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (likely(PyUnicode_IS_ASCII(o))) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif } #endif #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { return __Pyx_PyUnicode_AsStringAndSize(o, length); } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { int retval; if (unlikely(!x)) return -1; retval = __Pyx_PyObject_IsTrue(x); Py_DECREF(x); return retval; } static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(result)) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "__int__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } return result; } #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", type_name, type_name, Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { #if CYTHON_USE_TYPE_SLOTS PyNumberMethods *m; #endif const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x) || PyLong_Check(x))) #else if (likely(PyLong_Check(x))) #endif return __Pyx_NewRef(x); #if CYTHON_USE_TYPE_SLOTS m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = m->nb_int(x); } else if (m && m->nb_long) { name = "long"; res = m->nb_long(x); } #else if (likely(m && m->nb_int)) { name = "int"; res = m->nb_int(x); } #endif #else if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { res = PyNumber_Int(x); } #endif if (likely(res)) { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { #else if (unlikely(!PyLong_CheckExact(res))) { #endif return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)b)->ob_digit; const Py_ssize_t size = Py_SIZE(b); if (likely(__Pyx_sst_abs(size) <= 1)) { ival = likely(size) ? digits[0] : 0; if (size == -1) ival = -ival; return ival; } else { switch (size) { case 2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; case -4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; } } #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ python-clickhouse-driver-0.2.3/clickhouse_driver/bufferedreader.pyx000066400000000000000000000211531420676740400257040ustar00rootroot00000000000000from cpython cimport Py_INCREF, PyBytes_FromStringAndSize, PyBytes_AsString from cpython.bytearray cimport PyByteArray_AsString # Using python's versions of pure c memory management functions for # proper memory statistics count. from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM from libc.string cimport memcpy cdef class BufferedReader(object): cdef public unsigned long long position, current_buffer_size cdef public bytearray buffer def __init__(self, bufsize): self.buffer = bytearray(bufsize) self.position = 0 self.current_buffer_size = 0 super(BufferedReader, self).__init__() def read_into_buffer(self): raise NotImplementedError def read(self, unsigned long long unread): # When the buffer is large enough bytes read are almost # always hit the buffer. cdef unsigned long long next_position = unread + self.position if next_position < self.current_buffer_size: t = self.position self.position = next_position return bytes(self.buffer[t:self.position]) cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) cdef unsigned long long read_bytes rv = bytes() while unread > 0: if self.position == self.current_buffer_size: self.read_into_buffer() buffer_ptr = PyByteArray_AsString(self.buffer) self.position = 0 read_bytes = min(unread, self.current_buffer_size - self.position) rv += PyBytes_FromStringAndSize( &buffer_ptr[self.position], read_bytes ) self.position += read_bytes unread -= read_bytes return rv def read_one(self): if self.position == self.current_buffer_size: self.read_into_buffer() self.position = 0 rv = self.buffer[self.position] self.position += 1 return rv def read_strings(self, unsigned long long n_items, encoding=None): """ Python has great overhead between function calls. We inline strings reading logic here to avoid this overhead. """ items = PyTuple_New(n_items) cdef unsigned long long i # Buffer vars cdef char* buffer_ptr = PyByteArray_AsString(self.buffer) cdef unsigned long long right # String length vars cdef unsigned long long size, shift, bytes_read cdef unsigned long long b # String for decode vars. cdef char *c_string = NULL cdef unsigned long long c_string_size = 1024 cdef char *c_encoding = NULL if encoding: encoding = encoding.encode('utf-8') c_encoding = encoding cdef object rv = object() # String for decode vars. if c_encoding: c_string = PyMem_Realloc(NULL, c_string_size) for i in range(n_items): shift = size = 0 # Read string size while True: if self.position == self.current_buffer_size: self.read_into_buffer() # `read_into_buffer` can override buffer buffer_ptr = PyByteArray_AsString(self.buffer) self.position = 0 b = buffer_ptr[self.position] self.position += 1 size |= (b & 0x7f) << shift if b < 0x80: break shift += 7 right = self.position + size if c_encoding: if size + 1 > c_string_size: c_string_size = size + 1 c_string = PyMem_Realloc(c_string, c_string_size) if c_string is NULL: raise MemoryError() c_string[size] = 0 bytes_read = 0 # Decoding pure c strings in Cython is faster than in pure Python. # We need to copy it into buffer for adding null symbol at the end. # In ClickHouse block there is no null if right > self.current_buffer_size: if c_encoding: memcpy(&c_string[bytes_read], &buffer_ptr[self.position], self.current_buffer_size - self.position) else: rv = PyBytes_FromStringAndSize( &buffer_ptr[self.position], self.current_buffer_size - self.position ) bytes_read = self.current_buffer_size - self.position # Read the rest of the string. while bytes_read != size: self.position = size - bytes_read self.read_into_buffer() # `read_into_buffer` can override buffer buffer_ptr = PyByteArray_AsString(self.buffer) # There can be not enough data in buffer. self.position = min( self.position, self.current_buffer_size ) if c_encoding: memcpy( &c_string[bytes_read], buffer_ptr, self.position ) else: rv += PyBytes_FromStringAndSize( buffer_ptr, self.position ) bytes_read += self.position else: if c_encoding: memcpy(c_string, &buffer_ptr[self.position], size) else: rv = PyBytes_FromStringAndSize( &buffer_ptr[self.position], size ) self.position = right if c_encoding: try: rv = c_string[:size].decode(c_encoding) except UnicodeDecodeError: rv = PyBytes_FromStringAndSize(c_string, size) Py_INCREF(rv) PyTuple_SET_ITEM(items, i, rv) if c_string: PyMem_Free(c_string) return items def read_fixed_strings_as_bytes(self, Py_ssize_t n_items, Py_ssize_t length): cdef Py_ssize_t i data = self.read(length * n_items) cdef char* data_ptr = PyBytes_AsString(data) items = PyTuple_New(n_items) for i in range(n_items): item = PyBytes_FromStringAndSize(&data_ptr[i * length], length) Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) return items def read_fixed_strings(self, Py_ssize_t n_items, Py_ssize_t length, encoding=None): if encoding is None: return self.read_fixed_strings_as_bytes(n_items, length) cdef Py_ssize_t i, j encoding = encoding.encode('utf-8') cdef char* c_encoding = encoding data = self.read(length * n_items) cdef char* data_ptr = PyBytes_AsString(data) cdef char* c_string = PyMem_Malloc(length + 1) if not c_string: raise MemoryError() c_string[length] = 0 items = PyTuple_New(n_items) for i in range(n_items): memcpy(c_string, &data_ptr[i * length], length) # Get last non zero byte of string from the end. j = length - 1 while j >= 0 and not c_string[j]: j -= 1 try: item = c_string[:j + 1].decode(c_encoding) except UnicodeDecodeError: item = PyBytes_FromStringAndSize(c_string, length) Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) PyMem_Free(c_string) return items cdef class BufferedSocketReader(BufferedReader): cdef object sock def __init__(self, sock, bufsize): self.sock = sock super(BufferedSocketReader, self).__init__(bufsize) def read_into_buffer(self): self.current_buffer_size = self.sock.recv_into(self.buffer) if self.current_buffer_size == 0: raise EOFError('Unexpected EOF while reading bytes') cdef class CompressedBufferedReader(BufferedReader): cdef object read_block def __init__(self, read_block, bufsize): self.read_block = read_block super(CompressedBufferedReader, self).__init__(bufsize) def read_into_buffer(self): self.buffer = bytearray(self.read_block()) self.current_buffer_size = len(self.buffer) if self.current_buffer_size == 0: raise EOFError('Unexpected EOF while reading bytes') python-clickhouse-driver-0.2.3/clickhouse_driver/bufferedwriter.c000066400000000000000000014732501420676740400253720ustar00rootroot00000000000000/* Generated by Cython 0.29.21 */ /* BEGIN: Cython Metadata { "distutils": { "depends": [], "name": "clickhouse_driver.bufferedwriter", "sources": [ "clickhouse_driver/bufferedwriter.pyx" ] }, "module_name": "clickhouse_driver.bufferedwriter" } END: Cython Metadata */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else #define CYTHON_ABI "0_29_21" #define CYTHON_HEX_VERSION 0x001D15F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #define __PYX_COMMA , #ifndef HAVE_LONG_LONG #if PY_VERSION_HEX >= 0x02070000 #define HAVE_LONG_LONG #endif #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #if PY_VERSION_HEX < 0x03050000 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #undef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #undef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 1 #undef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 0 #undef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 0 #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) #define CYTHON_USE_PYTYPE_LOOKUP 1 #endif #if PY_MAJOR_VERSION < 3 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 #endif #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #if PY_VERSION_HEX < 0x030300F0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #elif !defined(CYTHON_USE_UNICODE_WRITER) #define CYTHON_USE_UNICODE_WRITER 1 #endif #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #ifndef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 1 #endif #ifndef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 1 #endif #ifndef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) #endif #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #ifndef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) #endif #endif #if !defined(CYTHON_FAST_PYCCALL) #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) #endif #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #undef SHIFT #undef BASE #undef MASK #ifdef SIZEOF_VOID_P enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; #endif #endif #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_cpp_attribute #define __has_cpp_attribute(x) 0 #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif #ifndef CYTHON_MAYBE_UNUSED_VAR # if defined(__cplusplus) template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } # else # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) # endif #endif #ifndef CYTHON_NCP_UNUSED # if CYTHON_COMPILING_IN_CPYTHON # define CYTHON_NCP_UNUSED # else # define CYTHON_NCP_UNUSED CYTHON_UNUSED # endif #endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifdef _MSC_VER #ifndef _MSC_STDINT_H_ #if _MSC_VER < 1300 typedef unsigned char uint8_t; typedef unsigned int uint32_t; #else typedef unsigned __int8 uint8_t; typedef unsigned __int32 uint32_t; #endif #endif #else #include #endif #ifndef CYTHON_FALLTHROUGH #if defined(__cplusplus) && __cplusplus >= 201103L #if __has_cpp_attribute(fallthrough) #define CYTHON_FALLTHROUGH [[fallthrough]] #elif __has_cpp_attribute(clang::fallthrough) #define CYTHON_FALLTHROUGH [[clang::fallthrough]] #elif __has_cpp_attribute(gnu::fallthrough) #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] #endif #endif #ifndef CYTHON_FALLTHROUGH #if __has_attribute(fallthrough) #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) #else #define CYTHON_FALLTHROUGH #endif #endif #if defined(__clang__ ) && defined(__apple_build_version__) #if __apple_build_version__ < 7000000 #undef CYTHON_FALLTHROUGH #define CYTHON_FALLTHROUGH #endif #endif #endif #ifndef CYTHON_INLINE #if defined(__clang__) #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) #elif defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif #ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif #ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #ifndef METH_STACKLESS #define METH_STACKLESS 0 #endif #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) #ifndef METH_FASTCALL #define METH_FASTCALL 0x80 #endif typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames); #else #define __Pyx_PyCFunctionFast _PyCFunctionFast #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) #define PyObject_Realloc(p) PyMem_Realloc(p) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 #define PyMem_RawMalloc(n) PyMem_Malloc(n) #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) #define PyMem_RawFree(p) PyMem_Free(p) #endif #if CYTHON_COMPILING_IN_PYSTON #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) #else #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) #endif #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #elif PY_VERSION_HEX >= 0x03060000 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() #elif PY_VERSION_HEX >= 0x03000000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #else #define __Pyx_PyThreadState_Current _PyThreadState_Current #endif #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) #include "pythread.h" #define Py_tss_NEEDS_INIT 0 typedef int Py_tss_t; static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { *key = PyThread_create_key(); return 0; } static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); *key = Py_tss_NEEDS_INIT; return key; } static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { PyObject_Free(key); } static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { return *key != Py_tss_NEEDS_INIT; } static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { PyThread_delete_key(*key); *key = Py_tss_NEEDS_INIT; } static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { return PyThread_set_key_value(*key, value); } static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { return PyThread_get_key_value(*key); } #endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else #define __Pyx_PyDict_NewPresized(n) PyDict_New() #endif #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) #else #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) #else #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 #define PyUnicode_1BYTE_KIND 1 #define PyUnicode_2BYTE_KIND 2 #define PyUnicode_4BYTE_KIND 4 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #endif #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)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) #define PyObject_ASCII(o) PyObject_Repr(o) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #if PY_VERSION_HEX >= 0x030900A4 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) #else #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) #endif #if CYTHON_ASSUME_SAFE_MACROS #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) #else #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) #endif #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #if CYTHON_USE_ASYNC_SLOTS #if PY_VERSION_HEX >= 0x030500B1 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #else #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #endif #else #define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef __Pyx_PyAsyncMethodsStruct typedef struct { unaryfunc am_await; unaryfunc am_aiter; unaryfunc am_anext; } __Pyx_PyAsyncMethodsStruct; #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) #define __Pyx_truncl trunc #else #define __Pyx_truncl truncl #endif #define __PYX_MARK_ERR_POS(f_index, lineno) \ { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } #define __PYX_ERR(f_index, lineno, Ln_error) \ { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #define __PYX_HAVE__clickhouse_driver__bufferedwriter #define __PYX_HAVE_API__clickhouse_driver__bufferedwriter /* Early includes */ #include #include #include "pythread.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) #define CYTHON_WITHOUT_ASSERTIONS #endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_uchar_cast(c) ((unsigned char)c) #define __Pyx_long_cast(x) ((long)x) #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ (sizeof(type) < sizeof(Py_ssize_t)) ||\ (sizeof(type) > sizeof(Py_ssize_t) &&\ likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX) &&\ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ v == (type)PY_SSIZE_T_MIN))) ||\ (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { return (size_t) i < (size_t) limit; } #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) #elif SIZEOF_INT >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) #elif defined (_MSC_VER) #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) #define __Pyx_sst_abs(value) __builtin_llabs(value) #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); #define __Pyx_PySequence_Tuple(obj)\ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_ASSUME_SAFE_MACROS #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) #else #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) #endif #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } static PyObject *__pyx_m = NULL; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_cython_runtime = NULL; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "clickhouse_driver/bufferedwriter.pyx", "stringsource", "type.pxd", "bool.pxd", "complex.pxd", }; /*--- Type declarations ---*/ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; /* "clickhouse_driver/bufferedwriter.pyx":10 * * * cdef class BufferedWriter(object): # <<<<<<<<<<<<<< * cdef char* buffer * cdef unsigned long long position, buffer_size */ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter { PyObject_HEAD struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_vtab; char *buffer; unsigned PY_LONG_LONG position; unsigned PY_LONG_LONG buffer_size; }; /* "clickhouse_driver/bufferedwriter.pyx":119 * * * cdef class BufferedSocketWriter(BufferedWriter): # <<<<<<<<<<<<<< * cdef object sock * */ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter __pyx_base; PyObject *sock; }; /* "clickhouse_driver/bufferedwriter.pyx":133 * * * cdef class CompressedBufferedWriter(BufferedWriter): # <<<<<<<<<<<<<< * cdef object compressor * */ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter __pyx_base; PyObject *compressor; }; /* "clickhouse_driver/bufferedwriter.pyx":10 * * * cdef class BufferedWriter(object): # <<<<<<<<<<<<<< * cdef char* buffer * cdef unsigned long long position, buffer_size */ struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter { PyObject *(*write_into_stream)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, int __pyx_skip_dispatch); PyObject *(*write)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, PyObject *, int __pyx_skip_dispatch); }; static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter; /* "clickhouse_driver/bufferedwriter.pyx":119 * * * cdef class BufferedSocketWriter(BufferedWriter): # <<<<<<<<<<<<<< * cdef object sock * */ struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter { struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter __pyx_base; }; static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; /* "clickhouse_driver/bufferedwriter.pyx":133 * * * cdef class CompressedBufferedWriter(BufferedWriter): # <<<<<<<<<<<<<< * cdef object compressor * */ struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter { struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter __pyx_base; }; static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil)\ if (acquire_gil) {\ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ PyGILState_Release(__pyx_gilstate_save);\ } else {\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_XDECREF(tmp);\ } while (0) #define __Pyx_DECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) /* PyObjectGetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* PyObjectCall.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif /* PyFunctionFastCall.proto */ #if CYTHON_FAST_PYCALL #define __Pyx_PyFunction_FastCall(func, args, nargs)\ __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); #else #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) #endif #define __Pyx_BUILD_ASSERT_EXPR(cond)\ (sizeof(char [1 - 2*!(cond)]) - 1) #ifndef Py_MEMBER_SIZE #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) #endif static size_t __pyx_pyframe_localsplus_offset = 0; #include "frameobject.h" #define __Pxy_PyFrame_Initialize_Offsets()\ ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) #define __Pyx_PyFrame_GetLocalsplus(frame)\ (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) #endif /* PyObjectCallMethO.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); #endif /* PyObjectCallNoArg.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #else #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif /* PyCFunctionFastCall.proto */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); #else #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) #endif /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyDictVersioning.proto */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ (version_var) = __PYX_GET_DICT_VERSION(dict);\ (cache_var) = (value); #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ (VAR) = __pyx_dict_cached_value;\ } else {\ (VAR) = __pyx_dict_cached_value = (LOOKUP);\ __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ }\ } static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); #else #define __PYX_GET_DICT_VERSION(dict) (0) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); #endif /* PyThreadStateGet.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type #else #define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_assign #define __Pyx_PyErr_Occurred() PyErr_Occurred() #endif /* PyErrFetchRestore.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) #else #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #endif #else #define __Pyx_PyErr_Clear() PyErr_Clear() #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) #endif /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /* PyObjectCall2Args.proto */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS #define __Pyx_GetModuleGlobalName(var, name) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } #define __Pyx_GetModuleGlobalNameUncached(var, name) {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); #endif /* PyErrExceptionMatches.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); #else #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) #endif /* GetAttr.proto */ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /* GetAttr3.proto */ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /* ImportFrom.proto */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ __Pyx_GetItemInt_Generic(o, to_py_func(i)))) #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); /* HasAttr.proto */ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /* CallNextTpTraverse.proto */ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse); /* CallNextTpClear.proto */ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc); /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr #endif /* PyObject_GenericGetAttr.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr #endif /* SetVTable.proto */ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /* PyObjectGetAttrStrNoError.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); /* SetupReduce.proto */ static int __Pyx_setup_reduce(PyObject* type_obj); /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) #else static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); #endif /* CodeObjectCache.proto */ typedef struct { PyCodeObject* code_object; int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); /* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntFromPy.proto */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* FastTypeChecks.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); #else #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write_into_stream(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data, int __pyx_skip_dispatch); /* proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ /* Module declarations from 'cpython.version' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.type' */ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'libc.string' */ /* Module declarations from 'libc.stdio' */ /* Module declarations from 'cpython.object' */ /* Module declarations from 'cpython.ref' */ /* Module declarations from 'cpython.exc' */ /* Module declarations from 'cpython.module' */ /* Module declarations from 'cpython.mem' */ /* Module declarations from 'cpython.tuple' */ /* Module declarations from 'cpython.list' */ /* Module declarations from 'cpython.sequence' */ /* Module declarations from 'cpython.mapping' */ /* Module declarations from 'cpython.iterator' */ /* Module declarations from 'cpython.number' */ /* Module declarations from 'cpython.int' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; /* Module declarations from 'cpython.long' */ /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.complex' */ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.string' */ /* Module declarations from 'cpython.unicode' */ /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ /* Module declarations from 'cpython.function' */ /* Module declarations from 'cpython.method' */ /* Module declarations from 'cpython.weakref' */ /* Module declarations from 'cpython.getargs' */ /* Module declarations from 'cpython.pythread' */ /* Module declarations from 'cpython.pystate' */ /* Module declarations from 'cpython.cobject' */ /* Module declarations from 'cpython.oldbuffer' */ /* Module declarations from 'cpython.set' */ /* Module declarations from 'cpython.buffer' */ /* Module declarations from 'cpython.bytes' */ /* Module declarations from 'cpython.pycapsule' */ /* Module declarations from 'cpython' */ /* Module declarations from 'clickhouse_driver.bufferedwriter' */ static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter = 0; static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter = 0; static PyTypeObject *__pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter = 0; static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, PyObject *); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedSocketWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *, PyObject *); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_CompressedBufferedWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "clickhouse_driver.bufferedwriter" extern int __pyx_module_is_main_clickhouse_driver__bufferedwriter; int __pyx_module_is_main_clickhouse_driver__bufferedwriter = 0; /* Implementation of 'clickhouse_driver.bufferedwriter' */ static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_super; static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_ValueError; static const char __pyx_k__2[] = ""; static const char __pyx_k_new[] = "__new__"; static const char __pyx_k_dict[] = "__dict__"; static const char __pyx_k_init[] = "__init__"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_sock[] = "sock"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_items[] = "items"; static const char __pyx_k_super[] = "super"; static const char __pyx_k_write[] = "write"; static const char __pyx_k_encode[] = "encode"; static const char __pyx_k_errors[] = "errors"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_length[] = "length"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_update[] = "update"; static const char __pyx_k_varint[] = "varint"; static const char __pyx_k_bufsize[] = "bufsize"; static const char __pyx_k_sendall[] = "sendall"; static const char __pyx_k_encoding[] = "encoding"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_pyx_type[] = "__pyx_type"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_pyx_state[] = "__pyx_state"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; static const char __pyx_k_ValueError[] = "ValueError"; static const char __pyx_k_compressor[] = "compressor"; static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_make_varint[] = "make_varint"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_BufferedWriter[] = "BufferedWriter"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_write_into_stream[] = "write_into_stream"; static const char __pyx_k_TooLargeStringSize[] = "TooLargeStringSize"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; static const char __pyx_k_BufferedSocketWriter[] = "BufferedSocketWriter"; static const char __pyx_k_bytes_object_expected[] = "bytes object expected"; static const char __pyx_k_CompressedBufferedWriter[] = "CompressedBufferedWriter"; static const char __pyx_k_pyx_unpickle_BufferedWriter[] = "__pyx_unpickle_BufferedWriter"; static const char __pyx_k_write_fixed_strings_as_bytes[] = "write_fixed_strings_as_bytes"; static const char __pyx_k_pyx_unpickle_BufferedSocketWri[] = "__pyx_unpickle_BufferedSocketWriter"; static const char __pyx_k_pyx_unpickle_CompressedBuffere[] = "__pyx_unpickle_CompressedBufferedWriter"; static const char __pyx_k_Incompatible_checksums_s_vs_0x10[] = "Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))"; static const char __pyx_k_Incompatible_checksums_s_vs_0x25[] = "Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))"; static const char __pyx_k_Incompatible_checksums_s_vs_0x3b[] = "Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))"; static const char __pyx_k_clickhouse_driver_bufferedwriter[] = "clickhouse_driver.bufferedwriter"; static PyObject *__pyx_n_s_BufferedSocketWriter; static PyObject *__pyx_n_s_BufferedWriter; static PyObject *__pyx_n_s_CompressedBufferedWriter; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x10; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x25; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x3b; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_n_s_TooLargeStringSize; static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s__2; static PyObject *__pyx_n_s_bufsize; static PyObject *__pyx_kp_u_bytes_object_expected; static PyObject *__pyx_n_s_clickhouse_driver_bufferedwriter; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_compressor; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_encoding; static PyObject *__pyx_n_s_errors; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_init; static PyObject *__pyx_n_s_items; static PyObject *__pyx_n_s_length; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_make_varint; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_new; static PyObject *__pyx_n_s_pickle; static PyObject *__pyx_n_s_pyx_PickleError; static PyObject *__pyx_n_s_pyx_checksum; static PyObject *__pyx_n_s_pyx_result; static PyObject *__pyx_n_s_pyx_state; static PyObject *__pyx_n_s_pyx_type; static PyObject *__pyx_n_s_pyx_unpickle_BufferedSocketWri; static PyObject *__pyx_n_s_pyx_unpickle_BufferedWriter; static PyObject *__pyx_n_s_pyx_unpickle_CompressedBuffere; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_sendall; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_sock; static PyObject *__pyx_kp_s_stringsource; static PyObject *__pyx_n_s_super; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_update; static PyObject *__pyx_n_s_varint; static PyObject *__pyx_n_s_write; static PyObject *__pyx_n_s_write_fixed_strings_as_bytes; static PyObject *__pyx_n_s_write_into_stream; static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_bufsize); /* proto */ static void __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_2__dealloc__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_4write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_6write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_8flush(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_10write_strings(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_encoding); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_12write_fixed_strings_as_bytes(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, Py_ssize_t __pyx_v_length); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_14write_fixed_strings(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, Py_ssize_t __pyx_v_length, PyObject *__pyx_v_encoding); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_16__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_18__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, PyObject *__pyx_v_sock, PyObject *__pyx_v_bufsize); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_2write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, PyObject *__pyx_v_compressor, PyObject *__pyx_v_bufsize); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_2write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_4flush(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_6__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_8__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_2__pyx_unpickle_BufferedSocketWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_4__pyx_unpickle_CompressedBufferedWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedWriter(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_17355272; static PyObject *__pyx_int_39656716; static PyObject *__pyx_int_62583983; static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__7; static PyObject *__pyx_codeobj__4; static PyObject *__pyx_codeobj__6; static PyObject *__pyx_codeobj__8; /* Late includes */ /* "clickhouse_driver/bufferedwriter.pyx":14 * cdef unsigned long long position, buffer_size * * def __init__(self, unsigned long long bufsize): # <<<<<<<<<<<<<< * self.buffer = PyMem_Malloc(bufsize) * if not self.buffer: */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned PY_LONG_LONG __pyx_v_bufsize; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bufsize,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 14, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); } __pyx_v_bufsize = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_bufsize == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 14, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedwriter.pyx":15 * * def __init__(self, unsigned long long bufsize): * self.buffer = PyMem_Malloc(bufsize) # <<<<<<<<<<<<<< * if not self.buffer: * raise MemoryError() */ __pyx_v_self->buffer = ((char *)PyMem_Malloc(__pyx_v_bufsize)); /* "clickhouse_driver/bufferedwriter.pyx":16 * def __init__(self, unsigned long long bufsize): * self.buffer = PyMem_Malloc(bufsize) * if not self.buffer: # <<<<<<<<<<<<<< * raise MemoryError() * */ __pyx_t_1 = ((!(__pyx_v_self->buffer != 0)) != 0); if (unlikely(__pyx_t_1)) { /* "clickhouse_driver/bufferedwriter.pyx":17 * self.buffer = PyMem_Malloc(bufsize) * if not self.buffer: * raise MemoryError() # <<<<<<<<<<<<<< * * self.position = 0 */ PyErr_NoMemory(); __PYX_ERR(0, 17, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":16 * def __init__(self, unsigned long long bufsize): * self.buffer = PyMem_Malloc(bufsize) * if not self.buffer: # <<<<<<<<<<<<<< * raise MemoryError() * */ } /* "clickhouse_driver/bufferedwriter.pyx":19 * raise MemoryError() * * self.position = 0 # <<<<<<<<<<<<<< * self.buffer_size = bufsize * */ __pyx_v_self->position = 0; /* "clickhouse_driver/bufferedwriter.pyx":20 * * self.position = 0 * self.buffer_size = bufsize # <<<<<<<<<<<<<< * * super(BufferedWriter, self).__init__() */ __pyx_v_self->buffer_size = __pyx_v_bufsize; /* "clickhouse_driver/bufferedwriter.pyx":22 * self.buffer_size = bufsize * * super(BufferedWriter, self).__init__() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self)); __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_init); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/bufferedwriter.pyx":14 * cdef unsigned long long position, buffer_size * * def __init__(self, unsigned long long bufsize): # <<<<<<<<<<<<<< * self.buffer = PyMem_Malloc(bufsize) * if not self.buffer: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":24 * super(BufferedWriter, self).__init__() * * def __dealloc__(self): # <<<<<<<<<<<<<< * PyMem_Free(self.buffer) * */ /* Python wrapper */ static void __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_2__dealloc__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); } static void __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_2__dealloc__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); /* "clickhouse_driver/bufferedwriter.pyx":25 * * def __dealloc__(self): * PyMem_Free(self.buffer) # <<<<<<<<<<<<<< * * cpdef write_into_stream(self): */ PyMem_Free(__pyx_v_self->buffer); /* "clickhouse_driver/bufferedwriter.pyx":24 * super(BufferedWriter, self).__init__() * * def __dealloc__(self): # <<<<<<<<<<<<<< * PyMem_Free(self.buffer) * */ /* function exit code */ __Pyx_RefNannyFinishContext(); } /* "clickhouse_driver/bufferedwriter.pyx":27 * PyMem_Free(self.buffer) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * raise NotImplementedError * */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_5write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write_into_stream(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, int __pyx_skip_dispatch) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write_into_stream); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_5write_into_stream)) { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; } #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS } #endif } /* "clickhouse_driver/bufferedwriter.pyx":28 * * cpdef write_into_stream(self): * raise NotImplementedError # <<<<<<<<<<<<<< * * cpdef write(self, data): */ __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0); __PYX_ERR(0, 28, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":27 * PyMem_Free(self.buffer) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * raise NotImplementedError * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_5write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_5write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_into_stream (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_4write_into_stream(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_4write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":30 * raise NotImplementedError * * cpdef write(self, data): # <<<<<<<<<<<<<< * cdef unsigned long long size, written = 0 * cdef unsigned long long data_len = PyBytes_GET_SIZE(data) */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data, int __pyx_skip_dispatch) { unsigned PY_LONG_LONG __pyx_v_size; unsigned PY_LONG_LONG __pyx_v_written; unsigned PY_LONG_LONG __pyx_v_data_len; char *__pyx_v_c_data; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; unsigned PY_LONG_LONG __pyx_t_6; unsigned PY_LONG_LONG __pyx_t_7; unsigned PY_LONG_LONG __pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write", 0); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write)) { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_data) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_data); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; } #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS } #endif } /* "clickhouse_driver/bufferedwriter.pyx":31 * * cpdef write(self, data): * cdef unsigned long long size, written = 0 # <<<<<<<<<<<<<< * cdef unsigned long long data_len = PyBytes_GET_SIZE(data) * cdef char* c_data = PyBytes_AS_STRING(data) */ __pyx_v_written = 0; /* "clickhouse_driver/bufferedwriter.pyx":32 * cpdef write(self, data): * cdef unsigned long long size, written = 0 * cdef unsigned long long data_len = PyBytes_GET_SIZE(data) # <<<<<<<<<<<<<< * cdef char* c_data = PyBytes_AS_STRING(data) * */ __pyx_v_data_len = PyBytes_GET_SIZE(__pyx_v_data); /* "clickhouse_driver/bufferedwriter.pyx":33 * cdef unsigned long long size, written = 0 * cdef unsigned long long data_len = PyBytes_GET_SIZE(data) * cdef char* c_data = PyBytes_AS_STRING(data) # <<<<<<<<<<<<<< * * while written < data_len: */ __pyx_v_c_data = PyBytes_AS_STRING(__pyx_v_data); /* "clickhouse_driver/bufferedwriter.pyx":35 * cdef char* c_data = PyBytes_AS_STRING(data) * * while written < data_len: # <<<<<<<<<<<<<< * size = min(data_len - written, self.buffer_size - self.position) * memcpy(&self.buffer[self.position], &c_data[written], size) */ while (1) { __pyx_t_5 = ((__pyx_v_written < __pyx_v_data_len) != 0); if (!__pyx_t_5) break; /* "clickhouse_driver/bufferedwriter.pyx":36 * * while written < data_len: * size = min(data_len - written, self.buffer_size - self.position) # <<<<<<<<<<<<<< * memcpy(&self.buffer[self.position], &c_data[written], size) * */ __pyx_t_6 = (__pyx_v_self->buffer_size - __pyx_v_self->position); __pyx_t_7 = (__pyx_v_data_len - __pyx_v_written); if (((__pyx_t_6 < __pyx_t_7) != 0)) { __pyx_t_8 = __pyx_t_6; } else { __pyx_t_8 = __pyx_t_7; } __pyx_v_size = __pyx_t_8; /* "clickhouse_driver/bufferedwriter.pyx":37 * while written < data_len: * size = min(data_len - written, self.buffer_size - self.position) * memcpy(&self.buffer[self.position], &c_data[written], size) # <<<<<<<<<<<<<< * * if self.position == self.buffer_size: */ (void)(memcpy((&(__pyx_v_self->buffer[__pyx_v_self->position])), (&(__pyx_v_c_data[__pyx_v_written])), __pyx_v_size)); /* "clickhouse_driver/bufferedwriter.pyx":39 * memcpy(&self.buffer[self.position], &c_data[written], size) * * if self.position == self.buffer_size: # <<<<<<<<<<<<<< * self.write_into_stream() * */ __pyx_t_5 = ((__pyx_v_self->position == __pyx_v_self->buffer_size) != 0); if (__pyx_t_5) { /* "clickhouse_driver/bufferedwriter.pyx":40 * * if self.position == self.buffer_size: * self.write_into_stream() # <<<<<<<<<<<<<< * * self.position += size */ __pyx_t_1 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write_into_stream(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":39 * memcpy(&self.buffer[self.position], &c_data[written], size) * * if self.position == self.buffer_size: # <<<<<<<<<<<<<< * self.write_into_stream() * */ } /* "clickhouse_driver/bufferedwriter.pyx":42 * self.write_into_stream() * * self.position += size # <<<<<<<<<<<<<< * written += size * */ __pyx_v_self->position = (__pyx_v_self->position + __pyx_v_size); /* "clickhouse_driver/bufferedwriter.pyx":43 * * self.position += size * written += size # <<<<<<<<<<<<<< * * def flush(self): */ __pyx_v_written = (__pyx_v_written + __pyx_v_size); } /* "clickhouse_driver/bufferedwriter.pyx":30 * raise NotImplementedError * * cpdef write(self, data): # <<<<<<<<<<<<<< * cdef unsigned long long size, written = 0 * cdef unsigned long long data_len = PyBytes_GET_SIZE(data) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write(PyObject *__pyx_v_self, PyObject *__pyx_v_data) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_6write(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), ((PyObject *)__pyx_v_data)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_6write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write(__pyx_v_self, __pyx_v_data, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":45 * written += size * * def flush(self): # <<<<<<<<<<<<<< * self.write_into_stream() * */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_9flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_9flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("flush (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_8flush(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_8flush(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("flush", 0); /* "clickhouse_driver/bufferedwriter.pyx":46 * * def flush(self): * self.write_into_stream() # <<<<<<<<<<<<<< * * def write_strings(self, items, encoding=None): */ __pyx_t_1 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write_into_stream(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":45 * written += size * * def flush(self): # <<<<<<<<<<<<<< * self.write_into_stream() * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.flush", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":48 * self.write_into_stream() * * def write_strings(self, items, encoding=None): # <<<<<<<<<<<<<< * cdef int do_encode = encoding is not None * */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_11write_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_11write_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; PyObject *__pyx_v_encoding = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_strings (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_encoding,0}; PyObject* values[2] = {0,0}; values[1] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "write_strings") < 0)) __PYX_ERR(0, 48, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_items = values[0]; __pyx_v_encoding = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_strings", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 48, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_10write_strings(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), __pyx_v_items, __pyx_v_encoding); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_10write_strings(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_encoding) { int __pyx_v_do_encode; PyObject *__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; Py_ssize_t __pyx_t_3; PyObject *(*__pyx_t_4)(PyObject *); PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_strings", 0); /* "clickhouse_driver/bufferedwriter.pyx":49 * * def write_strings(self, items, encoding=None): * cdef int do_encode = encoding is not None # <<<<<<<<<<<<<< * * for value in items: */ __pyx_t_1 = (__pyx_v_encoding != Py_None); __pyx_v_do_encode = __pyx_t_1; /* "clickhouse_driver/bufferedwriter.pyx":51 * cdef int do_encode = encoding is not None * * for value in items: # <<<<<<<<<<<<<< * if not PyBytes_Check(value): * if do_encode: */ if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) { __pyx_t_2 = __pyx_v_items; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 51, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_4)) { if (likely(PyList_CheckExact(__pyx_t_2))) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 51, __pyx_L1_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 51, __pyx_L1_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } } else { __pyx_t_5 = __pyx_t_4(__pyx_t_2); if (unlikely(!__pyx_t_5)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 51, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_5); } __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/bufferedwriter.pyx":52 * * for value in items: * if not PyBytes_Check(value): # <<<<<<<<<<<<<< * if do_encode: * value = value.encode(encoding) */ __pyx_t_1 = ((!(PyBytes_Check(__pyx_v_value) != 0)) != 0); if (__pyx_t_1) { /* "clickhouse_driver/bufferedwriter.pyx":53 * for value in items: * if not PyBytes_Check(value): * if do_encode: # <<<<<<<<<<<<<< * value = value.encode(encoding) * else: */ __pyx_t_1 = (__pyx_v_do_encode != 0); if (likely(__pyx_t_1)) { /* "clickhouse_driver/bufferedwriter.pyx":54 * if not PyBytes_Check(value): * if do_encode: * value = value.encode(encoding) # <<<<<<<<<<<<<< * else: * raise ValueError('bytes object expected') */ __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); } } __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_v_encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_encoding); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/bufferedwriter.pyx":53 * for value in items: * if not PyBytes_Check(value): * if do_encode: # <<<<<<<<<<<<<< * value = value.encode(encoding) * else: */ goto __pyx_L6; } /* "clickhouse_driver/bufferedwriter.pyx":56 * value = value.encode(encoding) * else: * raise ValueError('bytes object expected') # <<<<<<<<<<<<<< * * self.write(make_varint(PyBytes_GET_SIZE(value))) */ /*else*/ { __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 56, __pyx_L1_error) } __pyx_L6:; /* "clickhouse_driver/bufferedwriter.pyx":52 * * for value in items: * if not PyBytes_Check(value): # <<<<<<<<<<<<<< * if do_encode: * value = value.encode(encoding) */ } /* "clickhouse_driver/bufferedwriter.pyx":58 * raise ValueError('bytes object expected') * * self.write(make_varint(PyBytes_GET_SIZE(value))) # <<<<<<<<<<<<<< * self.write(value) * */ __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_make_varint); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = PyInt_FromSsize_t(PyBytes_GET_SIZE(__pyx_v_value)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_8)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); } } __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_t_5, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/bufferedwriter.pyx":59 * * self.write(make_varint(PyBytes_GET_SIZE(value))) * self.write(value) # <<<<<<<<<<<<<< * * def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): */ __pyx_t_6 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_value, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/bufferedwriter.pyx":51 * cdef int do_encode = encoding is not None * * for value in items: # <<<<<<<<<<<<<< * if not PyBytes_Check(value): * if do_encode: */ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/bufferedwriter.pyx":48 * self.write_into_stream() * * def write_strings(self, items, encoding=None): # <<<<<<<<<<<<<< * cdef int do_encode = encoding is not None * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":61 * self.write(value) * * def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): # <<<<<<<<<<<<<< * cdef Py_ssize_t buf_pos = 0 * cdef Py_ssize_t items_buf_size = length * len(items) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_13write_fixed_strings_as_bytes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_13write_fixed_strings_as_bytes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; Py_ssize_t __pyx_v_length; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_fixed_strings_as_bytes (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_length,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_length)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("write_fixed_strings_as_bytes", 1, 2, 2, 1); __PYX_ERR(0, 61, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "write_fixed_strings_as_bytes") < 0)) __PYX_ERR(0, 61, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_items = values[0]; __pyx_v_length = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_length == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 61, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_fixed_strings_as_bytes", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 61, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_fixed_strings_as_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_12write_fixed_strings_as_bytes(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), __pyx_v_items, __pyx_v_length); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_12write_fixed_strings_as_bytes(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, Py_ssize_t __pyx_v_length) { Py_ssize_t __pyx_v_buf_pos; Py_ssize_t __pyx_v_items_buf_size; char *__pyx_v_c_value; char *__pyx_v_items_buf; PyObject *__pyx_v_value = NULL; Py_ssize_t __pyx_v_value_len; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations Py_ssize_t __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *(*__pyx_t_4)(PyObject *); PyObject *__pyx_t_5 = NULL; Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; char *__pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_fixed_strings_as_bytes", 0); /* "clickhouse_driver/bufferedwriter.pyx":62 * * def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): * cdef Py_ssize_t buf_pos = 0 # <<<<<<<<<<<<<< * cdef Py_ssize_t items_buf_size = length * len(items) * */ __pyx_v_buf_pos = 0; /* "clickhouse_driver/bufferedwriter.pyx":63 * def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): * cdef Py_ssize_t buf_pos = 0 * cdef Py_ssize_t items_buf_size = length * len(items) # <<<<<<<<<<<<<< * * cdef char* c_value */ __pyx_t_1 = PyObject_Length(__pyx_v_items); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 63, __pyx_L1_error) __pyx_v_items_buf_size = (__pyx_v_length * __pyx_t_1); /* "clickhouse_driver/bufferedwriter.pyx":66 * * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) # <<<<<<<<<<<<<< * if not items_buf: * raise MemoryError() */ __pyx_v_items_buf = ((char *)PyMem_Malloc(__pyx_v_items_buf_size)); /* "clickhouse_driver/bufferedwriter.pyx":67 * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: # <<<<<<<<<<<<<< * raise MemoryError() * */ __pyx_t_2 = ((!(__pyx_v_items_buf != 0)) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedwriter.pyx":68 * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: * raise MemoryError() # <<<<<<<<<<<<<< * * memset(items_buf, 0, items_buf_size) */ PyErr_NoMemory(); __PYX_ERR(0, 68, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":67 * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: # <<<<<<<<<<<<<< * raise MemoryError() * */ } /* "clickhouse_driver/bufferedwriter.pyx":70 * raise MemoryError() * * memset(items_buf, 0, items_buf_size) # <<<<<<<<<<<<<< * * for value in items: */ (void)(memset(__pyx_v_items_buf, 0, __pyx_v_items_buf_size)); /* "clickhouse_driver/bufferedwriter.pyx":72 * memset(items_buf, 0, items_buf_size) * * for value in items: # <<<<<<<<<<<<<< * value_len = len(value) * if length < value_len: */ if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) { __pyx_t_3 = __pyx_v_items; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_4 = NULL; } else { __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_4)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 72, __pyx_L1_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 72, __pyx_L1_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } } else { __pyx_t_5 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_5)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 72, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_5); } __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/bufferedwriter.pyx":73 * * for value in items: * value_len = len(value) # <<<<<<<<<<<<<< * if length < value_len: * raise errors.TooLargeStringSize() */ __pyx_t_6 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 73, __pyx_L1_error) __pyx_v_value_len = __pyx_t_6; /* "clickhouse_driver/bufferedwriter.pyx":74 * for value in items: * value_len = len(value) * if length < value_len: # <<<<<<<<<<<<<< * raise errors.TooLargeStringSize() * */ __pyx_t_2 = ((__pyx_v_length < __pyx_v_value_len) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedwriter.pyx":75 * value_len = len(value) * if length < value_len: * raise errors.TooLargeStringSize() # <<<<<<<<<<<<<< * * c_value = PyBytes_AsString(value) */ __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_errors); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_TooLargeStringSize); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_8); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 75, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":74 * for value in items: * value_len = len(value) * if length < value_len: # <<<<<<<<<<<<<< * raise errors.TooLargeStringSize() * */ } /* "clickhouse_driver/bufferedwriter.pyx":77 * raise errors.TooLargeStringSize() * * c_value = PyBytes_AsString(value) # <<<<<<<<<<<<<< * * memcpy(&items_buf[buf_pos], c_value, value_len) */ __pyx_t_9 = PyBytes_AsString(__pyx_v_value); if (unlikely(__pyx_t_9 == ((char *)NULL))) __PYX_ERR(0, 77, __pyx_L1_error) __pyx_v_c_value = __pyx_t_9; /* "clickhouse_driver/bufferedwriter.pyx":79 * c_value = PyBytes_AsString(value) * * memcpy(&items_buf[buf_pos], c_value, value_len) # <<<<<<<<<<<<<< * buf_pos += length * */ (void)(memcpy((&(__pyx_v_items_buf[__pyx_v_buf_pos])), __pyx_v_c_value, __pyx_v_value_len)); /* "clickhouse_driver/bufferedwriter.pyx":80 * * memcpy(&items_buf[buf_pos], c_value, value_len) * buf_pos += length # <<<<<<<<<<<<<< * * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) */ __pyx_v_buf_pos = (__pyx_v_buf_pos + __pyx_v_length); /* "clickhouse_driver/bufferedwriter.pyx":72 * memset(items_buf, 0, items_buf_size) * * for value in items: # <<<<<<<<<<<<<< * value_len = len(value) * if length < value_len: */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedwriter.pyx":82 * buf_pos += length * * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) # <<<<<<<<<<<<<< * * PyMem_Free(items_buf) */ __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_items_buf, __pyx_v_items_buf_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_t_3, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/bufferedwriter.pyx":84 * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) * * PyMem_Free(items_buf) # <<<<<<<<<<<<<< * * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): */ PyMem_Free(__pyx_v_items_buf); /* "clickhouse_driver/bufferedwriter.pyx":61 * self.write(value) * * def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): # <<<<<<<<<<<<<< * cdef Py_ssize_t buf_pos = 0 * cdef Py_ssize_t items_buf_size = length * len(items) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_fixed_strings_as_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":86 * PyMem_Free(items_buf) * * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): # <<<<<<<<<<<<<< * if encoding is None: * self.write_fixed_strings_as_bytes(items, length) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_15write_fixed_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_15write_fixed_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; Py_ssize_t __pyx_v_length; PyObject *__pyx_v_encoding = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_fixed_strings (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_length,&__pyx_n_s_encoding,0}; PyObject* values[3] = {0,0,0}; values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_length)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("write_fixed_strings", 0, 2, 3, 1); __PYX_ERR(0, 86, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "write_fixed_strings") < 0)) __PYX_ERR(0, 86, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_items = values[0]; __pyx_v_length = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_length == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L3_error) __pyx_v_encoding = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_fixed_strings", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 86, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_fixed_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_14write_fixed_strings(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), __pyx_v_items, __pyx_v_length, __pyx_v_encoding); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_14write_fixed_strings(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_items, Py_ssize_t __pyx_v_length, PyObject *__pyx_v_encoding) { Py_ssize_t __pyx_v_buf_pos; Py_ssize_t __pyx_v_items_buf_size; char *__pyx_v_c_value; char *__pyx_v_items_buf; PyObject *__pyx_v_value = NULL; Py_ssize_t __pyx_v_value_len; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; Py_ssize_t __pyx_t_9; PyObject *(*__pyx_t_10)(PyObject *); Py_ssize_t __pyx_t_11; char *__pyx_t_12; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_fixed_strings", 0); /* "clickhouse_driver/bufferedwriter.pyx":87 * * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): * if encoding is None: # <<<<<<<<<<<<<< * self.write_fixed_strings_as_bytes(items, length) * return */ __pyx_t_1 = (__pyx_v_encoding == Py_None); __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedwriter.pyx":88 * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): * if encoding is None: * self.write_fixed_strings_as_bytes(items, length) # <<<<<<<<<<<<<< * return * */ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write_fixed_strings_as_bytes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_7 = 0; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_7 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_items, __pyx_t_5}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_items, __pyx_t_5}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } __Pyx_INCREF(__pyx_v_items); __Pyx_GIVEREF(__pyx_v_items); PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_items); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedwriter.pyx":89 * if encoding is None: * self.write_fixed_strings_as_bytes(items, length) * return # <<<<<<<<<<<<<< * * cdef Py_ssize_t buf_pos = 0 */ __Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; /* "clickhouse_driver/bufferedwriter.pyx":87 * * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): * if encoding is None: # <<<<<<<<<<<<<< * self.write_fixed_strings_as_bytes(items, length) * return */ } /* "clickhouse_driver/bufferedwriter.pyx":91 * return * * cdef Py_ssize_t buf_pos = 0 # <<<<<<<<<<<<<< * cdef Py_ssize_t items_buf_size = length * len(items) * */ __pyx_v_buf_pos = 0; /* "clickhouse_driver/bufferedwriter.pyx":92 * * cdef Py_ssize_t buf_pos = 0 * cdef Py_ssize_t items_buf_size = length * len(items) # <<<<<<<<<<<<<< * * cdef char* c_value */ __pyx_t_9 = PyObject_Length(__pyx_v_items); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 92, __pyx_L1_error) __pyx_v_items_buf_size = (__pyx_v_length * __pyx_t_9); /* "clickhouse_driver/bufferedwriter.pyx":95 * * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) # <<<<<<<<<<<<<< * if not items_buf: * raise MemoryError() */ __pyx_v_items_buf = ((char *)PyMem_Malloc(__pyx_v_items_buf_size)); /* "clickhouse_driver/bufferedwriter.pyx":96 * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: # <<<<<<<<<<<<<< * raise MemoryError() * */ __pyx_t_2 = ((!(__pyx_v_items_buf != 0)) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedwriter.pyx":97 * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: * raise MemoryError() # <<<<<<<<<<<<<< * * memset(items_buf, 0, items_buf_size) */ PyErr_NoMemory(); __PYX_ERR(0, 97, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":96 * cdef char* c_value * cdef char* items_buf = PyMem_Malloc(items_buf_size) * if not items_buf: # <<<<<<<<<<<<<< * raise MemoryError() * */ } /* "clickhouse_driver/bufferedwriter.pyx":99 * raise MemoryError() * * memset(items_buf, 0, items_buf_size) # <<<<<<<<<<<<<< * * for value in items: */ (void)(memset(__pyx_v_items_buf, 0, __pyx_v_items_buf_size)); /* "clickhouse_driver/bufferedwriter.pyx":101 * memset(items_buf, 0, items_buf_size) * * for value in items: # <<<<<<<<<<<<<< * if not PyBytes_Check(value): * value = value.encode(encoding) */ if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) { __pyx_t_3 = __pyx_v_items; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0; __pyx_t_10 = NULL; } else { __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 101, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_10)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 101, __pyx_L1_error) #else __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 101, __pyx_L1_error) #else __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } } else { __pyx_t_4 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_4)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 101, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_4); } __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedwriter.pyx":102 * * for value in items: * if not PyBytes_Check(value): # <<<<<<<<<<<<<< * value = value.encode(encoding) * */ __pyx_t_2 = ((!(PyBytes_Check(__pyx_v_value) != 0)) != 0); if (__pyx_t_2) { /* "clickhouse_driver/bufferedwriter.pyx":103 * for value in items: * if not PyBytes_Check(value): * value = value.encode(encoding) # <<<<<<<<<<<<<< * * value_len = len(value) */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_v_encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_encoding); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedwriter.pyx":102 * * for value in items: * if not PyBytes_Check(value): # <<<<<<<<<<<<<< * value = value.encode(encoding) * */ } /* "clickhouse_driver/bufferedwriter.pyx":105 * value = value.encode(encoding) * * value_len = len(value) # <<<<<<<<<<<<<< * if length < value_len: * raise errors.TooLargeStringSize() */ __pyx_t_11 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 105, __pyx_L1_error) __pyx_v_value_len = __pyx_t_11; /* "clickhouse_driver/bufferedwriter.pyx":106 * * value_len = len(value) * if length < value_len: # <<<<<<<<<<<<<< * raise errors.TooLargeStringSize() * */ __pyx_t_2 = ((__pyx_v_length < __pyx_v_value_len) != 0); if (unlikely(__pyx_t_2)) { /* "clickhouse_driver/bufferedwriter.pyx":107 * value_len = len(value) * if length < value_len: * raise errors.TooLargeStringSize() # <<<<<<<<<<<<<< * * c_value = PyBytes_AsString(value) */ __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_errors); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_TooLargeStringSize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_8)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); } } __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_5); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 107, __pyx_L1_error) /* "clickhouse_driver/bufferedwriter.pyx":106 * * value_len = len(value) * if length < value_len: # <<<<<<<<<<<<<< * raise errors.TooLargeStringSize() * */ } /* "clickhouse_driver/bufferedwriter.pyx":109 * raise errors.TooLargeStringSize() * * c_value = PyBytes_AsString(value) # <<<<<<<<<<<<<< * * memcpy(&items_buf[buf_pos], c_value, value_len) */ __pyx_t_12 = PyBytes_AsString(__pyx_v_value); if (unlikely(__pyx_t_12 == ((char *)NULL))) __PYX_ERR(0, 109, __pyx_L1_error) __pyx_v_c_value = __pyx_t_12; /* "clickhouse_driver/bufferedwriter.pyx":111 * c_value = PyBytes_AsString(value) * * memcpy(&items_buf[buf_pos], c_value, value_len) # <<<<<<<<<<<<<< * buf_pos += length * */ (void)(memcpy((&(__pyx_v_items_buf[__pyx_v_buf_pos])), __pyx_v_c_value, __pyx_v_value_len)); /* "clickhouse_driver/bufferedwriter.pyx":112 * * memcpy(&items_buf[buf_pos], c_value, value_len) * buf_pos += length # <<<<<<<<<<<<<< * * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) */ __pyx_v_buf_pos = (__pyx_v_buf_pos + __pyx_v_length); /* "clickhouse_driver/bufferedwriter.pyx":101 * memset(items_buf, 0, items_buf_size) * * for value in items: # <<<<<<<<<<<<<< * if not PyBytes_Check(value): * value = value.encode(encoding) */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "clickhouse_driver/bufferedwriter.pyx":114 * buf_pos += length * * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) # <<<<<<<<<<<<<< * * PyMem_Free(items_buf) */ __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_items_buf, __pyx_v_items_buf_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_t_3, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; /* "clickhouse_driver/bufferedwriter.pyx":116 * self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) * * PyMem_Free(items_buf) # <<<<<<<<<<<<<< * * */ PyMem_Free(__pyx_v_items_buf); /* "clickhouse_driver/bufferedwriter.pyx":86 * PyMem_Free(items_buf) * * def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): # <<<<<<<<<<<<<< * if encoding is None: * self.write_fixed_strings_as_bytes(items, length) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.write_fixed_strings", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_16__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_16__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.position) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_v_state = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.position) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_4 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v__dict = __pyx_t_4; __pyx_t_4 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_5 = (__pyx_v__dict != Py_None); __pyx_t_6 = (__pyx_t_5 != 0); if (__pyx_t_6) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__dict); __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = False */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = False # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, None), state */ /*else*/ { __pyx_v_use_setstate = 0; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = False * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, None), state * else: */ __pyx_t_6 = (__pyx_v_use_setstate != 0); if (__pyx_t_6) { /* "(tree fragment)":13 * use_setstate = False * if use_setstate: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_BufferedWriter); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_39656716); __Pyx_GIVEREF(__pyx_int_39656716); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_39656716); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = False * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, None), state * else: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedWriter__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_BufferedWriter); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_39656716); __Pyx_GIVEREF(__pyx_int_39656716); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_39656716); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_state); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedWriter__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_18__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_18__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedWriter__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedWriter, (type(self), 0x25d1d0c, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedWriter__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedWriter.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":122 * cdef object sock * * def __init__(self, sock, bufsize): # <<<<<<<<<<<<<< * self.sock = sock * super(BufferedSocketWriter, self).__init__(bufsize) */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_sock = 0; PyObject *__pyx_v_bufsize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sock,&__pyx_n_s_bufsize,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sock)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 122, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 122, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_sock = values[0]; __pyx_v_bufsize = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 122, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)__pyx_v_self), __pyx_v_sock, __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, PyObject *__pyx_v_sock, PyObject *__pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedwriter.pyx":123 * * def __init__(self, sock, bufsize): * self.sock = sock # <<<<<<<<<<<<<< * super(BufferedSocketWriter, self).__init__(bufsize) * */ __Pyx_INCREF(__pyx_v_sock); __Pyx_GIVEREF(__pyx_v_sock); __Pyx_GOTREF(__pyx_v_self->sock); __Pyx_DECREF(__pyx_v_self->sock); __pyx_v_self->sock = __pyx_v_sock; /* "clickhouse_driver/bufferedwriter.pyx":124 * def __init__(self, sock, bufsize): * self.sock = sock * super(BufferedSocketWriter, self).__init__(bufsize) # <<<<<<<<<<<<<< * * cpdef write_into_stream(self): */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self)); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_bufsize) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_bufsize); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":122 * cdef object sock * * def __init__(self, sock, bufsize): # <<<<<<<<<<<<<< * self.sock = sock * super(BufferedSocketWriter, self).__init__(bufsize) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":126 * super(BufferedSocketWriter, self).__init__(bufsize) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * self.sock.sendall( * PyBytes_FromStringAndSize(self.buffer, self.position) */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, int __pyx_skip_dispatch) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write_into_stream); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_3write_into_stream)) { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; } #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS } #endif } /* "clickhouse_driver/bufferedwriter.pyx":127 * * cpdef write_into_stream(self): * self.sock.sendall( # <<<<<<<<<<<<<< * PyBytes_FromStringAndSize(self.buffer, self.position) * ) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->sock, __pyx_n_s_sendall); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "clickhouse_driver/bufferedwriter.pyx":128 * cpdef write_into_stream(self): * self.sock.sendall( * PyBytes_FromStringAndSize(self.buffer, self.position) # <<<<<<<<<<<<<< * ) * self.position = 0 */ __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_self->__pyx_base.buffer, __pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":130 * PyBytes_FromStringAndSize(self.buffer, self.position) * ) * self.position = 0 # <<<<<<<<<<<<<< * * */ __pyx_v_self->__pyx_base.position = 0; /* "clickhouse_driver/bufferedwriter.pyx":126 * super(BufferedSocketWriter, self).__init__(bufsize) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * self.sock.sendall( * PyBytes_FromStringAndSize(self.buffer, self.position) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_into_stream (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_2write_into_stream(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_2write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_4__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_4__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.position, self.sock) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_INCREF(__pyx_v_self->sock); __Pyx_GIVEREF(__pyx_v_self->sock); PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_self->sock); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_v_state = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_4 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v__dict = __pyx_t_4; __pyx_t_4 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_5 = (__pyx_v__dict != Py_None); __pyx_t_6 = (__pyx_t_5 != 0); if (__pyx_t_6) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__dict); __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = self.sock is not None */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.position, self.sock) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = self.sock is not None # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, None), state */ /*else*/ { __pyx_t_6 = (__pyx_v_self->sock != Py_None); __pyx_v_use_setstate = __pyx_t_6; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = self.sock is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, None), state * else: */ __pyx_t_6 = (__pyx_v_use_setstate != 0); if (__pyx_t_6) { /* "(tree fragment)":13 * use_setstate = self.sock is not None * if use_setstate: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_BufferedSocketWri); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_62583983); __Pyx_GIVEREF(__pyx_int_62583983); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_62583983); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = self.sock is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, None), state * else: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedSocketWriter__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_BufferedSocketWri); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_62583983); __Pyx_GIVEREF(__pyx_int_62583983); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_62583983); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_state); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketWriter__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_6__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_6__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BufferedSocketWriter__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedSocketWriter__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_BufferedSocketWriter, (type(self), 0x3baf4af, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketWriter__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.BufferedSocketWriter.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":136 * cdef object compressor * * def __init__(self, compressor, bufsize): # <<<<<<<<<<<<<< * self.compressor = compressor * super(CompressedBufferedWriter, self).__init__(bufsize) */ /* Python wrapper */ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_compressor = 0; PyObject *__pyx_v_bufsize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_compressor,&__pyx_n_s_bufsize,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_compressor)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bufsize)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 136, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 136, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_compressor = values[0]; __pyx_v_bufsize = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 136, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter___init__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self), __pyx_v_compressor, __pyx_v_bufsize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, PyObject *__pyx_v_compressor, PyObject *__pyx_v_bufsize) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "clickhouse_driver/bufferedwriter.pyx":137 * * def __init__(self, compressor, bufsize): * self.compressor = compressor # <<<<<<<<<<<<<< * super(CompressedBufferedWriter, self).__init__(bufsize) * */ __Pyx_INCREF(__pyx_v_compressor); __Pyx_GIVEREF(__pyx_v_compressor); __Pyx_GOTREF(__pyx_v_self->compressor); __Pyx_DECREF(__pyx_v_self->compressor); __pyx_v_self->compressor = __pyx_v_compressor; /* "clickhouse_driver/bufferedwriter.pyx":138 * def __init__(self, compressor, bufsize): * self.compressor = compressor * super(CompressedBufferedWriter, self).__init__(bufsize) # <<<<<<<<<<<<<< * * cpdef write_into_stream(self): */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter)); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self)); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_bufsize) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_bufsize); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":136 * cdef object compressor * * def __init__(self, compressor, bufsize): # <<<<<<<<<<<<<< * self.compressor = compressor * super(CompressedBufferedWriter, self).__init__(bufsize) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":140 * super(CompressedBufferedWriter, self).__init__(bufsize) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * self.compressor.write( * PyBytes_FromStringAndSize(self.buffer, self.position) */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, int __pyx_skip_dispatch) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write_into_stream); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_3write_into_stream)) { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; } #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; } #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS } #endif } /* "clickhouse_driver/bufferedwriter.pyx":141 * * cpdef write_into_stream(self): * self.compressor.write( # <<<<<<<<<<<<<< * PyBytes_FromStringAndSize(self.buffer, self.position) * ) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->compressor, __pyx_n_s_write); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "clickhouse_driver/bufferedwriter.pyx":142 * cpdef write_into_stream(self): * self.compressor.write( * PyBytes_FromStringAndSize(self.buffer, self.position) # <<<<<<<<<<<<<< * ) * self.position = 0 */ __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_self->__pyx_base.buffer, __pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":144 * PyBytes_FromStringAndSize(self.buffer, self.position) * ) * self.position = 0 # <<<<<<<<<<<<<< * * def flush(self): */ __pyx_v_self->__pyx_base.position = 0; /* "clickhouse_driver/bufferedwriter.pyx":140 * super(CompressedBufferedWriter, self).__init__(bufsize) * * cpdef write_into_stream(self): # <<<<<<<<<<<<<< * self.compressor.write( * PyBytes_FromStringAndSize(self.buffer, self.position) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_3write_into_stream(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_into_stream (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_2write_into_stream(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_2write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_into_stream", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.write_into_stream", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/bufferedwriter.pyx":146 * self.position = 0 * * def flush(self): # <<<<<<<<<<<<<< * self.write_into_stream() */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_5flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_5flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("flush (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_4flush(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_4flush(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("flush", 0); /* "clickhouse_driver/bufferedwriter.pyx":147 * * def flush(self): * self.write_into_stream() # <<<<<<<<<<<<<< */ __pyx_t_1 = ((struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.write_into_stream(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v_self), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":146 * self.position = 0 * * def flush(self): # <<<<<<<<<<<<<< * self.write_into_stream() */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.flush", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_6__reduce_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_6__reduce_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self) { PyObject *__pyx_v_state = 0; PyObject *__pyx_v__dict = 0; int __pyx_v_use_setstate; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":5 * cdef object _dict * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.compressor, self.position) # <<<<<<<<<<<<<< * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_INCREF(__pyx_v_self->compressor); __Pyx_GIVEREF(__pyx_v_self->compressor); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_self->compressor); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_v_state = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; /* "(tree fragment)":6 * cdef bint use_setstate * state = (self.buffer, self.buffer_size, self.compressor, self.position) * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< * if _dict is not None: * state += (_dict,) */ __pyx_t_4 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v__dict = __pyx_t_4; __pyx_t_4 = 0; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.compressor, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ __pyx_t_5 = (__pyx_v__dict != Py_None); __pyx_t_6 = (__pyx_t_5 != 0); if (__pyx_t_6) { /* "(tree fragment)":8 * _dict = getattr(self, '__dict__', None) * if _dict is not None: * state += (_dict,) # <<<<<<<<<<<<<< * use_setstate = True * else: */ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__dict); __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; /* "(tree fragment)":9 * if _dict is not None: * state += (_dict,) * use_setstate = True # <<<<<<<<<<<<<< * else: * use_setstate = self.compressor is not None */ __pyx_v_use_setstate = 1; /* "(tree fragment)":7 * state = (self.buffer, self.buffer_size, self.compressor, self.position) * _dict = getattr(self, '__dict__', None) * if _dict is not None: # <<<<<<<<<<<<<< * state += (_dict,) * use_setstate = True */ goto __pyx_L3; } /* "(tree fragment)":11 * use_setstate = True * else: * use_setstate = self.compressor is not None # <<<<<<<<<<<<<< * if use_setstate: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, None), state */ /*else*/ { __pyx_t_6 = (__pyx_v_self->compressor != Py_None); __pyx_v_use_setstate = __pyx_t_6; } __pyx_L3:; /* "(tree fragment)":12 * else: * use_setstate = self.compressor is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, None), state * else: */ __pyx_t_6 = (__pyx_v_use_setstate != 0); if (__pyx_t_6) { /* "(tree fragment)":13 * use_setstate = self.compressor is not None * if use_setstate: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, None), state # <<<<<<<<<<<<<< * else: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, state) */ __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_CompressedBuffere); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_17355272); __Pyx_GIVEREF(__pyx_int_17355272); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_17355272); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "(tree fragment)":12 * else: * use_setstate = self.compressor is not None * if use_setstate: # <<<<<<<<<<<<<< * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, None), state * else: */ } /* "(tree fragment)":15 * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, None), state * else: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_CompressedBufferedWriter__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_CompressedBuffere); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_INCREF(__pyx_int_17355272); __Pyx_GIVEREF(__pyx_int_17355272); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_17355272); __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_state); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef tuple state * cdef object _dict */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":16 * else: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedWriter__set_state(self, __pyx_state) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_8__setstate_cython__(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_8__setstate_cython__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":17 * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_CompressedBufferedWriter__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_CompressedBufferedWriter__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":16 * else: * return __pyx_unpickle_CompressedBufferedWriter, (type(self), 0x108d208, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedWriter__set_state(self, __pyx_state) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.CompressedBufferedWriter.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_BufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_BufferedWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_BufferedWriter = {"__pyx_unpickle_BufferedWriter", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_BufferedWriter, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_BufferedWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedWriter", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedWriter", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BufferedWriter") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedWriter", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x25d1d0c: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x25d1d0c) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0x25d1d0c: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedWriter.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0x25d1d0c: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = BufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x25, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x25d1d0c: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedWriter.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = BufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x25d1d0c = (buffer, buffer_size, position))" % __pyx_checksum) * __pyx_result = BufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_BufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; char *__pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; int __pyx_t_6; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] # <<<<<<<<<<<<<< * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[3]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_AsWritableString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __pyx_v___pyx_result->buffer = __pyx_t_2; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->buffer_size = __pyx_t_3; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->position = __pyx_t_3; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[3]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = ((__pyx_t_5 > 3) != 0); if (__pyx_t_6) { } else { __pyx_t_4 = __pyx_t_6; goto __pyx_L4_bool_binop_done; } __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_7 = (__pyx_t_6 != 0); __pyx_t_4 = __pyx_t_7; __pyx_L4_bool_binop_done:; if (__pyx_t_4) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[3]) # <<<<<<<<<<<<<< */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[3]) */ } /* "(tree fragment)":11 * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_BufferedSocketWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_BufferedSocketWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_BufferedSocketWriter = {"__pyx_unpickle_BufferedSocketWriter", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_BufferedSocketWriter, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_BufferedSocketWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketWriter", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketWriter", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BufferedSocketWriter") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BufferedSocketWriter", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedSocketWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_2__pyx_unpickle_BufferedSocketWriter(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_2__pyx_unpickle_BufferedSocketWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x3baf4af: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x3baf4af) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0x3baf4af: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0x3baf4af: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x3b, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x3baf4af: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedSocketWriter__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3baf4af = (buffer, buffer_size, position, sock))" % __pyx_checksum) * __pyx_result = BufferedSocketWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_BufferedSocketWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedSocketWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_BufferedSocketWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; char *__pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; int __pyx_t_6; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] # <<<<<<<<<<<<<< * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_AsWritableString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __pyx_v___pyx_result->__pyx_base.buffer = __pyx_t_2; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.buffer_size = __pyx_t_3; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.position = __pyx_t_3; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->sock); __Pyx_DECREF(__pyx_v___pyx_result->sock); __pyx_v___pyx_result->sock = __pyx_t_1; __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = ((__pyx_t_5 > 4) != 0); if (__pyx_t_6) { } else { __pyx_t_4 = __pyx_t_6; goto __pyx_L4_bool_binop_done; } __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_7 = (__pyx_t_6 != 0); __pyx_t_4 = __pyx_t_7; __pyx_L4_bool_binop_done:; if (__pyx_t_4) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) # <<<<<<<<<<<<<< */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ } /* "(tree fragment)":11 * __pyx_unpickle_BufferedSocketWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedSocketWriter__set_state(BufferedSocketWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2]; __pyx_result.sock = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedSocketWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_CompressedBufferedWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_CompressedBufferedWriter = {"__pyx_unpickle_CompressedBufferedWriter", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_CompressedBufferedWriter, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_CompressedBufferedWriter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedWriter", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedWriter", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_CompressedBufferedWriter") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CompressedBufferedWriter", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_CompressedBufferedWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedwriter_4__pyx_unpickle_CompressedBufferedWriter(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_4__pyx_unpickle_CompressedBufferedWriter(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = 0; PyObject *__pyx_v___pyx_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter", 0); /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x108d208: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) */ __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x108d208) != 0); if (__pyx_t_1) { /* "(tree fragment)":5 * cdef object __pyx_result * if __pyx_checksum != 0x108d208: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * if __pyx_checksum != 0x108d208: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) # <<<<<<<<<<<<<< * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x10, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 6, __pyx_L1_error) /* "(tree fragment)":4 * cdef object __pyx_PickleError * cdef object __pyx_result * if __pyx_checksum != 0x108d208: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) */ } /* "(tree fragment)":7 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v___pyx_result = __pyx_t_3; __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { /* "(tree fragment)":9 * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) __pyx_t_3 = __pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_CompressedBufferedWriter__set_state(((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":8 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x108d208 = (buffer, buffer_size, compressor, position))" % __pyx_checksum) * __pyx_result = CompressedBufferedWriter.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":10 * if __pyx_state is not None: * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v___pyx_result); __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_CompressedBufferedWriter", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":11 * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_CompressedBufferedWriter__set_state(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; char *__pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; int __pyx_t_4; Py_ssize_t __pyx_t_5; int __pyx_t_6; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter__set_state", 0); /* "(tree fragment)":12 * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] # <<<<<<<<<<<<<< * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_AsWritableString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __pyx_v___pyx_result->__pyx_base.buffer = __pyx_t_2; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.buffer_size = __pyx_t_3; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->compressor); __Pyx_DECREF(__pyx_v___pyx_result->compressor); __pyx_v___pyx_result->compressor = __pyx_t_1; __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 12, __pyx_L1_error) } __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->__pyx_base.position = __pyx_t_3; /* "(tree fragment)":13 * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 13, __pyx_L1_error) } __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_6 = ((__pyx_t_5 > 4) != 0); if (__pyx_t_6) { } else { __pyx_t_4 = __pyx_t_6; goto __pyx_L4_bool_binop_done; } __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) __pyx_t_7 = (__pyx_t_6 != 0); __pyx_t_4 = __pyx_t_7; __pyx_L4_bool_binop_done:; if (__pyx_t_4) { /* "(tree fragment)":14 * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) # <<<<<<<<<<<<<< */ __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(1, 14, __pyx_L1_error) } __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_10 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":13 * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) */ } /* "(tree fragment)":11 * __pyx_unpickle_CompressedBufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_CompressedBufferedWriter__set_state(CompressedBufferedWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.compressor = __pyx_state[2]; __pyx_result.position = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_CompressedBufferedWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedWriter; static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedWriter(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *p; PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *)o); p->__pyx_vtab = __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter; return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedWriter(PyObject *o) { #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_3__dealloc__(o); __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedwriter_BufferedWriter[] = { {"write_into_stream", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_5write_into_stream, METH_NOARGS, 0}, {"write", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write, METH_O, 0}, {"flush", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_9flush, METH_NOARGS, 0}, {"write_strings", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_11write_strings, METH_VARARGS|METH_KEYWORDS, 0}, {"write_fixed_strings_as_bytes", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_13write_fixed_strings_as_bytes, METH_VARARGS|METH_KEYWORDS, 0}, {"write_fixed_strings", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_15write_fixed_strings, METH_VARARGS|METH_KEYWORDS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_17__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_19__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedwriter.BufferedWriter", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedWriter, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedwriter_BufferedWriter, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedWriter, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *p; PyObject *o = __pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedWriter(t, a, k); if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter*)__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; p->sock = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter(PyObject *o) { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->sock); #if CYTHON_USE_TYPE_SLOTS if (PyType_IS_GC(Py_TYPE(o)->tp_base)) #endif PyObject_GC_Track(o); __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedWriter(o); } static int __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)o; e = ((likely(__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)) ? ((__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_traverse) ? __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter)); if (e) return e; if (p->sock) { e = (*v)(p->sock, a); if (e) return e; } return 0; } static int __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter(PyObject *o) { PyObject* tmp; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter *)o; if (likely(__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)) { if (__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_clear) __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter); tmp = ((PyObject*)p->sock); p->sock = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter[] = { {"write_into_stream", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_3write_into_stream, METH_NOARGS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_5__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_7__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedwriter.BufferedSocketWriter", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter, /*tp_traverse*/ __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter __pyx_vtable_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; static PyObject *__pyx_tp_new_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *p; PyObject *o = __pyx_tp_new_17clickhouse_driver_14bufferedwriter_BufferedWriter(t, a, k); if (unlikely(!o)) return 0; p = ((struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter*)__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; p->compressor = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter(PyObject *o) { struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->compressor); #if CYTHON_USE_TYPE_SLOTS if (PyType_IS_GC(Py_TYPE(o)->tp_base)) #endif PyObject_GC_Track(o); __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedWriter(o); } static int __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)o; e = ((likely(__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)) ? ((__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_traverse) ? __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter)); if (e) return e; if (p->compressor) { e = (*v)(p->compressor, a); if (e) return e; } return 0; } static int __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter(PyObject *o) { PyObject* tmp; struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *p = (struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter *)o; if (likely(__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter)) { if (__pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_clear) __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter); tmp = ((PyObject*)p->compressor); p->compressor = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter[] = { {"write_into_stream", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_3write_into_stream, METH_NOARGS, 0}, {"flush", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_5flush, METH_NOARGS, 0}, {"__reduce_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_7__reduce_cython__, METH_NOARGS, 0}, {"__setstate_cython__", (PyCFunction)__pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_9__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter = { PyVarObject_HEAD_INIT(0, 0) "clickhouse_driver.bufferedwriter.CompressedBufferedWriter", /*tp_name*/ sizeof(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter, /*tp_dealloc*/ #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ #endif #if PY_VERSION_HEX >= 0x030800b4 0, /*tp_vectorcall_offset*/ #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter, /*tp_traverse*/ __pyx_tp_clear_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif #if PY_VERSION_HEX >= 0x030800b1 0, /*tp_vectorcall*/ #endif #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 0, /*tp_print*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 #if CYTHON_PEP489_MULTI_PHASE_INIT static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ static int __pyx_pymod_exec_bufferedwriter(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec_bufferedwriter}, {0, NULL} }; #endif static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, "bufferedwriter", 0, /* m_doc */ #if CYTHON_PEP489_MULTI_PHASE_INIT 0, /* m_size */ #else -1, /* m_size */ #endif __pyx_methods /* m_methods */, #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_moduledef_slots, /* m_slots */ #else NULL, /* m_reload */ #endif NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif #ifndef CYTHON_SMALL_CODE #if defined(__clang__) #define CYTHON_SMALL_CODE #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) #define CYTHON_SMALL_CODE __attribute__((cold)) #else #define CYTHON_SMALL_CODE #endif #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_BufferedSocketWriter, __pyx_k_BufferedSocketWriter, sizeof(__pyx_k_BufferedSocketWriter), 0, 0, 1, 1}, {&__pyx_n_s_BufferedWriter, __pyx_k_BufferedWriter, sizeof(__pyx_k_BufferedWriter), 0, 0, 1, 1}, {&__pyx_n_s_CompressedBufferedWriter, __pyx_k_CompressedBufferedWriter, sizeof(__pyx_k_CompressedBufferedWriter), 0, 0, 1, 1}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x10, __pyx_k_Incompatible_checksums_s_vs_0x10, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x10), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x25, __pyx_k_Incompatible_checksums_s_vs_0x25, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x25), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x3b, __pyx_k_Incompatible_checksums_s_vs_0x3b, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x3b), 0, 0, 1, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_TooLargeStringSize, __pyx_k_TooLargeStringSize, sizeof(__pyx_k_TooLargeStringSize), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, {&__pyx_n_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 1}, {&__pyx_n_s_bufsize, __pyx_k_bufsize, sizeof(__pyx_k_bufsize), 0, 0, 1, 1}, {&__pyx_kp_u_bytes_object_expected, __pyx_k_bytes_object_expected, sizeof(__pyx_k_bytes_object_expected), 0, 1, 0, 0}, {&__pyx_n_s_clickhouse_driver_bufferedwriter, __pyx_k_clickhouse_driver_bufferedwriter, sizeof(__pyx_k_clickhouse_driver_bufferedwriter), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_compressor, __pyx_k_compressor, sizeof(__pyx_k_compressor), 0, 0, 1, 1}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, {&__pyx_n_s_encoding, __pyx_k_encoding, sizeof(__pyx_k_encoding), 0, 0, 1, 1}, {&__pyx_n_s_errors, __pyx_k_errors, sizeof(__pyx_k_errors), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_make_varint, __pyx_k_make_varint, sizeof(__pyx_k_make_varint), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_BufferedSocketWri, __pyx_k_pyx_unpickle_BufferedSocketWri, sizeof(__pyx_k_pyx_unpickle_BufferedSocketWri), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_BufferedWriter, __pyx_k_pyx_unpickle_BufferedWriter, sizeof(__pyx_k_pyx_unpickle_BufferedWriter), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_CompressedBuffere, __pyx_k_pyx_unpickle_CompressedBuffere, sizeof(__pyx_k_pyx_unpickle_CompressedBuffere), 0, 0, 1, 1}, {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_sendall, __pyx_k_sendall, sizeof(__pyx_k_sendall), 0, 0, 1, 1}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, {&__pyx_n_s_sock, __pyx_k_sock, sizeof(__pyx_k_sock), 0, 0, 1, 1}, {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, {&__pyx_n_s_varint, __pyx_k_varint, sizeof(__pyx_k_varint), 0, 0, 1, 1}, {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1}, {&__pyx_n_s_write_fixed_strings_as_bytes, __pyx_k_write_fixed_strings_as_bytes, sizeof(__pyx_k_write_fixed_strings_as_bytes), 0, 0, 1, 1}, {&__pyx_n_s_write_into_stream, __pyx_k_write_into_stream, sizeof(__pyx_k_write_into_stream), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 17, __pyx_L1_error) __pyx_builtin_super = __Pyx_GetBuiltinName(__pyx_n_s_super); if (!__pyx_builtin_super) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 28, __pyx_L1_error) __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 56, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "clickhouse_driver/bufferedwriter.pyx":56 * value = value.encode(encoding) * else: * raise ValueError('bytes object expected') # <<<<<<<<<<<<<< * * self.write(make_varint(PyBytes_GET_SIZE(value))) */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_bytes_object_expected); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* "(tree fragment)":1 * def __pyx_unpickle_BufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_tuple__3 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_BufferedWriter, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(1, 1, __pyx_L1_error) __pyx_tuple__5 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_BufferedSocketWri, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(1, 1, __pyx_L1_error) __pyx_tuple__7 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_CompressedBuffere, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_int_17355272 = PyInt_FromLong(17355272L); if (unlikely(!__pyx_int_17355272)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_39656716 = PyInt_FromLong(39656716L); if (unlikely(!__pyx_int_39656716)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_62583983 = PyInt_FromLong(62583983L); if (unlikely(!__pyx_int_62583983)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ static int __Pyx_modinit_global_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); /*--- Global init code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_variable_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); /*--- Variable export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); /*--- Function export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter = &__pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedWriter; __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedWriter.write_into_stream = (PyObject *(*)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, int __pyx_skip_dispatch))__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write_into_stream; __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedWriter.write = (PyObject *(*)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, PyObject *, int __pyx_skip_dispatch))__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write; if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter) < 0) __PYX_ERR(0, 10, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (__Pyx_SetVtable(__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter.tp_dict, __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter) < 0) __PYX_ERR(0, 10, __pyx_L1_error) if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BufferedWriter, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter) < 0) __PYX_ERR(0, 10, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter) < 0) __PYX_ERR(0, 10, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter = &__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedWriter; __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter = &__pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.__pyx_base = *__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter; __pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.__pyx_base.write_into_stream = (PyObject *(*)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, int __pyx_skip_dispatch))__pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_write_into_stream; __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_base = __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter; if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter) < 0) __PYX_ERR(0, 119, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (__Pyx_SetVtable(__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter.tp_dict, __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter) < 0) __PYX_ERR(0, 119, __pyx_L1_error) if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BufferedSocketWriter, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter) < 0) __PYX_ERR(0, 119, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter) < 0) __PYX_ERR(0, 119, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter = &__pyx_type_17clickhouse_driver_14bufferedwriter_BufferedSocketWriter; __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter = &__pyx_vtable_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; __pyx_vtable_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.__pyx_base = *__pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter; __pyx_vtable_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.__pyx_base.write_into_stream = (PyObject *(*)(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *, int __pyx_skip_dispatch))__pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_write_into_stream; __pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_base = __pyx_ptype_17clickhouse_driver_14bufferedwriter_BufferedWriter; if (PyType_Ready(&__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter) < 0) __PYX_ERR(0, 133, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_dictoffset && __pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (__Pyx_SetVtable(__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter.tp_dict, __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter) < 0) __PYX_ERR(0, 133, __pyx_L1_error) if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CompressedBufferedWriter, (PyObject *)&__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter) < 0) __PYX_ERR(0, 133, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter) < 0) __PYX_ERR(0, 133, __pyx_L1_error) __pyx_ptype_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter = &__pyx_type_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_type_import_code(void) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); /*--- Type import code ---*/ __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), #else sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_variable_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); /*--- Variable import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } #ifndef CYTHON_NO_PYINIT_EXPORT #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC #elif PY_MAJOR_VERSION < 3 #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" void #else #define __Pyx_PyMODINIT_FUNC void #endif #else #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" PyObject * #else #define __Pyx_PyMODINIT_FUNC PyObject * #endif #endif #if PY_MAJOR_VERSION < 3 __Pyx_PyMODINIT_FUNC initbufferedwriter(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC initbufferedwriter(void) #else __Pyx_PyMODINIT_FUNC PyInit_bufferedwriter(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit_bufferedwriter(void) #if CYTHON_PEP489_MULTI_PHASE_INIT { return PyModuleDef_Init(&__pyx_moduledef); } static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { #if PY_VERSION_HEX >= 0x030700A1 static PY_INT64_T main_interpreter_id = -1; PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); if (main_interpreter_id == -1) { main_interpreter_id = current_id; return (unlikely(current_id == -1)) ? -1 : 0; } else if (unlikely(main_interpreter_id != current_id)) #else static PyInterpreterState *main_interpreter = NULL; PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; if (!main_interpreter) { main_interpreter = current_interpreter; } else if (unlikely(main_interpreter != current_interpreter)) #endif { PyErr_SetString( PyExc_ImportError, "Interpreter change detected - this module can only be loaded into one interpreter per process."); return -1; } return 0; } 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) { PyObject *value = PyObject_GetAttrString(spec, from_name); int result = 0; if (likely(value)) { if (allow_none || value != Py_None) { result = PyDict_SetItemString(moddict, to_name, value); } Py_DECREF(value); } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); } else { result = -1; } return result; } static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { PyObject *module = NULL, *moddict, *modname; if (__Pyx_check_single_interpreter()) return NULL; if (__pyx_m) return __Pyx_NewRef(__pyx_m); modname = PyObject_GetAttrString(spec, "name"); if (unlikely(!modname)) goto bad; module = PyModule_NewObject(modname); Py_DECREF(modname); if (unlikely(!module)) goto bad; moddict = PyModule_GetDict(module); if (unlikely(!moddict)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; return module; bad: Py_XDECREF(module); return NULL; } static CYTHON_SMALL_CODE int __pyx_pymod_exec_bufferedwriter(PyObject *__pyx_pyinit_module) #endif #endif { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m) { if (__pyx_m == __pyx_pyinit_module) return 0; PyErr_SetString(PyExc_RuntimeError, "Module 'bufferedwriter' has already been imported. Re-initialisation is not supported."); return -1; } #elif PY_MAJOR_VERSION >= 3 if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_bufferedwriter(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pxy_PyFrame_Initialize_Offsets __Pxy_PyFrame_Initialize_Offsets(); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_m = __pyx_pyinit_module; Py_INCREF(__pyx_m); #else #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("bufferedwriter", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) #endif __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_clickhouse_driver__bufferedwriter) { if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "clickhouse_driver.bufferedwriter")) { if (unlikely(PyDict_SetItemString(modules, "clickhouse_driver.bufferedwriter", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Global type/function init code ---*/ (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); (void)__Pyx_modinit_function_export_code(); if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_variable_import_code(); (void)__Pyx_modinit_function_import_code(); /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /* "clickhouse_driver/bufferedwriter.pyx":6 * from libc.string cimport memcpy, memset * * from . import errors # <<<<<<<<<<<<<< * from .varint import make_varint * */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_errors); __Pyx_GIVEREF(__pyx_n_s_errors); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_errors); __pyx_t_2 = __Pyx_Import(__pyx_n_s__2, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_errors); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_errors, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/bufferedwriter.pyx":7 * * from . import errors * from .varint import make_varint # <<<<<<<<<<<<<< * * */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_make_varint); __Pyx_GIVEREF(__pyx_n_s_make_varint); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_make_varint); __pyx_t_1 = __Pyx_Import(__pyx_n_s_varint, __pyx_t_2, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_make_varint); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_make_varint, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_BufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_BufferedWriter, NULL, __pyx_n_s_clickhouse_driver_bufferedwriter); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BufferedWriter, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":11 * __pyx_unpickle_BufferedWriter__set_state( __pyx_result, __pyx_state) * return __pyx_result * cdef __pyx_unpickle_BufferedWriter__set_state(BufferedWriter __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.buffer = __pyx_state[0]; __pyx_result.buffer_size = __pyx_state[1]; __pyx_result.position = __pyx_state[2] * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_BufferedSocketWriter, NULL, __pyx_n_s_clickhouse_driver_bufferedwriter); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BufferedSocketWri, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_CompressedBufferedWriter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * cdef object __pyx_PickleError * cdef object __pyx_result */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_CompressedBufferedWriter, NULL, __pyx_n_s_clickhouse_driver_bufferedwriter); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_CompressedBuffere, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/bufferedwriter.pyx":1 * from cpython cimport PyMem_Malloc, PyMem_Free, PyBytes_AsString, \ # <<<<<<<<<<<<<< * PyBytes_Check, PyBytes_FromStringAndSize, PyBytes_AS_STRING, \ * PyBytes_GET_SIZE */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init clickhouse_driver.bufferedwriter", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init clickhouse_driver.bufferedwriter"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if CYTHON_PEP489_MULTI_PHASE_INIT return (__pyx_m != NULL) ? 0 : -1; #elif PY_MAJOR_VERSION >= 3 return __pyx_m; #else return; #endif } /* --- Runtime support code --- */ /* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule(modname); if (!m) goto end; p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif /* PyObjectGetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #endif /* GetBuiltinName */ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { PyErr_Format(PyExc_NameError, #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } /* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* PyObjectCall */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; ternaryfunc call = func->ob_type->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyFunctionFastCall */ #if CYTHON_FAST_PYCALL static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, PyObject *globals) { PyFrameObject *f; PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject **fastlocals; Py_ssize_t i; PyObject *result; assert(globals != NULL); /* XXX Perhaps we should create a specialized PyFrame_New() that doesn't take locals, but does take builtins without sanity checking them. */ assert(tstate != NULL); f = PyFrame_New(tstate, co, globals, NULL); if (f == NULL) { return NULL; } fastlocals = __Pyx_PyFrame_GetLocalsplus(f); for (i = 0; i < na; i++) { Py_INCREF(*args); fastlocals[i] = *args++; } result = PyEval_EvalFrameEx(f,0); ++tstate->recursion_depth; Py_DECREF(f); --tstate->recursion_depth; return result; } #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *argdefs = PyFunction_GET_DEFAULTS(func); PyObject *closure; #if PY_MAJOR_VERSION >= 3 PyObject *kwdefs; #endif PyObject *kwtuple, **k; PyObject **d; Py_ssize_t nd; Py_ssize_t nk; PyObject *result; assert(kwargs == NULL || PyDict_Check(kwargs)); nk = kwargs ? PyDict_Size(kwargs) : 0; if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { return NULL; } if ( #if PY_MAJOR_VERSION >= 3 co->co_kwonlyargcount == 0 && #endif likely(kwargs == NULL || nk == 0) && co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { if (argdefs == NULL && co->co_argcount == nargs) { result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); goto done; } else if (nargs == 0 && argdefs != NULL && co->co_argcount == Py_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ args = &PyTuple_GET_ITEM(argdefs, 0); result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); goto done; } } if (kwargs != NULL) { Py_ssize_t pos, i; kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) { result = NULL; goto done; } k = &PyTuple_GET_ITEM(kwtuple, 0); pos = i = 0; while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { Py_INCREF(k[i]); Py_INCREF(k[i+1]); i += 2; } nk = i / 2; } else { kwtuple = NULL; k = NULL; } closure = PyFunction_GET_CLOSURE(func); #if PY_MAJOR_VERSION >= 3 kwdefs = PyFunction_GET_KW_DEFAULTS(func); #endif if (argdefs != NULL) { d = &PyTuple_GET_ITEM(argdefs, 0); nd = Py_SIZE(argdefs); } else { d = NULL; nd = 0; } #if PY_MAJOR_VERSION >= 3 result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, kwdefs, closure); #else result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, closure); #endif Py_XDECREF(kwtuple); done: Py_LeaveRecursiveCall(); return result; } #endif #endif /* PyObjectCallMethO */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { PyObject *self, *result; PyCFunction cfunc; cfunc = PyCFunction_GET_FUNCTION(func); self = PyCFunction_GET_SELF(func); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = cfunc(self, arg); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCallNoArg */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) #endif { if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } } return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); } #endif /* PyCFunctionFastCall */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { PyCFunctionObject *func = (PyCFunctionObject*)func_obj; PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); int flags = PyCFunction_GET_FLAGS(func); assert(PyCFunction_Check(func)); assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); assert(nargs >= 0); assert(nargs == 0 || args != NULL); /* _PyCFunction_FastCallDict() must not be called with an exception set, because it may clear it (directly or indirectly) and so the caller loses its exception */ assert(!PyErr_Occurred()); if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); } else { return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); } } #endif /* PyObjectCallOneArg */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_New(1); if (unlikely(!args)) return NULL; Py_INCREF(arg); PyTuple_SET_ITEM(args, 0, arg); result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, &arg, 1); } #endif if (likely(PyCFunction_Check(func))) { if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { return __Pyx_PyObject_CallMethO(func, arg); #if CYTHON_FAST_PYCCALL } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { return __Pyx_PyCFunction_FastCall(func, &arg, 1); #endif } } return __Pyx__PyObject_CallOneArg(func, arg); } #else static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_Pack(1, arg); if (unlikely(!args)) return NULL; result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } #endif /* PyDictVersioning */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { PyObject *dict = Py_TYPE(obj)->tp_dict; return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; } static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { PyObject **dictptr = NULL; Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; if (offset) { #if CYTHON_COMPILING_IN_CPYTHON dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); #else dictptr = _PyObject_GetDictPtr(obj); #endif } return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; } static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { PyObject *dict = Py_TYPE(obj)->tp_dict; if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) return 0; return obj_dict_version == __Pyx_get_object_dict_version(obj); } #endif /* PyErrFetchRestore */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #endif /* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { __Pyx_PyThreadState_declare Py_XINCREF(type); if (!value || value == Py_None) value = NULL; else Py_INCREF(value); if (!tb || tb == Py_None) tb = NULL; else { Py_INCREF(tb); if (!PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } } if (PyType_Check(type)) { #if CYTHON_COMPILING_IN_PYPY if (!value) { Py_INCREF(Py_None); value = Py_None; } #endif PyErr_NormalizeException(&type, &value, &tb); } else { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } value = type; type = (PyObject*) Py_TYPE(type); Py_INCREF(type); if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto raise_error; } } __Pyx_PyThreadState_assign __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { PyObject* owned_instance = NULL; if (tb == Py_None) { tb = 0; } else if (tb && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto bad; } if (value == Py_None) value = 0; if (PyExceptionInstance_Check(type)) { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto bad; } value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { PyObject *instance_class = NULL; if (value && PyExceptionInstance_Check(value)) { instance_class = (PyObject*) Py_TYPE(value); if (instance_class != type) { int is_subclass = PyObject_IsSubclass(instance_class, type); if (!is_subclass) { instance_class = NULL; } else if (unlikely(is_subclass == -1)) { goto bad; } else { type = instance_class; } } } if (!instance_class) { PyObject *args; if (!value) args = PyTuple_New(0); else if (PyTuple_Check(value)) { Py_INCREF(value); args = value; } else args = PyTuple_Pack(1, value); if (!args) goto bad; owned_instance = PyObject_Call(type, args, NULL); Py_DECREF(args); if (!owned_instance) goto bad; value = owned_instance; if (!PyExceptionInstance_Check(value)) { PyErr_Format(PyExc_TypeError, "calling %R should have returned an instance of " "BaseException, not %R", type, Py_TYPE(value)); goto bad; } } } else { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto bad; } if (cause) { PyObject *fixed_cause; if (cause == Py_None) { fixed_cause = NULL; } else if (PyExceptionClass_Check(cause)) { fixed_cause = PyObject_CallObject(cause, NULL); if (fixed_cause == NULL) goto bad; } else if (PyExceptionInstance_Check(cause)) { fixed_cause = cause; Py_INCREF(fixed_cause); } else { PyErr_SetString(PyExc_TypeError, "exception causes must derive from " "BaseException"); goto bad; } PyException_SetCause(value, fixed_cause); } PyErr_SetObject(type, value); if (tb) { #if CYTHON_COMPILING_IN_PYPY PyObject *tmp_type, *tmp_value, *tmp_tb; PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); Py_INCREF(tb); PyErr_Restore(tmp_type, tmp_value, tb); Py_XDECREF(tmp_tb); #else PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } #endif } bad: Py_XDECREF(owned_instance); return; } #endif /* PyObjectCall2Args */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { PyObject *args, *result = NULL; #if CYTHON_FAST_PYCALL if (PyFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyFunction_FastCall(function, args, 2); } #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyCFunction_FastCall(function, args, 2); } #endif args = PyTuple_New(2); if (unlikely(!args)) goto done; Py_INCREF(arg1); PyTuple_SET_ITEM(args, 0, arg1); Py_INCREF(arg2); PyTuple_SET_ITEM(args, 1, arg2); Py_INCREF(function); result = __Pyx_PyObject_Call(function, args, NULL); Py_DECREF(args); Py_DECREF(function); done: return result; } /* GetModuleGlobalName */ #if CYTHON_USE_DICT_VERSIONS static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) #else static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) #endif { PyObject *result; #if !CYTHON_AVOID_BORROWED_REFS #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } else if (unlikely(PyErr_Occurred())) { return NULL; } #else result = PyDict_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } #endif #else result = PyObject_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } PyErr_Clear(); #endif return __Pyx_GetBuiltinName(name); } /* PyErrExceptionMatches */ #if CYTHON_FAST_THREAD_STATE static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; icurexc_type; if (exc_type == err) return 1; if (unlikely(!exc_type)) return 0; if (unlikely(PyTuple_Check(err))) return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); } #endif /* GetAttr */ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { #if CYTHON_USE_TYPE_SLOTS #if PY_MAJOR_VERSION >= 3 if (likely(PyUnicode_Check(n))) #else if (likely(PyString_Check(n))) #endif return __Pyx_PyObject_GetAttrStr(o, n); #endif return PyObject_GetAttr(o, n); } /* GetAttr3 */ static PyObject *__Pyx_GetAttr3Default(PyObject *d) { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) return NULL; __Pyx_PyErr_Clear(); Py_INCREF(d); return d; } static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { PyObject *r = __Pyx_GetAttr(o, n); return (likely(r)) ? r : __Pyx_GetAttr3Default(d); } /* Import */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; #if PY_MAJOR_VERSION < 3 PyObject *py_import; py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) { module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; } #endif if (!module) { #if PY_MAJOR_VERSION < 3 PyObject *py_level = PyInt_FromLong(level); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, level); #endif } } bad: #if PY_MAJOR_VERSION < 3 Py_XDECREF(py_import); #endif Py_XDECREF(empty_list); Py_XDECREF(empty_dict); return module; } /* ImportFrom */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_ImportError, #if PY_MAJOR_VERSION < 3 "cannot import name %.230s", PyString_AS_STRING(name)); #else "cannot import name %S", name); #endif } return value; } /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyList_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyTuple_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS if (is_list || PyList_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; } } else if (PyTuple_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (likely(l >= 0)) { i += l; } else { if (!PyErr_ExceptionMatches(PyExc_OverflowError)) return NULL; PyErr_Clear(); } } return m->sq_item(o, i); } } #else if (is_list || PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } /* HasAttr */ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { PyObject *r; if (unlikely(!__Pyx_PyBaseString_Check(n))) { PyErr_SetString(PyExc_TypeError, "hasattr(): attribute name must be string"); return -1; } r = __Pyx_GetAttr(o, n); if (unlikely(!r)) { PyErr_Clear(); return 0; } else { Py_DECREF(r); return 1; } } /* CallNextTpTraverse */ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) { PyTypeObject* type = Py_TYPE(obj); while (type && type->tp_traverse != current_tp_traverse) type = type->tp_base; while (type && type->tp_traverse == current_tp_traverse) type = type->tp_base; if (type && type->tp_traverse) return type->tp_traverse(obj, v, a); return 0; } /* CallNextTpClear */ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) { PyTypeObject* type = Py_TYPE(obj); while (type && type->tp_clear != current_tp_clear) type = type->tp_base; while (type && type->tp_clear == current_tp_clear) type = type->tp_base; if (type && type->tp_clear) type->tp_clear(obj); } /* PyObject_GenericGetAttrNoDict */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { PyErr_Format(PyExc_AttributeError, #if PY_MAJOR_VERSION >= 3 "'%.50s' object has no attribute '%U'", tp->tp_name, attr_name); #else "'%.50s' object has no attribute '%.400s'", tp->tp_name, PyString_AS_STRING(attr_name)); #endif return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { PyObject *descr; PyTypeObject *tp = Py_TYPE(obj); if (unlikely(!PyString_Check(attr_name))) { return PyObject_GenericGetAttr(obj, attr_name); } assert(!tp->tp_dictoffset); descr = _PyType_Lookup(tp, attr_name); if (unlikely(!descr)) { return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); } Py_INCREF(descr); #if PY_MAJOR_VERSION < 3 if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) #endif { descrgetfunc f = Py_TYPE(descr)->tp_descr_get; if (unlikely(f)) { PyObject *res = f(descr, obj, (PyObject *)tp); Py_DECREF(descr); return res; } } return descr; } #endif /* PyObject_GenericGetAttr */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { return PyObject_GenericGetAttr(obj, attr_name); } return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); } #endif /* SetVTable */ static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 PyObject *ob = PyCapsule_New(vtable, 0, 0); #else PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); #endif if (!ob) goto bad; if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) goto bad; Py_DECREF(ob); return 0; bad: Py_XDECREF(ob); return -1; } /* PyObjectGetAttrStrNoError */ static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) __Pyx_PyErr_Clear(); } static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { PyObject *result; #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); } #endif result = __Pyx_PyObject_GetAttrStr(obj, attr_name); if (unlikely(!result)) { __Pyx_PyObject_GetAttrStr_ClearAttributeError(); } return result; } /* SetupReduce */ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; PyObject *name_attr; name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); if (likely(name_attr)) { ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); } else { ret = -1; } if (unlikely(ret < 0)) { PyErr_Clear(); ret = 0; } Py_XDECREF(name_attr); return ret; } static int __Pyx_setup_reduce(PyObject* type_obj) { int ret = 0; PyObject *object_reduce = NULL; PyObject *object_reduce_ex = NULL; PyObject *reduce = NULL; PyObject *reduce_ex = NULL; PyObject *reduce_cython = NULL; PyObject *setstate = NULL; PyObject *setstate_cython = NULL; #if CYTHON_USE_PYTYPE_LOOKUP if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #else if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #endif #if CYTHON_USE_PYTYPE_LOOKUP object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #else object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #endif reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; if (reduce_ex == object_reduce_ex) { #if CYTHON_USE_PYTYPE_LOOKUP object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #else object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #endif reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); if (likely(reduce_cython)) { ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (reduce == object_reduce || PyErr_Occurred()) { goto __PYX_BAD; } setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); if (!setstate) PyErr_Clear(); if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); if (likely(setstate_cython)) { ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; } else if (!setstate || PyErr_Occurred()) { goto __PYX_BAD; } } PyType_Modified((PyTypeObject*)type_obj); } } goto __PYX_GOOD; __PYX_BAD: if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); ret = -1; __PYX_GOOD: #if !CYTHON_USE_PYTYPE_LOOKUP Py_XDECREF(object_reduce); Py_XDECREF(object_reduce_ex); #endif Py_XDECREF(reduce); Py_XDECREF(reduce_ex); Py_XDECREF(reduce_cython); Py_XDECREF(setstate); Py_XDECREF(setstate_cython); return ret; } /* TypeImport */ #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) goto bad; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; #endif if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { PyOS_snprintf(warning, sizeof(warning), "%s.%s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; } return (PyTypeObject *)result; bad: Py_XDECREF(result); return NULL; } #endif /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON PyObject **cython_runtime_dict; #endif if (unlikely(!__pyx_cython_runtime)) { return c_line; } __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); #if CYTHON_COMPILING_IN_CPYTHON cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); if (likely(cython_runtime_dict)) { __PYX_PY_DICT_LOOKUP_IF_MODIFIED( use_cline, *cython_runtime_dict, __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) } else #endif { PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); if (use_cline_obj) { use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; Py_DECREF(use_cline_obj); } else { PyErr_Clear(); use_cline = NULL; } } if (!use_cline) { c_line = 0; PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); } else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { c_line = 0; } __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); return c_line; } #endif /* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = start + (end - start) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } /* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; PyThreadState *tstate = __Pyx_PyThreadState_Current; if (c_line) { c_line = __Pyx_CLineForTraceback(tstate, c_line); } py_code = __pyx_find_code_object(c_line ? -c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); } py_frame = PyFrame_New( tstate, /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; __Pyx_PyFrame_SetLineNumber(py_frame, py_line); PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) { 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; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG), little, !is_unsigned); } } /* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ {\ func_type value = func_value;\ if (sizeof(target_type) < sizeof(func_type)) {\ if (unlikely(value != (func_type) (target_type) value)) {\ func_type zero = 0;\ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ return (target_type) -1;\ if (is_unsigned && unlikely(value < zero))\ goto raise_neg_overflow;\ else\ goto raise_overflow;\ }\ }\ return (target_type) value;\ } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) { 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; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (unsigned PY_LONG_LONG) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0]) case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) { 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])); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) { 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])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (unsigned PY_LONG_LONG) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, +digits[0]) case -2: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case -3: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case -4: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else unsigned PY_LONG_LONG val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (unsigned PY_LONG_LONG) -1; } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (unsigned PY_LONG_LONG) -1; val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; } /* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (long) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -3: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -4: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; } #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (int) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -3: if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -4: if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; } #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } /* FastTypeChecks */ #if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; if (a == b) return 1; } return b == &PyBaseObject_Type; } static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { PyObject *mro; if (a == b) return 1; mro = a->tp_mro; if (likely(mro)) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(mro); for (i = 0; i < n; i++) { if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) return 1; } return 0; } return __Pyx_InBases(a, b); } #if PY_MAJOR_VERSION == 2 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { PyObject *exception, *value, *tb; int res; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&exception, &value, &tb); res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } if (!res) { res = PyObject_IsSubclass(err, exc_type2); if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } } __Pyx_ErrRestore(exception, value, tb); return res; } #else static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; if (!res) { res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); } return res; } #endif static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; assert(PyExceptionClass_Check(exc_type)); n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; ip) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; if (PyObject_Hash(*t->p) == -1) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT #if !CYTHON_PEP393_ENABLED static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; } #else static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (likely(PyUnicode_IS_ASCII(o))) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif } #endif #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { return __Pyx_PyUnicode_AsStringAndSize(o, length); } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { int retval; if (unlikely(!x)) return -1; retval = __Pyx_PyObject_IsTrue(x); Py_DECREF(x); return retval; } static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(result)) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "__int__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } return result; } #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", type_name, type_name, Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { #if CYTHON_USE_TYPE_SLOTS PyNumberMethods *m; #endif const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x) || PyLong_Check(x))) #else if (likely(PyLong_Check(x))) #endif return __Pyx_NewRef(x); #if CYTHON_USE_TYPE_SLOTS m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = m->nb_int(x); } else if (m && m->nb_long) { name = "long"; res = m->nb_long(x); } #else if (likely(m && m->nb_int)) { name = "int"; res = m->nb_int(x); } #endif #else if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { res = PyNumber_Int(x); } #endif if (likely(res)) { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { #else if (unlikely(!PyLong_CheckExact(res))) { #endif return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)b)->ob_digit; const Py_ssize_t size = Py_SIZE(b); if (likely(__Pyx_sst_abs(size) <= 1)) { ival = likely(size) ? digits[0] : 0; if (size == -1) ival = -ival; return ival; } else { switch (size) { case 2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; case -4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; } } #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ python-clickhouse-driver-0.2.3/clickhouse_driver/bufferedwriter.pyx000066400000000000000000000103451420676740400257570ustar00rootroot00000000000000from cpython cimport PyMem_Malloc, PyMem_Free, PyBytes_AsString, \ PyBytes_Check, PyBytes_FromStringAndSize, PyBytes_AS_STRING, \ PyBytes_GET_SIZE from libc.string cimport memcpy, memset from . import errors from .varint import make_varint cdef class BufferedWriter(object): cdef char* buffer cdef unsigned long long position, buffer_size def __init__(self, unsigned long long bufsize): self.buffer = PyMem_Malloc(bufsize) if not self.buffer: raise MemoryError() self.position = 0 self.buffer_size = bufsize super(BufferedWriter, self).__init__() def __dealloc__(self): PyMem_Free(self.buffer) cpdef write_into_stream(self): raise NotImplementedError cpdef write(self, data): cdef unsigned long long size, written = 0 cdef unsigned long long data_len = PyBytes_GET_SIZE(data) cdef char* c_data = PyBytes_AS_STRING(data) while written < data_len: size = min(data_len - written, self.buffer_size - self.position) memcpy(&self.buffer[self.position], &c_data[written], size) if self.position == self.buffer_size: self.write_into_stream() self.position += size written += size def flush(self): self.write_into_stream() def write_strings(self, items, encoding=None): cdef int do_encode = encoding is not None for value in items: if not PyBytes_Check(value): if do_encode: value = value.encode(encoding) else: raise ValueError('bytes object expected') self.write(make_varint(PyBytes_GET_SIZE(value))) self.write(value) def write_fixed_strings_as_bytes(self, items, Py_ssize_t length): cdef Py_ssize_t buf_pos = 0 cdef Py_ssize_t items_buf_size = length * len(items) cdef char* c_value cdef char* items_buf = PyMem_Malloc(items_buf_size) if not items_buf: raise MemoryError() memset(items_buf, 0, items_buf_size) for value in items: value_len = len(value) if length < value_len: raise errors.TooLargeStringSize() c_value = PyBytes_AsString(value) memcpy(&items_buf[buf_pos], c_value, value_len) buf_pos += length self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) PyMem_Free(items_buf) def write_fixed_strings(self, items, Py_ssize_t length, encoding=None): if encoding is None: self.write_fixed_strings_as_bytes(items, length) return cdef Py_ssize_t buf_pos = 0 cdef Py_ssize_t items_buf_size = length * len(items) cdef char* c_value cdef char* items_buf = PyMem_Malloc(items_buf_size) if not items_buf: raise MemoryError() memset(items_buf, 0, items_buf_size) for value in items: if not PyBytes_Check(value): value = value.encode(encoding) value_len = len(value) if length < value_len: raise errors.TooLargeStringSize() c_value = PyBytes_AsString(value) memcpy(&items_buf[buf_pos], c_value, value_len) buf_pos += length self.write(PyBytes_FromStringAndSize(items_buf, items_buf_size)) PyMem_Free(items_buf) cdef class BufferedSocketWriter(BufferedWriter): cdef object sock def __init__(self, sock, bufsize): self.sock = sock super(BufferedSocketWriter, self).__init__(bufsize) cpdef write_into_stream(self): self.sock.sendall( PyBytes_FromStringAndSize(self.buffer, self.position) ) self.position = 0 cdef class CompressedBufferedWriter(BufferedWriter): cdef object compressor def __init__(self, compressor, bufsize): self.compressor = compressor super(CompressedBufferedWriter, self).__init__(bufsize) cpdef write_into_stream(self): self.compressor.write( PyBytes_FromStringAndSize(self.buffer, self.position) ) self.position = 0 def flush(self): self.write_into_stream() python-clickhouse-driver-0.2.3/clickhouse_driver/client.py000066400000000000000000000637631420676740400240420ustar00rootroot00000000000000import re import ssl from contextlib import contextmanager from time import time import types from urllib.parse import urlparse, parse_qs, unquote from . import errors, defines from .block import ColumnOrientedBlock, RowOrientedBlock from .connection import Connection from .log import log_block from .protocol import ServerPacketTypes from .result import ( IterQueryResult, ProgressQueryResult, QueryResult, QueryInfo ) from .util.escape import escape_params from .util.helpers import column_chunks, chunks, asbool class Client(object): """ Client for communication with the ClickHouse server. Single connection is established per each connected instance of the client. :param settings: Dictionary of settings that passed to every query (except for the client settings, see below). Defaults to ``None`` (no additional settings). See all available settings in `ClickHouse docs `_. :param \\**kwargs: All other args are passed to the :py:class:`~clickhouse_driver.connection.Connection` constructor. The following keys when passed in ``settings`` are used for configuring the client itself: * ``insert_block_size`` -- chunk size to split rows for ``INSERT``. Defaults to ``1048576``. * ``strings_as_bytes`` -- turns off string column encoding/decoding. * ``strings_encoding`` -- specifies string encoding. UTF-8 by default. * ``use_numpy`` -- Use numpy for columns reading. New in version *0.2.0*. * ``opentelemetry_traceparent`` -- OpenTelemetry traceparent header as described by W3C Trace Context recommendation. New in version *0.2.2*. * ``opentelemetry_tracestate`` -- OpenTelemetry tracestate header as described by W3C Trace Context recommendation. New in version *0.2.2*. * ``quota_key`` -- A string to differentiate quotas when the user have keyed quotas configured on server. New in version *0.2.3*. """ available_client_settings = ( 'insert_block_size', # TODO: rename to max_insert_block_size 'strings_as_bytes', 'strings_encoding', 'use_numpy', 'opentelemetry_traceparent', 'opentelemetry_tracestate', 'quota_key' ) def __init__(self, *args, **kwargs): self.settings = (kwargs.pop('settings', None) or {}).copy() self.client_settings = { 'insert_block_size': int(self.settings.pop( 'insert_block_size', defines.DEFAULT_INSERT_BLOCK_SIZE, )), 'strings_as_bytes': self.settings.pop( 'strings_as_bytes', False ), 'strings_encoding': self.settings.pop( 'strings_encoding', defines.STRINGS_ENCODING ), 'use_numpy': self.settings.pop( 'use_numpy', False ), 'opentelemetry_traceparent': self.settings.pop( 'opentelemetry_traceparent', None ), 'opentelemetry_tracestate': self.settings.pop( 'opentelemetry_tracestate', '' ), 'quota_key': self.settings.pop( 'quota_key', '' ) } if self.client_settings['use_numpy']: try: from .numpy.result import ( NumpyIterQueryResult, NumpyProgressQueryResult, NumpyQueryResult ) self.query_result_cls = NumpyQueryResult self.iter_query_result_cls = NumpyIterQueryResult self.progress_query_result_cls = NumpyProgressQueryResult except ImportError: raise RuntimeError('Extras for NumPy must be installed') else: self.query_result_cls = QueryResult self.iter_query_result_cls = IterQueryResult self.progress_query_result_cls = ProgressQueryResult self.connection = Connection(*args, **kwargs) self.connection.context.settings = self.settings self.connection.context.client_settings = self.client_settings self.reset_last_query() super(Client, self).__init__() def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.disconnect() def disconnect(self): """ Disconnects from the server. """ self.connection.disconnect() self.reset_last_query() def reset_last_query(self): self.last_query = None def receive_result(self, with_column_types=False, progress=False, columnar=False): gen = self.packet_generator() if progress: return self.progress_query_result_cls( gen, with_column_types=with_column_types, columnar=columnar ) else: result = self.query_result_cls( gen, with_column_types=with_column_types, columnar=columnar ) return result.get_result() def iter_receive_result(self, with_column_types=False): gen = self.packet_generator() result = self.iter_query_result_cls( gen, with_column_types=with_column_types ) for rows in result: for row in rows: yield row def packet_generator(self): while True: try: packet = self.receive_packet() if not packet: break if packet is True: continue yield packet except (Exception, KeyboardInterrupt): self.disconnect() raise def receive_packet(self): packet = self.connection.receive_packet() if packet.type == ServerPacketTypes.EXCEPTION: raise packet.exception elif packet.type == ServerPacketTypes.PROGRESS: self.last_query.store_progress(packet.progress) return packet elif packet.type == ServerPacketTypes.END_OF_STREAM: return False elif packet.type == ServerPacketTypes.DATA: return packet elif packet.type == ServerPacketTypes.TOTALS: return packet elif packet.type == ServerPacketTypes.EXTREMES: return packet elif packet.type == ServerPacketTypes.PROFILE_INFO: self.last_query.store_profile(packet.profile_info) return True else: return True def make_query_settings(self, settings): settings = dict(settings or {}) # Pick client-related settings. client_settings = self.client_settings.copy() for key in self.available_client_settings: if key in settings: client_settings[key] = settings.pop(key) self.connection.context.client_settings = client_settings # The rest of settings are ClickHouse-related. query_settings = self.settings.copy() query_settings.update(settings) self.connection.context.settings = query_settings def track_current_database(self, query): query = query.strip('; ') if query.lower().startswith('use '): self.connection.database = query[4:].strip() @contextmanager def disconnect_on_error(self, query, settings): self.make_query_settings(settings) try: self.connection.force_connect() self.last_query = QueryInfo() yield self.track_current_database(query) except (Exception, KeyboardInterrupt): self.disconnect() raise def execute(self, query, params=None, with_column_types=False, external_tables=None, query_id=None, settings=None, types_check=False, columnar=False): """ Executes query. Establishes new connection if it wasn't established yet. After query execution connection remains intact for next queries. If connection can't be reused it will be closed and new connection will be created. :param query: query that will be send to server. :param params: substitution parameters for SELECT queries and data for INSERT queries. Data for INSERT can be `list`, `tuple` or :data:`~types.GeneratorType`. Defaults to ``None`` (no parameters or data). :param with_column_types: if specified column names and types will be returned alongside with result. Defaults to ``False``. :param external_tables: external tables to send. Defaults to ``None`` (no external tables). :param query_id: the query identifier. If no query id specified ClickHouse server will generate it. :param settings: dictionary of query settings. Defaults to ``None`` (no additional settings). :param types_check: enables type checking of data for INSERT queries. Causes additional overhead. Defaults to ``False``. :param columnar: if specified the result of the SELECT query will be returned in column-oriented form. It also allows to INSERT data in columnar form. Defaults to ``False`` (row-like form). :return: * number of inserted rows for INSERT queries with data. Returning rows count from INSERT FROM SELECT is not supported. * if `with_column_types=False`: `list` of `tuples` with rows/columns. * if `with_column_types=True`: `tuple` of 2 elements: * The first element is `list` of `tuples` with rows/columns. * The second element information is about columns: names and types. """ start_time = time() with self.disconnect_on_error(query, settings): # INSERT queries can use list/tuple/generator of list/tuples/dicts. # For SELECT parameters can be passed in only in dict right now. is_insert = isinstance(params, (list, tuple, types.GeneratorType)) if is_insert: rv = self.process_insert_query( query, params, external_tables=external_tables, query_id=query_id, types_check=types_check, columnar=columnar ) else: rv = self.process_ordinary_query( query, params=params, with_column_types=with_column_types, external_tables=external_tables, query_id=query_id, types_check=types_check, columnar=columnar ) self.last_query.store_elapsed(time() - start_time) return rv def execute_with_progress( self, query, params=None, with_column_types=False, external_tables=None, query_id=None, settings=None, types_check=False, columnar=False): """ Executes SELECT query with progress information. See, :ref:`execute-with-progress`. :param query: query that will be send to server. :param params: substitution parameters for SELECT queries and data for INSERT queries. Data for INSERT can be `list`, `tuple` or :data:`~types.GeneratorType`. Defaults to ``None`` (no parameters or data). :param with_column_types: if specified column names and types will be returned alongside with result. Defaults to ``False``. :param external_tables: external tables to send. Defaults to ``None`` (no external tables). :param query_id: the query identifier. If no query id specified ClickHouse server will generate it. :param settings: dictionary of query settings. Defaults to ``None`` (no additional settings). :param types_check: enables type checking of data for INSERT queries. Causes additional overhead. Defaults to ``False``. :param columnar: if specified the result will be returned in column-oriented form. Defaults to ``False`` (row-like form). :return: :ref:`progress-query-result` proxy. """ with self.disconnect_on_error(query, settings): return self.process_ordinary_query_with_progress( query, params=params, with_column_types=with_column_types, external_tables=external_tables, query_id=query_id, types_check=types_check, columnar=columnar ) def execute_iter( self, query, params=None, with_column_types=False, external_tables=None, query_id=None, settings=None, types_check=False): """ *New in version 0.0.14.* Executes SELECT query with results streaming. See, :ref:`execute-iter`. :param query: query that will be send to server. :param params: substitution parameters for SELECT queries and data for INSERT queries. Data for INSERT can be `list`, `tuple` or :data:`~types.GeneratorType`. Defaults to ``None`` (no parameters or data). :param with_column_types: if specified column names and types will be returned alongside with result. Defaults to ``False``. :param external_tables: external tables to send. Defaults to ``None`` (no external tables). :param query_id: the query identifier. If no query id specified ClickHouse server will generate it. :param settings: dictionary of query settings. Defaults to ``None`` (no additional settings). :param types_check: enables type checking of data for INSERT queries. Causes additional overhead. Defaults to ``False``. :return: :ref:`iter-query-result` proxy. """ with self.disconnect_on_error(query, settings): return self.iter_process_ordinary_query( query, params=params, with_column_types=with_column_types, external_tables=external_tables, query_id=query_id, types_check=types_check ) def query_dataframe( self, query, params=None, external_tables=None, query_id=None, settings=None): """ *New in version 0.2.0.* Queries DataFrame with specified SELECT query. :param query: query that will be send to server. :param params: substitution parameters. Defaults to ``None`` (no parameters or data). :param external_tables: external tables to send. Defaults to ``None`` (no external tables). :param query_id: the query identifier. If no query id specified ClickHouse server will generate it. :param settings: dictionary of query settings. Defaults to ``None`` (no additional settings). :return: pandas DataFrame. """ try: import pandas as pd except ImportError: raise RuntimeError('Extras for NumPy must be installed') data, columns = self.execute( query, columnar=True, with_column_types=True, params=params, external_tables=external_tables, query_id=query_id, settings=settings ) return pd.DataFrame( {re.sub(r'\W', '_', col[0]): d for d, col in zip(data, columns)} ) def insert_dataframe( self, query, dataframe, external_tables=None, query_id=None, settings=None): """ *New in version 0.2.0.* Inserts pandas DataFrame with specified query. :param query: query that will be send to server. :param dataframe: pandas DataFrame. :param external_tables: external tables to send. Defaults to ``None`` (no external tables). :param query_id: the query identifier. If no query id specified ClickHouse server will generate it. :param settings: dictionary of query settings. Defaults to ``None`` (no additional settings). :return: number of inserted rows. """ try: import pandas as pd # noqa: F401 except ImportError: raise RuntimeError('Extras for NumPy must be installed') start_time = time() with self.disconnect_on_error(query, settings): self.connection.send_query(query, query_id=query_id) self.connection.send_external_tables(external_tables) sample_block = self.receive_sample_block() rv = None if sample_block: columns = [x[0] for x in sample_block.columns_with_types] data = [dataframe[column].values for column in columns] rv = self.send_data(sample_block, data, columnar=True) self.receive_end_of_query() self.last_query.store_elapsed(time() - start_time) return rv def process_ordinary_query_with_progress( self, query, params=None, with_column_types=False, external_tables=None, query_id=None, types_check=False, columnar=False): if params is not None: query = self.substitute_params( query, params, self.connection.context ) self.connection.send_query(query, query_id=query_id) self.connection.send_external_tables(external_tables, types_check=types_check) return self.receive_result(with_column_types=with_column_types, progress=True, columnar=columnar) def process_ordinary_query( self, query, params=None, with_column_types=False, external_tables=None, query_id=None, types_check=False, columnar=False): if params is not None: query = self.substitute_params( query, params, self.connection.context ) self.connection.send_query(query, query_id=query_id) self.connection.send_external_tables(external_tables, types_check=types_check) return self.receive_result(with_column_types=with_column_types, columnar=columnar) def iter_process_ordinary_query( self, query, params=None, with_column_types=False, external_tables=None, query_id=None, types_check=False): if params is not None: query = self.substitute_params( query, params, self.connection.context ) self.connection.send_query(query, query_id=query_id) self.connection.send_external_tables(external_tables, types_check=types_check) return self.iter_receive_result(with_column_types=with_column_types) def process_insert_query(self, query_without_data, data, external_tables=None, query_id=None, types_check=False, columnar=False): self.connection.send_query(query_without_data, query_id=query_id) self.connection.send_external_tables(external_tables, types_check=types_check) sample_block = self.receive_sample_block() if sample_block: rv = self.send_data(sample_block, data, types_check=types_check, columnar=columnar) self.receive_end_of_query() return rv def receive_sample_block(self): while True: packet = self.connection.receive_packet() if packet.type == ServerPacketTypes.DATA: return packet.block elif packet.type == ServerPacketTypes.EXCEPTION: raise packet.exception elif packet.type == ServerPacketTypes.LOG: log_block(packet.block) elif packet.type == ServerPacketTypes.TABLE_COLUMNS: pass else: message = self.connection.unexpected_packet_message( 'Data, Exception, Log or TableColumns', packet.type ) raise errors.UnexpectedPacketFromServerError(message) def send_data(self, sample_block, data, types_check=False, columnar=False): inserted_rows = 0 client_settings = self.connection.context.client_settings block_cls = ColumnOrientedBlock if columnar else RowOrientedBlock if client_settings['use_numpy']: try: from .numpy.helpers import column_chunks as numpy_column_chunks if columnar: slicer = numpy_column_chunks else: raise ValueError( 'NumPy inserts is only allowed with columnar=True' ) except ImportError: raise RuntimeError('Extras for NumPy must be installed') else: slicer = column_chunks if columnar else chunks for chunk in slicer(data, client_settings['insert_block_size']): block = block_cls(sample_block.columns_with_types, chunk, types_check=types_check) self.connection.send_data(block) inserted_rows += block.num_rows # Empty block means end of data. self.connection.send_data(block_cls()) return inserted_rows def receive_end_of_query(self): while True: packet = self.connection.receive_packet() if packet.type == ServerPacketTypes.END_OF_STREAM: break elif packet.type == ServerPacketTypes.EXCEPTION: raise packet.exception elif packet.type == ServerPacketTypes.LOG: log_block(packet.block) elif packet.type == ServerPacketTypes.TABLE_COLUMNS: pass else: message = self.connection.unexpected_packet_message( 'Exception, EndOfStream or Log', packet.type ) raise errors.UnexpectedPacketFromServerError(message) def cancel(self, with_column_types=False): # TODO: Add warning if already cancelled. self.connection.send_cancel() # Client must still read until END_OF_STREAM packet. return self.receive_result(with_column_types=with_column_types) def substitute_params(self, query, params, context): if not isinstance(params, dict): raise ValueError('Parameters are expected in dict form') escaped = escape_params(params, context) return query % escaped @classmethod def from_url(cls, url): """ Return a client configured from the given URL. For example:: clickhouse://[user:password]@localhost:9000/default clickhouses://[user:password]@localhost:9440/default Three URL schemes are supported: clickhouse:// creates a normal TCP socket connection clickhouses:// creates a SSL wrapped TCP socket connection Any additional querystring arguments will be passed along to the Connection class's initializer. """ url = urlparse(url) settings = {} kwargs = {} host = url.hostname if url.port is not None: kwargs['port'] = url.port path = url.path.replace('/', '', 1) if path: kwargs['database'] = path if url.username is not None: kwargs['user'] = unquote(url.username) if url.password is not None: kwargs['password'] = unquote(url.password) if url.scheme == 'clickhouses': kwargs['secure'] = True compression_algs = {'lz4', 'lz4hc', 'zstd'} timeouts = { 'connect_timeout', 'send_receive_timeout', 'sync_request_timeout' } for name, value in parse_qs(url.query).items(): if not value or not len(value): continue value = value[0] if name == 'compression': value = value.lower() if value in compression_algs: kwargs[name] = value else: kwargs[name] = asbool(value) elif name == 'secure': kwargs[name] = asbool(value) elif name == 'use_numpy': settings[name] = asbool(value) elif name == 'client_name': kwargs[name] = value elif name in timeouts: kwargs[name] = float(value) elif name == 'compress_block_size': kwargs[name] = int(value) elif name == 'settings_is_important': kwargs[name] = asbool(value) # ssl elif name == 'verify': kwargs[name] = asbool(value) elif name == 'ssl_version': kwargs[name] = getattr(ssl, value) elif name in ['ca_certs', 'ciphers', 'keyfile', 'certfile']: kwargs[name] = value elif name == 'alt_hosts': kwargs['alt_hosts'] = value else: settings[name] = value if settings: kwargs['settings'] = settings return cls(host, **kwargs) python-clickhouse-driver-0.2.3/clickhouse_driver/clientinfo.py000066400000000000000000000065731420676740400247120ustar00rootroot00000000000000import socket import getpass from . import defines from . import errors from .opentelemetry import OpenTelemetryTraceContext from .varint import write_varint from .writer import write_binary_str, write_binary_uint8, \ write_binary_uint64, write_binary_uint128 class ClientInfo(object): class Interface(object): TCP = 1 HTTP = 2 class QueryKind(object): # Uninitialized object. NO_QUERY = 0 INITIAL_QUERY = 1 # Query that was initiated by another query for distributed query # execution. SECONDARY_QUERY = 2 client_version_major = defines.CLIENT_VERSION_MAJOR client_version_minor = defines.CLIENT_VERSION_MINOR client_version_patch = defines.CLIENT_VERSION_PATCH client_revision = defines.CLIENT_REVISION interface = Interface.TCP initial_user = '' initial_query_id = '' initial_address = '0.0.0.0:0' def __init__(self, client_name, context): self.query_kind = ClientInfo.QueryKind.NO_QUERY try: self.os_user = getpass.getuser() except KeyError: self.os_user = '' self.client_hostname = socket.gethostname() self.client_name = client_name self.client_trace_context = OpenTelemetryTraceContext( context.client_settings['opentelemetry_traceparent'], context.client_settings['opentelemetry_tracestate'] ) self.quota_key = context.client_settings['quota_key'] super(ClientInfo, self).__init__() @property def empty(self): return self.query_kind == ClientInfo.QueryKind.NO_QUERY def write(self, server_revision, fout): revision = server_revision if server_revision < defines.DBMS_MIN_REVISION_WITH_CLIENT_INFO: raise errors.LogicalError('Method ClientInfo.write is called ' 'for unsupported server revision') write_binary_uint8(self.query_kind, fout) if self.empty: return write_binary_str(self.initial_user, fout) write_binary_str(self.initial_query_id, fout) write_binary_str(self.initial_address, fout) write_binary_uint8(self.interface, fout) write_binary_str(self.os_user, fout) write_binary_str(self.client_hostname, fout) write_binary_str(self.client_name, fout) write_varint(self.client_version_major, fout) write_varint(self.client_version_minor, fout) write_varint(self.client_revision, fout) if revision >= defines.DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO: write_binary_str(self.quota_key, fout) if revision >= defines.DBMS_MIN_REVISION_WITH_VERSION_PATCH: write_varint(self.client_version_patch, fout) if revision >= defines.DBMS_MIN_REVISION_WITH_OPENTELEMETRY: if self.client_trace_context.trace_id is not None: # Have OpenTelemetry header. write_binary_uint8(1, fout) write_binary_uint128(self.client_trace_context.trace_id, fout) write_binary_uint64(self.client_trace_context.span_id, fout) write_binary_str(self.client_trace_context.tracestate, fout) write_binary_uint8(self.client_trace_context.trace_flags, fout) else: # Don't have OpenTelemetry header. write_binary_uint8(0, fout) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/000077500000000000000000000000001420676740400236535ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/columns/__init__.py000066400000000000000000000000001420676740400257520ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/columns/arraycolumn.py000066400000000000000000000115631420676740400265670ustar00rootroot00000000000000from itertools import chain from struct import Struct from .base import Column from .intcolumn import UInt64Column from ..util.helpers import pairwise class ArrayColumn(Column): """ Nested arrays written in flatten form after information about their sizes (offsets really). One element of array of arrays can be represented as tree: (0 depth) [[3, 4], [5, 6]] | | (1 depth) [3, 4] [5, 6] | | | | (leaf) 3 4 5 6 Offsets (sizes) written in breadth-first search order. In example above following sequence of offset will be written: 4 -> 2 -> 4 1) size of whole array: 4 2) size of array 1 in depth=1: 2 3) size of array 2 plus size of all array before in depth=1: 2 + 2 = 4 After sizes info comes flatten data: 3 -> 4 -> 5 -> 6 """ py_types = (list, tuple) def __init__(self, nested_column, **kwargs): self.size_column = UInt64Column() self.nested_column = nested_column self._write_depth_0_size = True super(ArrayColumn, self).__init__(**kwargs) def write_data(self, data, buf): # Column of Array(T) is stored in "compact" format and passed to server # wrapped into another Array without size of wrapper array. self.nested_column = ArrayColumn(self.nested_column) self.nested_column.nullable = self.nullable self.nullable = False self._write_depth_0_size = False self._write(data, buf) def read_data(self, rows, buf): self.nested_column = ArrayColumn(self.nested_column) self.nested_column.nullable = self.nullable self.nullable = False return self._read(rows, buf)[0] def _write_sizes(self, value, buf): nulls_map = [] column = self sizes = [len(value)] if self._write_depth_0_size else [] while True: nested_column = column.nested_column if not isinstance(nested_column, ArrayColumn): if column.nullable: nulls_map = [x is None for x in value] break offset = 0 new_value = [] for x in value: offset += len(x) sizes.append(offset) new_value.extend(x) value = new_value column = nested_column if nulls_map: self._write_nulls_map(nulls_map, buf) ns = Struct('<{}Q'.format(len(sizes))) buf.write(ns.pack(*sizes)) def _write_data(self, value, buf): if self.nullable: value = value or [] if isinstance(self.nested_column, ArrayColumn): value = list(chain.from_iterable(value)) if value: self.nested_column._write_data(value, buf) def _write_nulls_data(self, value, buf): if self.nullable: value = value or [] if isinstance(self.nested_column, ArrayColumn): value = list(chain.from_iterable(value)) self.nested_column._write_nulls_data(value, buf) else: if self.nested_column.nullable: self.nested_column._write_nulls_map(value, buf) def _write(self, value, buf): self._write_sizes(value, buf) self._write_nulls_data(value, buf) self._write_data(value, buf) def read_state_prefix(self, buf): return self.nested_column.read_state_prefix(buf) def write_state_prefix(self, buf): self.nested_column.write_state_prefix(buf) def _read(self, size, buf): slices_series = [[0, size]] nested_column = self.nested_column cur_level_slice_size = size cur_level_slice = None while (isinstance(nested_column, ArrayColumn)): if cur_level_slice is None: cur_level_slice = [0] ns = Struct('<{}Q'.format(cur_level_slice_size)) nested_sizes = ns.unpack(buf.read(ns.size)) cur_level_slice.extend(nested_sizes) slices_series.append(cur_level_slice) cur_level_slice = None cur_level_slice_size = nested_sizes[-1] if len(nested_sizes) > 0 \ else 0 nested_column = nested_column.nested_column n_items = cur_level_slice_size if size > 0 else 0 nulls_map = None if nested_column.nullable: nulls_map = self._read_nulls_map(n_items, buf) data = [] if n_items: data = list(nested_column._read_data( n_items, buf, nulls_map=nulls_map )) # Build nested structure. for slices in reversed(slices_series): data = [data[begin:end] for begin, end in pairwise(slices)] return tuple(data) def create_array_column(spec, column_by_spec_getter): inner = spec[6:-1] return ArrayColumn(column_by_spec_getter(inner)) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/base.py000066400000000000000000000077761420676740400251600ustar00rootroot00000000000000from struct import Struct, error as struct_error from . import exceptions class Column(object): ch_type = None py_types = None check_item = None after_read_items = None before_write_items = None types_check_enabled = False null_value = 0 def __init__(self, types_check=False, **kwargs): self.nullable = False self.types_check_enabled = types_check super(Column, self).__init__() def make_null_struct(self, n_items): return Struct('<{}B'.format(n_items)) def _read_nulls_map(self, n_items, buf): s = self.make_null_struct(n_items) return s.unpack(buf.read(s.size)) def _write_nulls_map(self, items, buf): s = self.make_null_struct(len(items)) items = [x is None for x in items] buf.write(s.pack(*items)) def check_item_type(self, value): if not isinstance(value, self.py_types): raise exceptions.ColumnTypeMismatchException(value) def prepare_items(self, items): nullable = self.nullable null_value = self.null_value check_item = self.check_item if self.types_check_enabled: check_item_type = self.check_item_type else: check_item_type = False if (not self.nullable and not check_item_type and not check_item and not self.before_write_items): return items nulls_map = [False] * len(items) if self.nullable else None for i, x in enumerate(items): if x is None and nullable: nulls_map[i] = True x = null_value else: if check_item_type: check_item_type(x) if check_item: check_item(x) items[i] = x if self.before_write_items: self.before_write_items(items, nulls_map=nulls_map) return items def write_data(self, items, buf): if self.nullable: self._write_nulls_map(items, buf) self._write_data(items, buf) def _write_data(self, items, buf): prepared = self.prepare_items(items) self.write_items(prepared, buf) def write_items(self, items, buf): raise NotImplementedError def read_data(self, n_items, buf): if self.nullable: nulls_map = self._read_nulls_map(n_items, buf) else: nulls_map = None return self._read_data(n_items, buf, nulls_map=nulls_map) def _read_data(self, n_items, buf, nulls_map=None): items = self.read_items(n_items, buf) if self.after_read_items: return self.after_read_items(items, nulls_map) elif nulls_map is not None: return tuple( (None if is_null else items[i]) for i, is_null in enumerate(nulls_map) ) return items def read_items(self, n_items, buf): raise NotImplementedError def read_state_prefix(self, buf): pass def write_state_prefix(self, buf): pass class FormatColumn(Column): """ Uses struct.pack for bulk items writing. """ format = None def make_struct(self, n_items): return Struct('<{}{}'.format(n_items, self.format)) def write_items(self, items, buf): s = self.make_struct(len(items)) try: buf.write(s.pack(*items)) except struct_error as e: raise exceptions.StructPackException(e) def read_items(self, n_items, buf): s = self.make_struct(n_items) return s.unpack(buf.read(s.size)) # How to write new column? # - Check ClickHouse documentation for column # - Wireshark and tcpdump are your friends. # - Use `clickhouse-client --compression 0` to see what's going on data # transmission. # - Check for similar existing columns and tests. # - Use `FormatColumn` for columns that use "simple" types under the hood. # - Some columns have before_write and after_read hooks. # Use them to convert items in column into "simple" types. python-clickhouse-driver-0.2.3/clickhouse_driver/columns/boolcolumn.py000066400000000000000000000001771420676740400264030ustar00rootroot00000000000000from .base import FormatColumn class BoolColumn(FormatColumn): ch_type = 'Bool' py_types = (bool, ) format = '?' python-clickhouse-driver-0.2.3/clickhouse_driver/columns/datecolumn.py000066400000000000000000000036131420676740400263630ustar00rootroot00000000000000from datetime import date, timedelta from .base import FormatColumn epoch_start = date(1970, 1, 1) epoch_end = date(2149, 6, 6) epoch_start_date32 = date(1925, 1, 1) epoch_end_date32 = date(2283, 11, 11) class DateColumn(FormatColumn): ch_type = 'Date' py_types = (date, ) format = 'H' min_value = epoch_start max_value = epoch_end date_lut_days = (epoch_end - epoch_start).days + 1 date_lut = {x: epoch_start + timedelta(x) for x in range(date_lut_days)} date_lut_reverse = {value: key for key, value in date_lut.items()} def before_write_items(self, items, nulls_map=None): null_value = self.null_value date_lut_reverse = self.date_lut_reverse min_value = self.min_value max_value = self.max_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue if type(item) != date: item = date(item.year, item.month, item.day) if min_value <= item <= max_value: items[i] = date_lut_reverse[item] else: items[i] = 0 def after_read_items(self, items, nulls_map=None): date_lut = self.date_lut if nulls_map is None: return tuple(date_lut[item] for item in items) else: return tuple( (None if is_null else date_lut[items[i]]) for i, is_null in enumerate(nulls_map) ) class Date32Column(DateColumn): ch_type = 'Date32' format = 'i' min_value = epoch_start_date32 max_value = epoch_end_date32 date_lut_days = (epoch_end_date32 - epoch_start).days + 1 date_lut = { x: epoch_start + timedelta(x) for x in range((epoch_start_date32 - epoch_start).days, date_lut_days) } date_lut_reverse = {value: key for key, value in date_lut.items()} python-clickhouse-driver-0.2.3/clickhouse_driver/columns/datetimecolumn.py000066400000000000000000000150431420676740400272420ustar00rootroot00000000000000from datetime import datetime from pytz import timezone as get_timezone, utc from ..util.compat import get_localzone_name_compat from .base import FormatColumn EPOCH = datetime(1970, 1, 1, tzinfo=utc) class DateTimeColumn(FormatColumn): ch_type = 'DateTime' py_types = (datetime, int) format = 'I' def __init__(self, timezone=None, offset_naive=True, **kwargs): self.timezone = timezone self.offset_naive = offset_naive super(DateTimeColumn, self).__init__(**kwargs) def after_read_items(self, items, nulls_map=None): tz = self.timezone fromts = datetime.fromtimestamp # A bit ugly copy-paste. But it helps save time on items # processing by avoiding lambda calls or if in loop. if self.offset_naive: if tz: if nulls_map is None: return tuple( fromts(item, tz).replace(tzinfo=None) for item in items ) else: return tuple( (None if is_null else fromts(items[i], tz).replace(tzinfo=None)) for i, is_null in enumerate(nulls_map) ) else: if nulls_map is None: return tuple(fromts(item) for item in items) else: return tuple( (None if is_null else fromts(items[i])) for i, is_null in enumerate(nulls_map) ) else: if nulls_map is None: return tuple(fromts(item, tz) for item in items) else: return tuple( (None if is_null else fromts(items[i], tz)) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): timezone = self.timezone null_value = self.null_value to_timestamp = datetime.timestamp for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue if isinstance(item, int): # support supplying raw integers to avoid # costly timezone conversions when using datetime continue if timezone: # Set server's timezone for offset-naive datetime. if item.tzinfo is None: item = timezone.localize(item) item = item.astimezone(utc) else: # If datetime is offset-aware use it's timezone. if item.tzinfo is not None: item = item.astimezone(utc) items[i] = int(to_timestamp(item)) class DateTime64Column(DateTimeColumn): ch_type = 'DateTime64' format = 'q' max_scale = 6 def __init__(self, scale=0, **kwargs): self.scale = scale super(DateTime64Column, self).__init__(**kwargs) def after_read_items(self, items, nulls_map=None): scale = float(10 ** self.scale) tz = self.timezone fromts = datetime.fromtimestamp # A bit ugly copy-paste. But it helps save time on items # processing by avoiding lambda calls or if in loop. if self.offset_naive: if tz: if nulls_map is None: return tuple( fromts(item / scale, tz).replace(tzinfo=None) for item in items ) else: return tuple( (None if is_null else fromts(items[i] / scale, tz).replace(tzinfo=None)) for i, is_null in enumerate(nulls_map) ) else: if nulls_map is None: return tuple(fromts(item / scale) for item in items) else: return tuple( (None if is_null else fromts(items[i] / scale)) for i, is_null in enumerate(nulls_map) ) else: if nulls_map is None: return tuple(fromts(item / scale, tz) for item in items) else: return tuple( (None if is_null else fromts(items[i] / scale, tz)) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): scale = 10 ** self.scale frac_scale = 10 ** (self.max_scale - self.scale) timezone = self.timezone null_value = self.null_value to_timestamp = datetime.timestamp for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue if isinstance(item, int): # support supplying raw integers to avoid # costly timezone conversions when using datetime continue if timezone: # Set server's timezone for offset-naive datetime. if item.tzinfo is None: item = timezone.localize(item) item = item.astimezone(utc) else: # If datetime is offset-aware use it's timezone. if item.tzinfo is not None: item = item.astimezone(utc) items[i] = ( int(to_timestamp(item)) * scale + int(item.microsecond / frac_scale) ) def create_datetime_column(spec, column_options): if spec.startswith('DateTime64'): cls = DateTime64Column spec = spec[11:-1] params = spec.split(',', 1) column_options['scale'] = int(params[0]) if len(params) > 1: spec = params[1].strip() + ')' else: cls = DateTimeColumn spec = spec[9:] context = column_options['context'] tz_name = timezone = None offset_naive = True # Use column's timezone if it's specified. if spec and spec[-1] == ')': tz_name = spec[1:-2] offset_naive = False else: if not context.settings.get('use_client_time_zone', False): local_timezone = get_localzone_name_compat() if local_timezone != context.server_info.timezone: tz_name = context.server_info.timezone if tz_name: timezone = get_timezone(tz_name) return cls(timezone=timezone, offset_naive=offset_naive, **column_options) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/decimalcolumn.py000066400000000000000000000070421420676740400270440ustar00rootroot00000000000000from decimal import Decimal, localcontext from .base import FormatColumn from .exceptions import ColumnTypeMismatchException from .intcolumn import Int128Column, Int256Column class DecimalColumn(FormatColumn): py_types = (Decimal, float, int) max_precision = None def __init__(self, precision, scale, types_check=False, **kwargs): self.precision = precision self.scale = scale super(DecimalColumn, self).__init__(**kwargs) if types_check: def check_item(value): parts = str(value).split('.') int_part = parts[0] frac_part = parts[1] if len(parts) > 1 else '' if len(int_part) > precision: raise ColumnTypeMismatchException(value) if len(frac_part) > scale: raise ColumnTypeMismatchException(value) self.check_item = check_item def after_read_items(self, items, nulls_map=None): if self.scale >= 1: scale = 10 ** self.scale if nulls_map is None: return tuple(Decimal(item) / scale for item in items) else: return tuple( (None if is_null else Decimal(items[i]) / scale) for i, is_null in enumerate(nulls_map) ) else: if nulls_map is None: return tuple(Decimal(item) for item in items) else: return tuple( (None if is_null else Decimal(items[i])) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): null_value = self.null_value if self.scale >= 1: scale = 10 ** self.scale for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value else: items[i] = int(Decimal(str(item)) * scale) else: for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value else: items[i] = int(Decimal(str(item))) # Override default precision to the maximum supported by underlying type. def _write_data(self, items, buf): with localcontext() as ctx: ctx.prec = self.max_precision super(DecimalColumn, self)._write_data(items, buf) def _read_data(self, n_items, buf, nulls_map=None): with localcontext() as ctx: ctx.prec = self.max_precision return super(DecimalColumn, self)._read_data( n_items, buf, nulls_map=nulls_map ) class Decimal32Column(DecimalColumn): format = 'i' max_precision = 9 class Decimal64Column(DecimalColumn): format = 'q' max_precision = 18 class Decimal128Column(DecimalColumn, Int128Column): max_precision = 38 class Decimal256Column(DecimalColumn, Int256Column): max_precision = 76 def create_decimal_column(spec, column_options): precision, scale = spec[8:-1].split(',') precision, scale = int(precision), int(scale) # Maximum precisions for underlying types are: # Int32 10**9 # Int64 10**18 # Int128 10**38 # Int256 10**76 if precision <= 9: cls = Decimal32Column elif precision <= 18: cls = Decimal64Column elif precision <= 38: cls = Decimal128Column else: cls = Decimal256Column return cls(precision, scale, **column_options) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/enumcolumn.py000066400000000000000000000062231420676740400264120ustar00rootroot00000000000000from enum import Enum from .. import errors from .intcolumn import IntColumn class EnumColumn(IntColumn): py_types = (Enum, int, str) def __init__(self, enum_cls, **kwargs): self.enum_cls = enum_cls super(EnumColumn, self).__init__(**kwargs) def before_write_items(self, items, nulls_map=None): null_value = self.null_value enum_cls = self.enum_cls for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue source_value = item.name if isinstance(item, Enum) else item # Check real enum value try: if isinstance(source_value, str): items[i] = enum_cls[source_value].value else: items[i] = enum_cls(source_value).value except (ValueError, KeyError): choices = ', '.join( "'{}' = {}".format(x.name.replace("'", r"\'"), x.value) for x in enum_cls ) enum_str = '{}({})'.format(enum_cls.__name__, choices) raise errors.LogicalError( "Unknown element '{}' for type {}" .format(source_value, enum_str) ) def after_read_items(self, items, nulls_map=None): enum_cls = self.enum_cls if nulls_map is None: return tuple(enum_cls(item).name for item in items) else: return tuple( (None if is_null else enum_cls(items[i]).name) for i, is_null in enumerate(nulls_map) ) class Enum8Column(EnumColumn): ch_type = 'Enum8' format = 'b' int_size = 1 class Enum16Column(EnumColumn): ch_type = 'Enum16' format = 'h' int_size = 2 def create_enum_column(spec, column_options): if spec.startswith('Enum8'): params = spec[6:-1] cls = Enum8Column else: params = spec[7:-1] cls = Enum16Column return cls(Enum(cls.ch_type, _parse_options(params)), **column_options) def _parse_options(option_string): options = dict() after_name = False escaped = False quote_character = None name = '' value = '' for ch in option_string: if escaped: name += ch escaped = False # accepting escaped character elif after_name: if ch in (' ', '='): pass elif ch == ',': options[name] = int(value) after_name = False name = '' value = '' # reset before collecting new option else: value += ch elif quote_character: if ch == '\\': escaped = True elif ch == quote_character: quote_character = None after_name = True # start collecting option value else: name += ch else: if ch == "'": quote_character = ch if after_name: options.setdefault(name, int(value)) # append word after last comma return options python-clickhouse-driver-0.2.3/clickhouse_driver/columns/exceptions.py000066400000000000000000000002431420676740400264050ustar00rootroot00000000000000 class ColumnException(Exception): pass class ColumnTypeMismatchException(ColumnException): pass class StructPackException(ColumnException): pass python-clickhouse-driver-0.2.3/clickhouse_driver/columns/floatcolumn.py000066400000000000000000000016351420676740400265550ustar00rootroot00000000000000from ctypes import c_float from .base import FormatColumn class FloatColumn(FormatColumn): py_types = (float, int) class Float32Column(FloatColumn): ch_type = 'Float32' format = 'f' def __init__(self, types_check=False, **kwargs): super(Float32Column, self).__init__(types_check=types_check, **kwargs) if types_check: # Chop only bytes that fit current type. # Cast to -nan or nan if overflows. def before_write_items(items, nulls_map=None): null_value = self.null_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value else: items[i] = c_float(item).value self.before_write_items = before_write_items class Float64Column(FloatColumn): ch_type = 'Float64' format = 'd' python-clickhouse-driver-0.2.3/clickhouse_driver/columns/intcolumn.py000066400000000000000000000066771420676740400262550ustar00rootroot00000000000000 from .exceptions import ColumnTypeMismatchException from .base import FormatColumn from .largeint import ( int128_from_quads, int128_to_quads, uint128_from_quads, uint128_to_quads, int256_from_quads, int256_to_quads, uint256_from_quads, uint256_to_quads ) class IntColumn(FormatColumn): py_types = (int, ) int_size = None def __init__(self, types_check=False, **kwargs): super(IntColumn, self).__init__(types_check=types_check, **kwargs) if types_check: self.mask = (1 << 8 * self.int_size) - 1 # Chop only bytes that fit current type. # ctypes.c_intXX is slower. def before_write_items(items, nulls_map=None): # TODO: cythonize null_value = self.null_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue if item >= 0: sign = 1 else: sign = -1 item = -item items[i] = sign * (item & self.mask) self.before_write_items = before_write_items class UIntColumn(IntColumn): def __init__(self, types_check=False, **kwargs): super(UIntColumn, self).__init__(types_check=types_check, **kwargs) if types_check: def check_item(value): if value < 0: raise ColumnTypeMismatchException(value) self.check_item = check_item class Int8Column(IntColumn): ch_type = 'Int8' format = 'b' int_size = 1 class Int16Column(IntColumn): ch_type = 'Int16' format = 'h' int_size = 2 class Int32Column(IntColumn): ch_type = 'Int32' format = 'i' int_size = 4 class Int64Column(IntColumn): ch_type = 'Int64' format = 'q' int_size = 8 class UInt8Column(UIntColumn): ch_type = 'UInt8' format = 'B' int_size = 1 class UInt16Column(UIntColumn): ch_type = 'UInt16' format = 'H' int_size = 2 class UInt32Column(UIntColumn): ch_type = 'UInt32' format = 'I' int_size = 4 class UInt64Column(UIntColumn): ch_type = 'UInt64' format = 'Q' int_size = 8 class LargeIntColumn(IntColumn): format = 'Q' # We manually deal with sign in read/write. factor = None to_quads = None from_quads = None def write_items(self, items, buf): n_items = len(items) s = self.make_struct(self.factor * n_items) uint_64_pairs = self.to_quads(items, n_items) buf.write(s.pack(*uint_64_pairs)) def read_items(self, n_items, buf): s = self.make_struct(self.factor * n_items) items = s.unpack(buf.read(s.size)) return self.from_quads(items, n_items) class Int128Column(LargeIntColumn): ch_type = 'Int128' int_size = 16 factor = 2 to_quads = int128_to_quads from_quads = int128_from_quads class UInt128Column(LargeIntColumn): ch_type = 'UInt128' int_size = 16 factor = 2 to_quads = uint128_to_quads from_quads = uint128_from_quads class Int256Column(LargeIntColumn): ch_type = 'Int256' int_size = 32 factor = 4 to_quads = int256_to_quads from_quads = int256_from_quads class UInt256Column(LargeIntColumn): ch_type = 'UInt256' int_size = 32 factor = 4 to_quads = uint256_to_quads from_quads = uint256_from_quads python-clickhouse-driver-0.2.3/clickhouse_driver/columns/intervalcolumn.py000066400000000000000000000011301420676740400272620ustar00rootroot00000000000000from .intcolumn import Int64Column class IntervalColumn(Int64Column): pass class IntervalDayColumn(IntervalColumn): ch_type = 'IntervalDay' class IntervalWeekColumn(IntervalColumn): ch_type = 'IntervalWeek' class IntervalMonthColumn(IntervalColumn): ch_type = 'IntervalMonth' class IntervalYearColumn(IntervalColumn): ch_type = 'IntervalYear' class IntervalHourColumn(IntervalColumn): ch_type = 'IntervalHour' class IntervalMinuteColumn(IntervalColumn): ch_type = 'IntervalMinute' class IntervalSecondColumn(IntervalColumn): ch_type = 'IntervalSecond' python-clickhouse-driver-0.2.3/clickhouse_driver/columns/ipcolumn.py000066400000000000000000000077771420676740400260750ustar00rootroot00000000000000from ipaddress import IPv4Address, IPv6Address, AddressValueError from .. import errors from .exceptions import ColumnTypeMismatchException from .stringcolumn import ByteFixedString from .intcolumn import UInt32Column class IPv4Column(UInt32Column): ch_type = "IPv4" py_types = (str, IPv4Address, int) def __init__(self, types_check=False, **kwargs): # UIntColumn overrides before_write_item and check_item # in its __init__ when types_check is True so we force # __init__ without it then add the appropriate check method for IPv4 super(UInt32Column, self).__init__(types_check=False, **kwargs) self.types_check_enabled = types_check if types_check: def check_item(value): if isinstance(value, int) and value < 0: raise ColumnTypeMismatchException(value) if not isinstance(value, IPv4Address): try: value = IPv4Address(value) except AddressValueError: # Cannot parse input in a valid IPv4 raise ColumnTypeMismatchException(value) self.check_item = check_item def after_read_items(self, items, nulls_map=None): if nulls_map is None: return tuple(IPv4Address(item) for item in items) else: return tuple( (None if is_null else IPv4Address(items[i])) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): null_value = self.null_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue # allow Ipv4 in integer, string or IPv4Address object try: if isinstance(item, int): continue if not isinstance(item, IPv4Address): item = IPv4Address(item) items[i] = int(item) except AddressValueError: raise errors.CannotParseDomainError( "Cannot parse IPv4 '{}'".format(item) ) class IPv6Column(ByteFixedString): ch_type = "IPv6" py_types = (str, IPv6Address, bytes) def __init__(self, types_check=False, **kwargs): super(IPv6Column, self).__init__(16, types_check=types_check, **kwargs) if types_check: def check_item(value): if isinstance(value, bytes) and len(value) != 16: raise ColumnTypeMismatchException(value) if not isinstance(value, IPv6Address): try: value = IPv6Address(value) except AddressValueError: # Cannot parse input in a valid IPv6 raise ColumnTypeMismatchException(value) self.check_item = check_item def after_read_items(self, items, nulls_map=None): if nulls_map is None: return tuple(IPv6Address(item) for item in items) else: return tuple( (None if is_null else IPv6Address(items[i])) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): null_value = self.null_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue # allow Ipv6 in bytes or python IPv6Address # this is raw bytes (not encoded) in order to fit FixedString(16) try: if isinstance(item, bytes): continue if not isinstance(item, IPv6Address): item = IPv6Address(item) items[i] = item.packed except AddressValueError: raise errors.CannotParseDomainError( "Cannot parse IPv6 '{}'".format(item) ) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/largeint.c000066400000000000000000010106411420676740400256270ustar00rootroot00000000000000/* Generated by Cython 0.29.21 */ /* BEGIN: Cython Metadata { "distutils": { "depends": [], "name": "clickhouse_driver.columns.largeint", "sources": [ "clickhouse_driver/columns/largeint.pyx" ] }, "module_name": "clickhouse_driver.columns.largeint" } END: Cython Metadata */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else #define CYTHON_ABI "0_29_21" #define CYTHON_HEX_VERSION 0x001D15F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #define __PYX_COMMA , #ifndef HAVE_LONG_LONG #if PY_VERSION_HEX >= 0x02070000 #define HAVE_LONG_LONG #endif #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #if PY_VERSION_HEX < 0x03050000 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #undef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #undef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 1 #undef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 0 #undef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 0 #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) #define CYTHON_USE_PYTYPE_LOOKUP 1 #endif #if PY_MAJOR_VERSION < 3 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 #endif #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #if PY_VERSION_HEX < 0x030300F0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #elif !defined(CYTHON_USE_UNICODE_WRITER) #define CYTHON_USE_UNICODE_WRITER 1 #endif #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #ifndef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 1 #endif #ifndef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 1 #endif #ifndef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) #endif #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #ifndef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) #endif #endif #if !defined(CYTHON_FAST_PYCCALL) #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) #endif #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #undef SHIFT #undef BASE #undef MASK #ifdef SIZEOF_VOID_P enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; #endif #endif #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_cpp_attribute #define __has_cpp_attribute(x) 0 #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif #ifndef CYTHON_MAYBE_UNUSED_VAR # if defined(__cplusplus) template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } # else # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) # endif #endif #ifndef CYTHON_NCP_UNUSED # if CYTHON_COMPILING_IN_CPYTHON # define CYTHON_NCP_UNUSED # else # define CYTHON_NCP_UNUSED CYTHON_UNUSED # endif #endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifdef _MSC_VER #ifndef _MSC_STDINT_H_ #if _MSC_VER < 1300 typedef unsigned char uint8_t; typedef unsigned int uint32_t; #else typedef unsigned __int8 uint8_t; typedef unsigned __int32 uint32_t; #endif #endif #else #include #endif #ifndef CYTHON_FALLTHROUGH #if defined(__cplusplus) && __cplusplus >= 201103L #if __has_cpp_attribute(fallthrough) #define CYTHON_FALLTHROUGH [[fallthrough]] #elif __has_cpp_attribute(clang::fallthrough) #define CYTHON_FALLTHROUGH [[clang::fallthrough]] #elif __has_cpp_attribute(gnu::fallthrough) #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] #endif #endif #ifndef CYTHON_FALLTHROUGH #if __has_attribute(fallthrough) #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) #else #define CYTHON_FALLTHROUGH #endif #endif #if defined(__clang__ ) && defined(__apple_build_version__) #if __apple_build_version__ < 7000000 #undef CYTHON_FALLTHROUGH #define CYTHON_FALLTHROUGH #endif #endif #endif #ifndef CYTHON_INLINE #if defined(__clang__) #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) #elif defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif #ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif #ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #ifndef METH_STACKLESS #define METH_STACKLESS 0 #endif #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) #ifndef METH_FASTCALL #define METH_FASTCALL 0x80 #endif typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames); #else #define __Pyx_PyCFunctionFast _PyCFunctionFast #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) #define PyObject_Realloc(p) PyMem_Realloc(p) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 #define PyMem_RawMalloc(n) PyMem_Malloc(n) #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) #define PyMem_RawFree(p) PyMem_Free(p) #endif #if CYTHON_COMPILING_IN_PYSTON #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) #else #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) #endif #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #elif PY_VERSION_HEX >= 0x03060000 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() #elif PY_VERSION_HEX >= 0x03000000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #else #define __Pyx_PyThreadState_Current _PyThreadState_Current #endif #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) #include "pythread.h" #define Py_tss_NEEDS_INIT 0 typedef int Py_tss_t; static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { *key = PyThread_create_key(); return 0; } static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); *key = Py_tss_NEEDS_INIT; return key; } static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { PyObject_Free(key); } static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { return *key != Py_tss_NEEDS_INIT; } static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { PyThread_delete_key(*key); *key = Py_tss_NEEDS_INIT; } static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { return PyThread_set_key_value(*key, value); } static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { return PyThread_get_key_value(*key); } #endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else #define __Pyx_PyDict_NewPresized(n) PyDict_New() #endif #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) #else #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) #else #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 #define PyUnicode_1BYTE_KIND 1 #define PyUnicode_2BYTE_KIND 2 #define PyUnicode_4BYTE_KIND 4 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #endif #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)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) #define PyObject_ASCII(o) PyObject_Repr(o) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #if PY_VERSION_HEX >= 0x030900A4 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) #else #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) #endif #if CYTHON_ASSUME_SAFE_MACROS #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) #else #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) #endif #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #if CYTHON_USE_ASYNC_SLOTS #if PY_VERSION_HEX >= 0x030500B1 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #else #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #endif #else #define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef __Pyx_PyAsyncMethodsStruct typedef struct { unaryfunc am_await; unaryfunc am_aiter; unaryfunc am_anext; } __Pyx_PyAsyncMethodsStruct; #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) #define __Pyx_truncl trunc #else #define __Pyx_truncl truncl #endif #define __PYX_MARK_ERR_POS(f_index, lineno) \ { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } #define __PYX_ERR(f_index, lineno, Ln_error) \ { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #define __PYX_HAVE__clickhouse_driver__columns__largeint #define __PYX_HAVE_API__clickhouse_driver__columns__largeint /* Early includes */ #include #include #include "pythread.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) #define CYTHON_WITHOUT_ASSERTIONS #endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_uchar_cast(c) ((unsigned char)c) #define __Pyx_long_cast(x) ((long)x) #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ (sizeof(type) < sizeof(Py_ssize_t)) ||\ (sizeof(type) > sizeof(Py_ssize_t) &&\ likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX) &&\ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ v == (type)PY_SSIZE_T_MIN))) ||\ (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { return (size_t) i < (size_t) limit; } #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) #elif SIZEOF_INT >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) #elif defined (_MSC_VER) #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) #define __Pyx_sst_abs(value) __builtin_llabs(value) #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); #define __Pyx_PySequence_Tuple(obj)\ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_ASSUME_SAFE_MACROS #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) #else #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) #endif #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } static PyObject *__pyx_m = NULL; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_cython_runtime = NULL; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "clickhouse_driver/columns/largeint.pyx", "type.pxd", "bool.pxd", "complex.pxd", }; /*--- Type declarations ---*/ /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil)\ if (acquire_gil) {\ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ PyGILState_Release(__pyx_gilstate_save);\ } else {\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_XDECREF(tmp);\ } while (0) #define __Pyx_DECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) /* PyObjectGetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ __Pyx_GetItemInt_Generic(o, to_py_func(i)))) #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); /* PyIntBinop.proto */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); #else #define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\ (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) #endif /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /* ImportFrom.proto */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /* PyDictVersioning.proto */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ (version_var) = __PYX_GET_DICT_VERSION(dict);\ (cache_var) = (value); #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ (VAR) = __pyx_dict_cached_value;\ } else {\ (VAR) = __pyx_dict_cached_value = (LOOKUP);\ __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ }\ } static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); #else #define __PYX_GET_DICT_VERSION(dict) (0) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); #endif /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS #define __Pyx_GetModuleGlobalName(var, name) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } #define __Pyx_GetModuleGlobalNameUncached(var, name) {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ } static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); #endif /* PyThreadStateGet.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type #else #define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_assign #define __Pyx_PyErr_Occurred() PyErr_Occurred() #endif /* PyErrFetchRestore.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) #else #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #endif #else #define __Pyx_PyErr_Clear() PyErr_Clear() #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) #endif /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) #else static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); #endif /* CodeObjectCache.proto */ typedef struct { PyCodeObject* code_object; int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); /* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value); /* CIntFromPy.proto */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* FastTypeChecks.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); #else #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /* Module declarations from 'cpython.version' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.type' */ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'libc.string' */ /* Module declarations from 'libc.stdio' */ /* Module declarations from 'cpython.object' */ /* Module declarations from 'cpython.ref' */ /* Module declarations from 'cpython.exc' */ /* Module declarations from 'cpython.module' */ /* Module declarations from 'cpython.mem' */ /* Module declarations from 'cpython.tuple' */ /* Module declarations from 'cpython.list' */ /* Module declarations from 'cpython.sequence' */ /* Module declarations from 'cpython.mapping' */ /* Module declarations from 'cpython.iterator' */ /* Module declarations from 'cpython.number' */ /* Module declarations from 'cpython.int' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; /* Module declarations from 'cpython.long' */ /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.complex' */ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.string' */ /* Module declarations from 'cpython.unicode' */ /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ /* Module declarations from 'cpython.function' */ /* Module declarations from 'cpython.method' */ /* Module declarations from 'cpython.weakref' */ /* Module declarations from 'cpython.getargs' */ /* Module declarations from 'cpython.pythread' */ /* Module declarations from 'cpython.pystate' */ /* Module declarations from 'cpython.cobject' */ /* Module declarations from 'cpython.oldbuffer' */ /* Module declarations from 'cpython.set' */ /* Module declarations from 'cpython.buffer' */ /* Module declarations from 'cpython.bytes' */ /* Module declarations from 'cpython.pycapsule' */ /* Module declarations from 'cpython' */ /* Module declarations from 'clickhouse_driver.columns.largeint' */ static PyObject *__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64 = 0; static PyObject *__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64 = 0; #define __Pyx_MODULE_NAME "clickhouse_driver.columns.largeint" extern int __pyx_module_is_main_clickhouse_driver__columns__largeint; int __pyx_module_is_main_clickhouse_driver__columns__largeint = 0; /* Implementation of 'clickhouse_driver.columns.largeint' */ static PyObject *__pyx_builtin_range; static const char __pyx_k_[] = ""; static const char __pyx_k_i[] = "i"; static const char __pyx_k_x[] = "x"; static const char __pyx_k_ix[] = "ix"; static const char __pyx_k_item[] = "item"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_items[] = "items"; static const char __pyx_k_range[] = "range"; static const char __pyx_k_factor[] = "factor"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_writer[] = "writer"; static const char __pyx_k_n_items[] = "n_items"; static const char __pyx_k_MAX_INT64[] = "MAX_INT64"; static const char __pyx_k_MAX_UINT64[] = "MAX_UINT64"; static const char __pyx_k_quad_items[] = "quad_items"; static const char __pyx_k_int128_to_quads[] = "int128_to_quads"; static const char __pyx_k_int256_to_quads[] = "int256_to_quads"; static const char __pyx_k_uint128_to_quads[] = "uint128_to_quads"; static const char __pyx_k_uint256_to_quads[] = "uint256_to_quads"; static const char __pyx_k_int128_from_quads[] = "int128_from_quads"; static const char __pyx_k_int256_from_quads[] = "int256_from_quads"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_uint128_from_quads[] = "uint128_from_quads"; static const char __pyx_k_uint256_from_quads[] = "uint256_from_quads"; static const char __pyx_k_clickhouse_driver_columns_largei[] = "clickhouse_driver/columns/largeint.pyx"; static const char __pyx_k_clickhouse_driver_columns_largei_2[] = "clickhouse_driver.columns.largeint"; static PyObject *__pyx_n_s_; static PyObject *__pyx_n_s_MAX_INT64; static PyObject *__pyx_n_s_MAX_UINT64; static PyObject *__pyx_kp_s_clickhouse_driver_columns_largei; static PyObject *__pyx_n_s_clickhouse_driver_columns_largei_2; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_factor; static PyObject *__pyx_n_s_i; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_int128_from_quads; static PyObject *__pyx_n_s_int128_to_quads; static PyObject *__pyx_n_s_int256_from_quads; static PyObject *__pyx_n_s_int256_to_quads; static PyObject *__pyx_n_s_item; static PyObject *__pyx_n_s_items; static PyObject *__pyx_n_s_ix; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_n_items; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_quad_items; static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_uint128_from_quads; static PyObject *__pyx_n_s_uint128_to_quads; static PyObject *__pyx_n_s_uint256_from_quads; static PyObject *__pyx_n_s_uint256_to_quads; static PyObject *__pyx_n_s_writer; static PyObject *__pyx_n_s_x; 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_64; static PyObject *__pyx_int_128; static PyObject *__pyx_int_192; static PyObject *__pyx_tuple__2; static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__10; static PyObject *__pyx_tuple__12; static PyObject *__pyx_tuple__14; static PyObject *__pyx_tuple__16; static PyObject *__pyx_codeobj__3; static PyObject *__pyx_codeobj__5; static PyObject *__pyx_codeobj__7; static PyObject *__pyx_codeobj__9; static PyObject *__pyx_codeobj__11; static PyObject *__pyx_codeobj__13; static PyObject *__pyx_codeobj__15; static PyObject *__pyx_codeobj__17; /* Late includes */ /* "clickhouse_driver/columns/largeint.pyx":10 * * * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_1int128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_1int128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_quad_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("int128_from_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("int128_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 10, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int128_from_quads") < 0)) __PYX_ERR(0, 10, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_quad_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("int128_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 10, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_int128_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; unsigned PY_LONG_LONG __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("int128_from_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":11 * * def int128_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 2 # <<<<<<<<<<<<<< * items = PyTuple_New(n_items) * */ __pyx_v_factor = 2; /* "clickhouse_driver/columns/largeint.pyx":12 * def int128_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":17 * cdef object item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":18 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * if quad_items[ix + 1] > MAX_INT64: */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":20 * ix = factor * i * * if quad_items[ix + 1] > MAX_INT64: # <<<<<<<<<<<<<< * item = ( * -((MAX_UINT64 - quad_items[ix + 1]) << 64) */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_7) { /* "clickhouse_driver/columns/largeint.pyx":22 * if quad_items[ix + 1] > MAX_INT64: * item = ( * -((MAX_UINT64 - quad_items[ix + 1]) << 64) # <<<<<<<<<<<<<< * - (MAX_UINT64 - quad_items[ix]) * - 1 */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Negative(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":23 * item = ( * -((MAX_UINT64 - quad_items[ix + 1]) << 64) * - (MAX_UINT64 - quad_items[ix]) # <<<<<<<<<<<<<< * - 1 * ) */ __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Subtract(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":24 * -((MAX_UINT64 - quad_items[ix + 1]) << 64) * - (MAX_UINT64 - quad_items[ix]) * - 1 # <<<<<<<<<<<<<< * ) * */ __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) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":20 * ix = factor * i * * if quad_items[ix + 1] > MAX_INT64: # <<<<<<<<<<<<<< * item = ( * -((MAX_UINT64 - quad_items[ix + 1]) << 64) */ goto __pyx_L5; } /* "clickhouse_driver/columns/largeint.pyx":28 * * else: * item = (quad_items[ix + 1] << 64) + quad_items[ix] # <<<<<<<<<<<<<< * * Py_INCREF(item) */ /*else*/ { __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_8); __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __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) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L5:; /* "clickhouse_driver/columns/largeint.pyx":30 * item = (quad_items[ix + 1] << 64) + quad_items[ix] * * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":31 * * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * * return items */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":33 * PyTuple_SET_ITEM(items, i, item) * * return items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":10 * * * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":36 * * * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_3int128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_3int128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("int128_to_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("int128_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 36, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int128_to_quads") < 0)) __PYX_ERR(0, 36, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("int128_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 36, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_2int128_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_quad_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_x = 0; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("int128_to_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":37 * * def int128_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 2 # <<<<<<<<<<<<<< * quad_items = PyTuple_New(n_items * factor) * */ __pyx_v_factor = 2; /* "clickhouse_driver/columns/largeint.pyx":38 * def int128_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_quad_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":43 * cdef object x, item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":44 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * x = items[i] */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":46 * ix = factor * i * * x = items[i] # <<<<<<<<<<<<<< * if x < 0: * x = -x - 1 */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":47 * * x = items[i] * if x < 0: # <<<<<<<<<<<<<< * x = -x - 1 * */ __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) __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* "clickhouse_driver/columns/largeint.pyx":48 * x = items[i] * if x < 0: * x = -x - 1 # <<<<<<<<<<<<<< * * item = MAX_UINT64 - x & MAX_UINT64 */ __pyx_t_1 = PyNumber_Negative(__pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":50 * x = -x - 1 * * item = MAX_UINT64 - x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":51 * * item = MAX_UINT64 - x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":52 * item = MAX_UINT64 - x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":54 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":55 * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":56 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * else: */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":47 * * x = items[i] * if x < 0: # <<<<<<<<<<<<<< * x = -x - 1 * */ goto __pyx_L5; } /* "clickhouse_driver/columns/largeint.pyx":59 * * else: * item = x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ /*else*/ { __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":60 * else: * item = x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":61 * item = x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":63 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":64 * * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":65 * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * return quad_items */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); } __pyx_L5:; } /* "clickhouse_driver/columns/largeint.pyx":67 * PyTuple_SET_ITEM(quad_items, ix + 1, item) * * return quad_items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_quad_items); __pyx_r = __pyx_v_quad_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":36 * * * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_quad_items); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":70 * * * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_5uint128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_5uint128_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_quad_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("uint128_from_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("uint128_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 70, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint128_from_quads") < 0)) __PYX_ERR(0, 70, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_quad_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("uint128_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 70, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_4uint128_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; unsigned PY_LONG_LONG __pyx_t_5; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("uint128_from_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":71 * * def uint128_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 2 # <<<<<<<<<<<<<< * items = PyTuple_New(n_items) * */ __pyx_v_factor = 2; /* "clickhouse_driver/columns/largeint.pyx":72 * def uint128_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":77 * cdef object item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * item = (quad_items[ix + 1] << 64) + quad_items[ix] */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":78 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * item = (quad_items[ix + 1] << 64) + quad_items[ix] * */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":79 * for i in range(n_items): * ix = factor * i * item = (quad_items[ix + 1] << 64) + quad_items[ix] # <<<<<<<<<<<<<< * * Py_INCREF(item) */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7); __pyx_t_7 = 0; /* "clickhouse_driver/columns/largeint.pyx":81 * item = (quad_items[ix + 1] << 64) + quad_items[ix] * * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":82 * * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * * return items */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":84 * PyTuple_SET_ITEM(items, i, item) * * return items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":70 * * * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":87 * * * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_7uint128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_7uint128_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("uint128_to_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("uint128_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 87, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint128_to_quads") < 0)) __PYX_ERR(0, 87, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("uint128_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_6uint128_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_quad_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_x = 0; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("uint128_to_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":88 * * def uint128_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 2 # <<<<<<<<<<<<<< * quad_items = PyTuple_New(n_items * factor) * */ __pyx_v_factor = 2; /* "clickhouse_driver/columns/largeint.pyx":89 * def uint128_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_quad_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":94 * cdef object x, item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":95 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * x = items[i] */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":97 * ix = factor * i * * x = items[i] # <<<<<<<<<<<<<< * item = x & MAX_UINT64 * Py_INCREF(item) */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":98 * * x = items[i] * item = x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":99 * x = items[i] * item = x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":100 * item = x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":102 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/columns/largeint.pyx":103 * * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":104 * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * return quad_items */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":106 * PyTuple_SET_ITEM(quad_items, ix + 1, item) * * return quad_items # <<<<<<<<<<<<<< * * # 256 bits */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_quad_items); __pyx_r = __pyx_v_quad_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":87 * * * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint128_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_quad_items); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":111 * * * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_9int256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_9int256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_quad_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("int256_from_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("int256_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 111, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int256_from_quads") < 0)) __PYX_ERR(0, 111, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_quad_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("int256_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 111, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_8int256_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; unsigned PY_LONG_LONG __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("int256_from_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":112 * * def int256_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 4 # <<<<<<<<<<<<<< * items = PyTuple_New(n_items) * */ __pyx_v_factor = 4; /* "clickhouse_driver/columns/largeint.pyx":113 * def int256_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":118 * cdef object item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":119 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * if quad_items[ix + 3] > MAX_INT64: */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":121 * ix = factor * i * * if quad_items[ix + 3] > MAX_INT64: # <<<<<<<<<<<<<< * item = ( * -((MAX_UINT64 - quad_items[ix + 3]) << 192) */ __pyx_t_5 = (__pyx_v_ix + 3); __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) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 121, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_7) { /* "clickhouse_driver/columns/largeint.pyx":123 * if quad_items[ix + 3] > MAX_INT64: * item = ( * -((MAX_UINT64 - quad_items[ix + 3]) << 192) # <<<<<<<<<<<<<< * -((MAX_UINT64 - quad_items[ix + 2]) << 128) * -((MAX_UINT64 - quad_items[ix + 1]) << 64) */ __pyx_t_5 = (__pyx_v_ix + 3); __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Negative(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":124 * item = ( * -((MAX_UINT64 - quad_items[ix + 3]) << 192) * -((MAX_UINT64 - quad_items[ix + 2]) << 128) # <<<<<<<<<<<<<< * -((MAX_UINT64 - quad_items[ix + 1]) << 64) * - (MAX_UINT64 - quad_items[ix]) */ __pyx_t_5 = (__pyx_v_ix + 2); __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":125 * -((MAX_UINT64 - quad_items[ix + 3]) << 192) * -((MAX_UINT64 - quad_items[ix + 2]) << 128) * -((MAX_UINT64 - quad_items[ix + 1]) << 64) # <<<<<<<<<<<<<< * - (MAX_UINT64 - quad_items[ix]) * - 1 */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Subtract(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":126 * -((MAX_UINT64 - quad_items[ix + 2]) << 128) * -((MAX_UINT64 - quad_items[ix + 1]) << 64) * - (MAX_UINT64 - quad_items[ix]) # <<<<<<<<<<<<<< * - 1 * ) */ __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Subtract(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":127 * -((MAX_UINT64 - quad_items[ix + 1]) << 64) * - (MAX_UINT64 - quad_items[ix]) * - 1 # <<<<<<<<<<<<<< * ) * */ __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) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":121 * ix = factor * i * * if quad_items[ix + 3] > MAX_INT64: # <<<<<<<<<<<<<< * item = ( * -((MAX_UINT64 - quad_items[ix + 3]) << 192) */ goto __pyx_L5; } /* "clickhouse_driver/columns/largeint.pyx":134 * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<< * quad_items[ix] * ) */ /*else*/ { /* "clickhouse_driver/columns/largeint.pyx":132 * else: * item = ( * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<< * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + */ __pyx_t_5 = (__pyx_v_ix + 3); __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) __Pyx_GOTREF(__pyx_t_8); __pyx_t_6 = PyNumber_Lshift(__pyx_t_8, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":133 * item = ( * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<< * (quad_items[ix + 1] << 64) + * quad_items[ix] */ __pyx_t_5 = (__pyx_v_ix + 2); __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) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyNumber_Lshift(__pyx_t_8, __pyx_int_128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; /* "clickhouse_driver/columns/largeint.pyx":132 * else: * item = ( * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<< * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + */ __pyx_t_8 = PyNumber_Add(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":134 * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<< * quad_items[ix] * ) */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":133 * item = ( * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<< * (quad_items[ix + 1] << 64) + * quad_items[ix] */ __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":135 * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + * quad_items[ix] # <<<<<<<<<<<<<< * ) * */ __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) __Pyx_GOTREF(__pyx_t_6); /* "clickhouse_driver/columns/largeint.pyx":134 * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<< * quad_items[ix] * ) */ __pyx_t_8 = PyNumber_Add(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_8); __pyx_t_8 = 0; } __pyx_L5:; /* "clickhouse_driver/columns/largeint.pyx":138 * ) * * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":139 * * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * * return items */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":141 * PyTuple_SET_ITEM(items, i, item) * * return items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":111 * * * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":144 * * * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_11int256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_11int256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("int256_to_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("int256_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 144, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "int256_to_quads") < 0)) __PYX_ERR(0, 144, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("int256_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 144, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_10int256_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_quad_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_x = 0; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("int256_to_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":145 * * def int256_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 4 # <<<<<<<<<<<<<< * quad_items = PyTuple_New(n_items * factor) * */ __pyx_v_factor = 4; /* "clickhouse_driver/columns/largeint.pyx":146 * def int256_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_quad_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":151 * cdef object x, item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":152 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * x = items[i] */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":154 * ix = factor * i * * x = items[i] # <<<<<<<<<<<<<< * if x < 0: * x = -x - 1 */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":155 * * x = items[i] * if x < 0: # <<<<<<<<<<<<<< * x = -x - 1 * */ __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) __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* "clickhouse_driver/columns/largeint.pyx":156 * x = items[i] * if x < 0: * x = -x - 1 # <<<<<<<<<<<<<< * * item = MAX_UINT64 - x & MAX_UINT64 */ __pyx_t_1 = PyNumber_Negative(__pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":158 * x = -x - 1 * * item = MAX_UINT64 - x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ __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) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":159 * * item = MAX_UINT64 - x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":160 * item = MAX_UINT64 - x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":162 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":163 * * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":164 * item = MAX_UINT64 - (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * item = MAX_UINT64 - (x >> 128) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":166 * PyTuple_SET_ITEM(quad_items, ix + 1, item) * * item = MAX_UINT64 - (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":167 * * item = MAX_UINT64 - (x >> 128) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 2, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":168 * item = MAX_UINT64 - (x >> 128) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<< * * item = MAX_UINT64 - (x >> 192) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":170 * PyTuple_SET_ITEM(quad_items, ix + 2, item) * * item = MAX_UINT64 - (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":171 * * item = MAX_UINT64 - (x >> 192) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 3, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":172 * item = MAX_UINT64 - (x >> 192) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<< * * else: */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":155 * * x = items[i] * if x < 0: # <<<<<<<<<<<<<< * x = -x - 1 * */ goto __pyx_L5; } /* "clickhouse_driver/columns/largeint.pyx":175 * * else: * item = x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ /*else*/ { __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":176 * else: * item = x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":177 * item = x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":179 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":180 * * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":181 * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * item = (x >> 128) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":183 * PyTuple_SET_ITEM(quad_items, ix + 1, item) * * item = (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) */ __pyx_t_6 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":184 * * item = (x >> 128) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 2, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":185 * item = (x >> 128) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<< * * item = (x >> 192) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":187 * PyTuple_SET_ITEM(quad_items, ix + 2, item) * * item = (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":188 * * item = (x >> 192) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 3, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":189 * item = (x >> 192) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<< * * return quad_items */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item); } __pyx_L5:; } /* "clickhouse_driver/columns/largeint.pyx":191 * PyTuple_SET_ITEM(quad_items, ix + 3, item) * * return quad_items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_quad_items); __pyx_r = __pyx_v_quad_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":144 * * * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.int256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_quad_items); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":194 * * * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_13uint256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_13uint256_from_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_quad_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("uint256_from_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quad_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quad_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("uint256_from_quads", 1, 2, 2, 1); __PYX_ERR(0, 194, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint256_from_quads") < 0)) __PYX_ERR(0, 194, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_quad_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("uint256_from_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 194, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_12uint256_from_quads(__pyx_self, __pyx_v_quad_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; unsigned PY_LONG_LONG __pyx_t_5; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("uint256_from_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":195 * * def uint256_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 4 # <<<<<<<<<<<<<< * items = PyTuple_New(n_items) * */ __pyx_v_factor = 4; /* "clickhouse_driver/columns/largeint.pyx":196 * def uint256_from_quads(quad_items, unsigned long long n_items): * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":201 * cdef object item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * item = ( */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":202 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * item = ( * (quad_items[ix + 3] << 192) + */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":204 * ix = factor * i * item = ( * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<< * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + */ __pyx_t_5 = (__pyx_v_ix + 3); __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) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyNumber_Lshift(__pyx_t_1, __pyx_int_192); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":205 * item = ( * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<< * (quad_items[ix + 1] << 64) + * quad_items[ix] */ __pyx_t_5 = (__pyx_v_ix + 2); __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) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = PyNumber_Lshift(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":204 * ix = factor * i * item = ( * (quad_items[ix + 3] << 192) + # <<<<<<<<<<<<<< * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + */ __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; /* "clickhouse_driver/columns/largeint.pyx":206 * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<< * quad_items[ix] * ) */ __pyx_t_5 = (__pyx_v_ix + 1); __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) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = PyNumber_Lshift(__pyx_t_7, __pyx_int_64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 206, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; /* "clickhouse_driver/columns/largeint.pyx":205 * item = ( * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + # <<<<<<<<<<<<<< * (quad_items[ix + 1] << 64) + * quad_items[ix] */ __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 205, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; /* "clickhouse_driver/columns/largeint.pyx":207 * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + * quad_items[ix] # <<<<<<<<<<<<<< * ) * */ __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) __Pyx_GOTREF(__pyx_t_6); /* "clickhouse_driver/columns/largeint.pyx":206 * (quad_items[ix + 3] << 192) + * (quad_items[ix + 2] << 128) + * (quad_items[ix + 1] << 64) + # <<<<<<<<<<<<<< * quad_items[ix] * ) */ __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":210 * ) * * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(items, i, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":211 * * Py_INCREF(item) * PyTuple_SET_ITEM(items, i, item) # <<<<<<<<<<<<<< * * return items */ PyTuple_SET_ITEM(__pyx_v_items, __pyx_v_i, __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":213 * PyTuple_SET_ITEM(items, i, item) * * return items # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_items); __pyx_r = __pyx_v_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":194 * * * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_from_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_items); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/columns/largeint.pyx":216 * * * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_15uint256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 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}; static PyObject *__pyx_pw_17clickhouse_driver_7columns_8largeint_15uint256_to_quads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; unsigned PY_LONG_LONG __pyx_v_n_items; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("uint256_to_quads (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_n_items,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_items)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("uint256_to_quads", 1, 2, 2, 1); __PYX_ERR(0, 216, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uint256_to_quads") < 0)) __PYX_ERR(0, 216, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_items = values[0]; __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) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("uint256_to_quads", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 216, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_7columns_8largeint_14uint256_to_quads(__pyx_self, __pyx_v_items, __pyx_v_n_items); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } 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) { unsigned int __pyx_v_factor; PyObject *__pyx_v_quad_items = NULL; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_ix; PyObject *__pyx_v_x = 0; PyObject *__pyx_v_item = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; unsigned PY_LONG_LONG __pyx_t_2; unsigned PY_LONG_LONG __pyx_t_3; unsigned PY_LONG_LONG __pyx_t_4; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("uint256_to_quads", 0); /* "clickhouse_driver/columns/largeint.pyx":217 * * def uint256_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 4 # <<<<<<<<<<<<<< * quad_items = PyTuple_New(n_items * factor) * */ __pyx_v_factor = 4; /* "clickhouse_driver/columns/largeint.pyx":218 * def uint256_to_quads(items, unsigned long long n_items): * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) # <<<<<<<<<<<<<< * * cdef unsigned long long i, ix */ __pyx_t_1 = PyTuple_New((__pyx_v_n_items * __pyx_v_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_quad_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":223 * cdef object x, item * * for i in range(n_items): # <<<<<<<<<<<<<< * ix = factor * i * */ __pyx_t_2 = __pyx_v_n_items; __pyx_t_3 = __pyx_t_2; for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/columns/largeint.pyx":224 * * for i in range(n_items): * ix = factor * i # <<<<<<<<<<<<<< * * x = items[i] */ __pyx_v_ix = (__pyx_v_factor * __pyx_v_i); /* "clickhouse_driver/columns/largeint.pyx":226 * ix = factor * i * * x = items[i] # <<<<<<<<<<<<<< * item = x & MAX_UINT64 * Py_INCREF(item) */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":227 * * x = items[i] * item = x & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) */ __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":228 * x = items[i] * item = x & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":229 * item = x & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix, item) # <<<<<<<<<<<<<< * * item = (x >> 64) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, __pyx_v_ix, __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":231 * PyTuple_SET_ITEM(quad_items, ix, item) * * item = (x >> 64) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/columns/largeint.pyx":232 * * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 1, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":233 * item = (x >> 64) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 1, item) # <<<<<<<<<<<<<< * * item = (x >> 128) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 1), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":235 * PyTuple_SET_ITEM(quad_items, ix + 1, item) * * item = (x >> 128) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) */ __pyx_t_5 = PyNumber_Rshift(__pyx_v_x, __pyx_int_128); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 235, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":236 * * item = (x >> 128) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 2, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":237 * item = (x >> 128) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 2, item) # <<<<<<<<<<<<<< * * item = (x >> 192) & MAX_UINT64 */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 2), __pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":239 * PyTuple_SET_ITEM(quad_items, ix + 2, item) * * item = (x >> 192) & MAX_UINT64 # <<<<<<<<<<<<<< * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) */ __pyx_t_1 = PyNumber_Rshift(__pyx_v_x, __pyx_int_192); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_item, __pyx_t_5); __pyx_t_5 = 0; /* "clickhouse_driver/columns/largeint.pyx":240 * * item = (x >> 192) & MAX_UINT64 * Py_INCREF(item) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(quad_items, ix + 3, item) * */ Py_INCREF(__pyx_v_item); /* "clickhouse_driver/columns/largeint.pyx":241 * item = (x >> 192) & MAX_UINT64 * Py_INCREF(item) * PyTuple_SET_ITEM(quad_items, ix + 3, item) # <<<<<<<<<<<<<< * * return quad_items */ PyTuple_SET_ITEM(__pyx_v_quad_items, (__pyx_v_ix + 3), __pyx_v_item); } /* "clickhouse_driver/columns/largeint.pyx":243 * PyTuple_SET_ITEM(quad_items, ix + 3, item) * * return quad_items # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_quad_items); __pyx_r = __pyx_v_quad_items; goto __pyx_L0; /* "clickhouse_driver/columns/largeint.pyx":216 * * * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.columns.largeint.uint256_to_quads", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_quad_items); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_item); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 #if CYTHON_PEP489_MULTI_PHASE_INIT static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ static int __pyx_pymod_exec_largeint(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec_largeint}, {0, NULL} }; #endif static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, "largeint", 0, /* m_doc */ #if CYTHON_PEP489_MULTI_PHASE_INIT 0, /* m_size */ #else -1, /* m_size */ #endif __pyx_methods /* m_methods */, #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_moduledef_slots, /* m_slots */ #else NULL, /* m_reload */ #endif NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif #ifndef CYTHON_SMALL_CODE #if defined(__clang__) #define CYTHON_SMALL_CODE #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) #define CYTHON_SMALL_CODE __attribute__((cold)) #else #define CYTHON_SMALL_CODE #endif #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 1, 1}, {&__pyx_n_s_MAX_INT64, __pyx_k_MAX_INT64, sizeof(__pyx_k_MAX_INT64), 0, 0, 1, 1}, {&__pyx_n_s_MAX_UINT64, __pyx_k_MAX_UINT64, sizeof(__pyx_k_MAX_UINT64), 0, 0, 1, 1}, {&__pyx_kp_s_clickhouse_driver_columns_largei, __pyx_k_clickhouse_driver_columns_largei, sizeof(__pyx_k_clickhouse_driver_columns_largei), 0, 0, 1, 0}, {&__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}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_factor, __pyx_k_factor, sizeof(__pyx_k_factor), 0, 0, 1, 1}, {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_int128_from_quads, __pyx_k_int128_from_quads, sizeof(__pyx_k_int128_from_quads), 0, 0, 1, 1}, {&__pyx_n_s_int128_to_quads, __pyx_k_int128_to_quads, sizeof(__pyx_k_int128_to_quads), 0, 0, 1, 1}, {&__pyx_n_s_int256_from_quads, __pyx_k_int256_from_quads, sizeof(__pyx_k_int256_from_quads), 0, 0, 1, 1}, {&__pyx_n_s_int256_to_quads, __pyx_k_int256_to_quads, sizeof(__pyx_k_int256_to_quads), 0, 0, 1, 1}, {&__pyx_n_s_item, __pyx_k_item, sizeof(__pyx_k_item), 0, 0, 1, 1}, {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, {&__pyx_n_s_ix, __pyx_k_ix, sizeof(__pyx_k_ix), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_n_items, __pyx_k_n_items, sizeof(__pyx_k_n_items), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_quad_items, __pyx_k_quad_items, sizeof(__pyx_k_quad_items), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_uint128_from_quads, __pyx_k_uint128_from_quads, sizeof(__pyx_k_uint128_from_quads), 0, 0, 1, 1}, {&__pyx_n_s_uint128_to_quads, __pyx_k_uint128_to_quads, sizeof(__pyx_k_uint128_to_quads), 0, 0, 1, 1}, {&__pyx_n_s_uint256_from_quads, __pyx_k_uint256_from_quads, sizeof(__pyx_k_uint256_from_quads), 0, 0, 1, 1}, {&__pyx_n_s_uint256_to_quads, __pyx_k_uint256_to_quads, sizeof(__pyx_k_uint256_to_quads), 0, 0, 1, 1}, {&__pyx_n_s_writer, __pyx_k_writer, sizeof(__pyx_k_writer), 0, 0, 1, 1}, {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 17, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "clickhouse_driver/columns/largeint.pyx":10 * * * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); __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) /* "clickhouse_driver/columns/largeint.pyx":36 * * * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); __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) /* "clickhouse_driver/columns/largeint.pyx":70 * * * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); __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) /* "clickhouse_driver/columns/largeint.pyx":87 * * * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); __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) /* "clickhouse_driver/columns/largeint.pyx":111 * * * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); __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) /* "clickhouse_driver/columns/largeint.pyx":144 * * * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); __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) /* "clickhouse_driver/columns/largeint.pyx":194 * * * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); __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) /* "clickhouse_driver/columns/largeint.pyx":216 * * * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_tuple__16); __Pyx_GIVEREF(__pyx_tuple__16); __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) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_192 = PyInt_FromLong(192); if (unlikely(!__pyx_int_192)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ static int __Pyx_modinit_global_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); /*--- Global init code ---*/ __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64 = Py_None; Py_INCREF(Py_None); __pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64 = Py_None; Py_INCREF(Py_None); __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_variable_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); /*--- Variable export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); /*--- Function export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_import_code(void) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); /*--- Type import code ---*/ __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), #else sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(2, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(3, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_variable_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); /*--- Variable import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } #ifndef CYTHON_NO_PYINIT_EXPORT #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC #elif PY_MAJOR_VERSION < 3 #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" void #else #define __Pyx_PyMODINIT_FUNC void #endif #else #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" PyObject * #else #define __Pyx_PyMODINIT_FUNC PyObject * #endif #endif #if PY_MAJOR_VERSION < 3 __Pyx_PyMODINIT_FUNC initlargeint(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC initlargeint(void) #else __Pyx_PyMODINIT_FUNC PyInit_largeint(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit_largeint(void) #if CYTHON_PEP489_MULTI_PHASE_INIT { return PyModuleDef_Init(&__pyx_moduledef); } static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { #if PY_VERSION_HEX >= 0x030700A1 static PY_INT64_T main_interpreter_id = -1; PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); if (main_interpreter_id == -1) { main_interpreter_id = current_id; return (unlikely(current_id == -1)) ? -1 : 0; } else if (unlikely(main_interpreter_id != current_id)) #else static PyInterpreterState *main_interpreter = NULL; PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; if (!main_interpreter) { main_interpreter = current_interpreter; } else if (unlikely(main_interpreter != current_interpreter)) #endif { PyErr_SetString( PyExc_ImportError, "Interpreter change detected - this module can only be loaded into one interpreter per process."); return -1; } return 0; } 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) { PyObject *value = PyObject_GetAttrString(spec, from_name); int result = 0; if (likely(value)) { if (allow_none || value != Py_None) { result = PyDict_SetItemString(moddict, to_name, value); } Py_DECREF(value); } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); } else { result = -1; } return result; } static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { PyObject *module = NULL, *moddict, *modname; if (__Pyx_check_single_interpreter()) return NULL; if (__pyx_m) return __Pyx_NewRef(__pyx_m); modname = PyObject_GetAttrString(spec, "name"); if (unlikely(!modname)) goto bad; module = PyModule_NewObject(modname); Py_DECREF(modname); if (unlikely(!module)) goto bad; moddict = PyModule_GetDict(module); if (unlikely(!moddict)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; return module; bad: Py_XDECREF(module); return NULL; } static CYTHON_SMALL_CODE int __pyx_pymod_exec_largeint(PyObject *__pyx_pyinit_module) #endif #endif { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m) { if (__pyx_m == __pyx_pyinit_module) return 0; PyErr_SetString(PyExc_RuntimeError, "Module 'largeint' has already been imported. Re-initialisation is not supported."); return -1; } #elif PY_MAJOR_VERSION >= 3 if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_largeint(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pxy_PyFrame_Initialize_Offsets __Pxy_PyFrame_Initialize_Offsets(); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_m = __pyx_pyinit_module; Py_INCREF(__pyx_m); #else #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("largeint", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) #endif __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_clickhouse_driver__columns__largeint) { if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "clickhouse_driver.columns.largeint")) { if (unlikely(PyDict_SetItemString(modules, "clickhouse_driver.columns.largeint", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Global type/function init code ---*/ (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); (void)__Pyx_modinit_function_export_code(); (void)__Pyx_modinit_type_init_code(); if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_variable_import_code(); (void)__Pyx_modinit_function_import_code(); /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /* "clickhouse_driver/columns/largeint.pyx":4 * from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM * * from .. import writer # <<<<<<<<<<<<<< * * cpdef object MAX_UINT64 = writer.MAX_UINT64 */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_writer); __Pyx_GIVEREF(__pyx_n_s_writer); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_writer); __pyx_t_2 = __Pyx_Import(__pyx_n_s_, __pyx_t_1, 2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_writer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_writer, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":6 * from .. import writer * * cpdef object MAX_UINT64 = writer.MAX_UINT64 # <<<<<<<<<<<<<< * cpdef object MAX_INT64 = writer.MAX_INT64 * */ __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_writer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XGOTREF(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64); __Pyx_DECREF_SET(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_UINT64, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/columns/largeint.pyx":7 * * cpdef object MAX_UINT64 = writer.MAX_UINT64 * cpdef object MAX_INT64 = writer.MAX_INT64 # <<<<<<<<<<<<<< * * */ __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_writer); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __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) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XGOTREF(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64); __Pyx_DECREF_SET(__pyx_v_17clickhouse_driver_7columns_8largeint_MAX_INT64, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":10 * * * def int128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_int128_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":36 * * * def int128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_int128_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 36, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":70 * * * def uint128_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint128_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 70, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":87 * * * def uint128_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 2 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint128_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":111 * * * def int256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_int256_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":144 * * * def int256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_int256_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":194 * * * def uint256_from_quads(quad_items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * items = PyTuple_New(n_items) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint256_from_quads, __pyx_t_2) < 0) __PYX_ERR(0, 194, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":216 * * * def uint256_to_quads(items, unsigned long long n_items): # <<<<<<<<<<<<<< * cdef unsigned int factor = 4 * quad_items = PyTuple_New(n_items * factor) */ __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) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_uint256_to_quads, __pyx_t_2) < 0) __PYX_ERR(0, 216, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/columns/largeint.pyx":1 * from cpython cimport Py_INCREF # <<<<<<<<<<<<<< * from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM * */ __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init clickhouse_driver.columns.largeint", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init clickhouse_driver.columns.largeint"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if CYTHON_PEP489_MULTI_PHASE_INIT return (__pyx_m != NULL) ? 0 : -1; #elif PY_MAJOR_VERSION >= 3 return __pyx_m; #else return; #endif } /* --- Runtime support code --- */ /* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule(modname); if (!m) goto end; p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif /* PyObjectGetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #endif /* GetBuiltinName */ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { PyErr_Format(PyExc_NameError, #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; } /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } /* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyList_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS Py_ssize_t wrapped_i = i; if (wraparound & unlikely(i < 0)) { wrapped_i += PyTuple_GET_SIZE(o); } if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS if (is_list || PyList_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; } } else if (PyTuple_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (likely(l >= 0)) { i += l; } else { if (!PyErr_ExceptionMatches(PyExc_OverflowError)) return NULL; PyErr_Clear(); } } return m->sq_item(o, i); } } #else if (is_list || PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { (void)inplace; (void)zerodivision_check; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(op1))) { const long b = intval; long x; long a = PyInt_AS_LONG(op1); x = (long)((unsigned long)a - b); if (likely((x^a) >= 0 || (x^~b) >= 0)) return PyInt_FromLong(x); return PyLong_Type.tp_as_number->nb_subtract(op1, op2); } #endif #if CYTHON_USE_PYLONG_INTERNALS if (likely(PyLong_CheckExact(op1))) { const long b = intval; long a, x; #ifdef HAVE_LONG_LONG const PY_LONG_LONG llb = intval; PY_LONG_LONG lla, llx; #endif const digit* digits = ((PyLongObject*)op1)->ob_digit; const Py_ssize_t size = Py_SIZE(op1); if (likely(__Pyx_sst_abs(size) <= 1)) { a = likely(size) ? digits[0] : 0; if (size == -1) a = -a; } else { switch (size) { case -2: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; #endif } CYTHON_FALLTHROUGH; case 2: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; #endif } CYTHON_FALLTHROUGH; case -3: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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])); goto long_long; #endif } CYTHON_FALLTHROUGH; case 3: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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])); goto long_long; #endif } CYTHON_FALLTHROUGH; case -4: if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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])); goto long_long; #endif } CYTHON_FALLTHROUGH; case 4: if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; #ifdef HAVE_LONG_LONG } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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])); goto long_long; #endif } CYTHON_FALLTHROUGH; default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2); } } x = a - b; return PyLong_FromLong(x); #ifdef HAVE_LONG_LONG long_long: llx = lla - llb; return PyLong_FromLongLong(llx); #endif } #endif if (PyFloat_CheckExact(op1)) { const long b = intval; double a = PyFloat_AS_DOUBLE(op1); double result; PyFPE_START_PROTECT("subtract", return NULL) result = ((double)a) - (double)b; PyFPE_END_PROTECT(result) return PyFloat_FromDouble(result); } return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2); } #endif /* TypeImport */ #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) goto bad; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; #endif if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { PyOS_snprintf(warning, sizeof(warning), "%s.%s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; } return (PyTypeObject *)result; bad: Py_XDECREF(result); return NULL; } #endif /* Import */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; #if PY_MAJOR_VERSION < 3 PyObject *py_import; py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) { module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; } #endif if (!module) { #if PY_MAJOR_VERSION < 3 PyObject *py_level = PyInt_FromLong(level); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, level); #endif } } bad: #if PY_MAJOR_VERSION < 3 Py_XDECREF(py_import); #endif Py_XDECREF(empty_list); Py_XDECREF(empty_dict); return module; } /* ImportFrom */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_ImportError, #if PY_MAJOR_VERSION < 3 "cannot import name %.230s", PyString_AS_STRING(name)); #else "cannot import name %S", name); #endif } return value; } /* PyDictVersioning */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { PyObject *dict = Py_TYPE(obj)->tp_dict; return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; } static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { PyObject **dictptr = NULL; Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; if (offset) { #if CYTHON_COMPILING_IN_CPYTHON dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); #else dictptr = _PyObject_GetDictPtr(obj); #endif } return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; } static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { PyObject *dict = Py_TYPE(obj)->tp_dict; if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) return 0; return obj_dict_version == __Pyx_get_object_dict_version(obj); } #endif /* GetModuleGlobalName */ #if CYTHON_USE_DICT_VERSIONS static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) #else static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) #endif { PyObject *result; #if !CYTHON_AVOID_BORROWED_REFS #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } else if (unlikely(PyErr_Occurred())) { return NULL; } #else result = PyDict_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } #endif #else result = PyObject_GetItem(__pyx_d, name); __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { return __Pyx_NewRef(result); } PyErr_Clear(); #endif return __Pyx_GetBuiltinName(name); } /* PyErrFetchRestore */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #endif /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON PyObject **cython_runtime_dict; #endif if (unlikely(!__pyx_cython_runtime)) { return c_line; } __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); #if CYTHON_COMPILING_IN_CPYTHON cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); if (likely(cython_runtime_dict)) { __PYX_PY_DICT_LOOKUP_IF_MODIFIED( use_cline, *cython_runtime_dict, __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) } else #endif { PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); if (use_cline_obj) { use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; Py_DECREF(use_cline_obj); } else { PyErr_Clear(); use_cline = NULL; } } if (!use_cline) { c_line = 0; PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); } else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { c_line = 0; } __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); return c_line; } #endif /* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = start + (end - start) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } /* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; PyThreadState *tstate = __Pyx_PyThreadState_Current; if (c_line) { c_line = __Pyx_CLineForTraceback(tstate, c_line); } py_code = __pyx_find_code_object(c_line ? -c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); } py_frame = PyFrame_New( tstate, /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; __Pyx_PyFrame_SetLineNumber(py_frame, py_line); PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } /* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ {\ func_type value = func_value;\ if (sizeof(target_type) < sizeof(func_type)) {\ if (unlikely(value != (func_type) (target_type) value)) {\ func_type zero = 0;\ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ return (target_type) -1;\ if (is_unsigned && unlikely(value < zero))\ goto raise_neg_overflow;\ else\ goto raise_overflow;\ }\ }\ return (target_type) value;\ } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) { 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; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) { 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; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (unsigned PY_LONG_LONG) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0]) case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) { 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])); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) { 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])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (unsigned PY_LONG_LONG) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, +digits[0]) case -2: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case -3: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case -4: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else unsigned PY_LONG_LONG val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (unsigned PY_LONG_LONG) -1; } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (unsigned PY_LONG_LONG) -1; val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (long) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -3: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -4: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; } #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (int) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -3: if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -4: if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; } #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } /* FastTypeChecks */ #if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; if (a == b) return 1; } return b == &PyBaseObject_Type; } static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { PyObject *mro; if (a == b) return 1; mro = a->tp_mro; if (likely(mro)) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(mro); for (i = 0; i < n; i++) { if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) return 1; } return 0; } return __Pyx_InBases(a, b); } #if PY_MAJOR_VERSION == 2 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { PyObject *exception, *value, *tb; int res; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&exception, &value, &tb); res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } if (!res) { res = PyObject_IsSubclass(err, exc_type2); if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } } __Pyx_ErrRestore(exception, value, tb); return res; } #else static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; if (!res) { res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); } return res; } #endif static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; assert(PyExceptionClass_Check(exc_type)); n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; ip) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; if (PyObject_Hash(*t->p) == -1) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT #if !CYTHON_PEP393_ENABLED static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; } #else static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (likely(PyUnicode_IS_ASCII(o))) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif } #endif #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { return __Pyx_PyUnicode_AsStringAndSize(o, length); } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { int retval; if (unlikely(!x)) return -1; retval = __Pyx_PyObject_IsTrue(x); Py_DECREF(x); return retval; } static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(result)) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "__int__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } return result; } #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", type_name, type_name, Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { #if CYTHON_USE_TYPE_SLOTS PyNumberMethods *m; #endif const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x) || PyLong_Check(x))) #else if (likely(PyLong_Check(x))) #endif return __Pyx_NewRef(x); #if CYTHON_USE_TYPE_SLOTS m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = m->nb_int(x); } else if (m && m->nb_long) { name = "long"; res = m->nb_long(x); } #else if (likely(m && m->nb_int)) { name = "int"; res = m->nb_int(x); } #endif #else if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { res = PyNumber_Int(x); } #endif if (likely(res)) { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { #else if (unlikely(!PyLong_CheckExact(res))) { #endif return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)b)->ob_digit; const Py_ssize_t size = Py_SIZE(b); if (likely(__Pyx_sst_abs(size) <= 1)) { ival = likely(size) ? digits[0] : 0; if (size == -1) ival = -ival; return ival; } else { switch (size) { case 2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; case -4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; } } #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ python-clickhouse-driver-0.2.3/clickhouse_driver/columns/largeint.pyx000066400000000000000000000136761420676740400262370ustar00rootroot00000000000000from cpython cimport Py_INCREF from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM from .. import writer cdef object MAX_UINT64 = writer.MAX_UINT64 cdef object MAX_INT64 = writer.MAX_INT64 def int128_from_quads(quad_items, unsigned long long n_items): cdef unsigned int factor = 2 items = PyTuple_New(n_items) cdef unsigned long long i, ix cdef object item for i in range(n_items): ix = factor * i if quad_items[ix + 1] > MAX_INT64: item = ( -((MAX_UINT64 - quad_items[ix + 1]) << 64) - (MAX_UINT64 - quad_items[ix]) - 1 ) else: item = (quad_items[ix + 1] << 64) + quad_items[ix] Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) return items def int128_to_quads(items, unsigned long long n_items): cdef unsigned int factor = 2 quad_items = PyTuple_New(n_items * factor) cdef unsigned long long i, ix cdef object x, item for i in range(n_items): ix = factor * i x = items[i] if x < 0: x = -x - 1 item = MAX_UINT64 - x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = MAX_UINT64 - (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) else: item = x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) return quad_items def uint128_from_quads(quad_items, unsigned long long n_items): cdef unsigned int factor = 2 items = PyTuple_New(n_items) cdef unsigned long long i, ix cdef object item for i in range(n_items): ix = factor * i item = (quad_items[ix + 1] << 64) + quad_items[ix] Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) return items def uint128_to_quads(items, unsigned long long n_items): cdef unsigned int factor = 2 quad_items = PyTuple_New(n_items * factor) cdef unsigned long long i, ix cdef object x, item for i in range(n_items): ix = factor * i x = items[i] item = x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) return quad_items # 256 bits def int256_from_quads(quad_items, unsigned long long n_items): cdef unsigned int factor = 4 items = PyTuple_New(n_items) cdef unsigned long long i, ix cdef object item for i in range(n_items): ix = factor * i if quad_items[ix + 3] > MAX_INT64: item = ( -((MAX_UINT64 - quad_items[ix + 3]) << 192) -((MAX_UINT64 - quad_items[ix + 2]) << 128) -((MAX_UINT64 - quad_items[ix + 1]) << 64) - (MAX_UINT64 - quad_items[ix]) - 1 ) else: item = ( (quad_items[ix + 3] << 192) + (quad_items[ix + 2] << 128) + (quad_items[ix + 1] << 64) + quad_items[ix] ) Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) return items def int256_to_quads(items, unsigned long long n_items): cdef unsigned int factor = 4 quad_items = PyTuple_New(n_items * factor) cdef unsigned long long i, ix cdef object x, item for i in range(n_items): ix = factor * i x = items[i] if x < 0: x = -x - 1 item = MAX_UINT64 - x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = MAX_UINT64 - (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) item = MAX_UINT64 - (x >> 128) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 2, item) item = MAX_UINT64 - (x >> 192) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 3, item) else: item = x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) item = (x >> 128) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 2, item) item = (x >> 192) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 3, item) return quad_items def uint256_from_quads(quad_items, unsigned long long n_items): cdef unsigned int factor = 4 items = PyTuple_New(n_items) cdef unsigned long long i, ix cdef object item for i in range(n_items): ix = factor * i item = ( (quad_items[ix + 3] << 192) + (quad_items[ix + 2] << 128) + (quad_items[ix + 1] << 64) + quad_items[ix] ) Py_INCREF(item) PyTuple_SET_ITEM(items, i, item) return items def uint256_to_quads(items, unsigned long long n_items): cdef unsigned int factor = 4 quad_items = PyTuple_New(n_items * factor) cdef unsigned long long i, ix cdef object x, item for i in range(n_items): ix = factor * i x = items[i] item = x & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix, item) item = (x >> 64) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 1, item) item = (x >> 128) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 2, item) item = (x >> 192) & MAX_UINT64 Py_INCREF(item) PyTuple_SET_ITEM(quad_items, ix + 3, item) return quad_items python-clickhouse-driver-0.2.3/clickhouse_driver/columns/lowcardinalitycolumn.py000066400000000000000000000076501420676740400305000ustar00rootroot00000000000000from math import log from ..reader import read_binary_uint64 from ..writer import write_binary_int64 from .base import Column from .intcolumn import UInt8Column, UInt16Column, UInt32Column, UInt64Column def create_low_cardinality_column(spec, column_by_spec_getter): inner = spec[15:-1] nested = column_by_spec_getter(inner) return LowCardinalityColumn(nested) class LowCardinalityColumn(Column): """ Stores column as index (unique elements) and keys. Good for de-duplication of large values with low cardinality. """ int_types = { 0: UInt8Column, 1: UInt16Column, 2: UInt32Column, 3: UInt64Column } # Need to read additional keys. # Additional keys are stored before indexes as value N and N keys # after them. has_additional_keys_bit = 1 << 9 # Need to update dictionary. # It means that previous granule has different dictionary. need_update_dictionary = 1 << 10 serialization_type = has_additional_keys_bit | need_update_dictionary def __init__(self, nested_column, **kwargs): self.nested_column = nested_column super(LowCardinalityColumn, self).__init__(**kwargs) def read_state_prefix(self, buf): return read_binary_uint64(buf) def write_state_prefix(self, buf): # KeysSerializationVersion. See ClickHouse docs. write_binary_int64(1, buf) def _write_data(self, items, buf): index, keys = [], [] key_by_index_element = {} if self.nested_column.nullable: # First element represents NULL if column is nullable. index.append(self.nested_column.null_value) # Prevent null map writing. Reset nested column nullable flag. self.nested_column.nullable = False for x in items: if x is None: # Zero element for null. keys.append(0) else: key = key_by_index_element.get(x) # Get key from index or add it to index. if key is None: key = len(key_by_index_element) key_by_index_element[x] = key index.append(x) keys.append(key + 1) else: for x in items: key = key_by_index_element.get(x) # Get key from index or add it to index. if key is None: key = len(key_by_index_element) key_by_index_element[x] = len(key_by_index_element) index.append(x) keys.append(key) # Do not write anything for empty column. # May happen while writing empty arrays. if not len(index): return int_type = int(log(len(index), 2) / 8) int_column = self.int_types[int_type]() serialization_type = self.serialization_type | int_type write_binary_int64(serialization_type, buf) write_binary_int64(len(index), buf) self.nested_column.write_data(index, buf) write_binary_int64(len(items), buf) int_column.write_items(keys, buf) def _read_data(self, n_items, buf, nulls_map=None): if not n_items: return tuple() serialization_type = read_binary_uint64(buf) # Lowest byte contains info about key type. key_type = serialization_type & 0xf keys_column = self.int_types[key_type]() nullable = self.nested_column.nullable # Prevent null map reading. Reset nested column nullable flag. self.nested_column.nullable = False index_size = read_binary_uint64(buf) index = self.nested_column.read_data(index_size, buf) if nullable: index = (None, ) + index[1:] read_binary_uint64(buf) # number of keys keys = keys_column.read_data(n_items, buf) return tuple(index[x] for x in keys) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/mapcolumn.py000066400000000000000000000033361420676740400262250ustar00rootroot00000000000000from .base import Column from .intcolumn import UInt64Column from ..util.helpers import pairwise class MapColumn(Column): py_types = (dict, ) def __init__(self, key_column, value_column, **kwargs): self.offset_column = UInt64Column() self.key_column = key_column self.value_column = value_column super(MapColumn, self).__init__(**kwargs) def read_state_prefix(self, buf): self.key_column.read_state_prefix(buf) self.value_column.read_state_prefix(buf) def write_state_prefix(self, buf): self.key_column.write_state_prefix(buf) self.value_column.write_state_prefix(buf) def read_items(self, n_items, buf): offsets = list(self.offset_column.read_items(n_items, buf)) last_offset = offsets[-1] keys = self.key_column.read_data(last_offset, buf) values = self.value_column.read_data(last_offset, buf) offsets.insert(0, 0) return [ dict(zip(keys[begin:end], values[begin:end])) for begin, end in pairwise(offsets) ] def write_items(self, items, buf): offsets = [] keys = [] values = [] total = 0 for x in items: total += len(x) offsets.append(total) keys.extend(x.keys()) values.extend(x.values()) self.offset_column.write_items(offsets, buf) self.key_column.write_data(keys, buf) self.value_column.write_data(values, buf) def create_map_column(spec, column_by_spec_getter): key, value = spec[4:-1].split(',') key_column = column_by_spec_getter(key.strip()) value_column = column_by_spec_getter(value.strip()) return MapColumn(key_column, value_column) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/nestedcolumn.py000066400000000000000000000034101420676740400267230ustar00rootroot00000000000000 from .arraycolumn import create_array_column def create_nested_column(spec, column_by_spec_getter): return create_array_column( 'Array(Tuple({}))'.format(','.join(get_nested_columns(spec))), column_by_spec_getter=column_by_spec_getter ) def get_nested_columns(spec): brackets = 0 column_begin = 0 inner_spec = get_inner_spec(spec) nested_columns = [] for i, x in enumerate(inner_spec + ','): if x == ',': if brackets == 0: nested_columns.append(inner_spec[column_begin:i]) column_begin = i + 1 elif x == '(': brackets += 1 elif x == ')': brackets -= 1 elif x == ' ': if brackets == 0: column_begin = i + 1 return nested_columns def get_columns_with_types(spec): brackets = 0 prev_comma = 0 prev_space = 0 inner_spec = get_inner_spec(spec) columns_with_types = [] for i, x in enumerate(inner_spec + ','): if x == ',': if brackets == 0: columns_with_types.append(( inner_spec[prev_comma:prev_space].strip(), inner_spec[prev_space:i] )) prev_comma = i + 1 elif x == '(': brackets += 1 elif x == ')': brackets -= 1 elif x == ' ': if brackets == 0: prev_space = i + 1 return columns_with_types def get_inner_spec(spec): brackets = 0 offset = len('Nested') i = offset for i, ch in enumerate(spec[offset:], offset): if ch == '(': brackets += 1 elif ch == ')': brackets -= 1 if brackets == 0: break return spec[offset + 1:i] python-clickhouse-driver-0.2.3/clickhouse_driver/columns/nothingcolumn.py000066400000000000000000000004031420676740400271060ustar00rootroot00000000000000from .intcolumn import FormatColumn class NothingColumn(FormatColumn): ch_type = 'Nothing' format = 'B' @property def size(self): return 1 def after_read_items(self, items, nulls_map=None): return (None, ) * len(items) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/nullablecolumn.py000066400000000000000000000002511420676740400272370ustar00rootroot00000000000000 def create_nullable_column(spec, column_by_spec_getter): inner = spec[9:-1] nested = column_by_spec_getter(inner) nested.nullable = True return nested python-clickhouse-driver-0.2.3/clickhouse_driver/columns/nullcolumn.py000066400000000000000000000005131420676740400264140ustar00rootroot00000000000000from .intcolumn import FormatColumn # TODO: Drop Null column support in future. # Compatibility with old servers. class NullColumn(FormatColumn): ch_type = 'Null' format = 'B' @property def size(self): return 1 def after_read_items(self, items, nulls_map=None): return (None, ) * len(items) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/000077500000000000000000000000001420676740400250235ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/__init__.py000066400000000000000000000000001420676740400271220ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/base.py000066400000000000000000000026021420676740400263070ustar00rootroot00000000000000import numpy as np import pandas as pd from ..base import Column class NumpyColumn(Column): dtype = None normalize_null_value = True def read_items(self, n_items, buf): data = buf.read(n_items * self.dtype.itemsize) return np.frombuffer(data, self.dtype.newbyteorder('<'), n_items) def write_items(self, items, buf): buf.write(items.astype(self.dtype.newbyteorder('<')).tobytes()) def _write_nulls_map(self, items, buf): s = self.make_null_struct(len(items)) nulls_map = self._get_nulls_map(items) buf.write(s.pack(*nulls_map)) def _get_nulls_map(self, items): return [bool(x) for x in pd.isnull(items)] def _read_data(self, n_items, buf, nulls_map=None): items = self.read_items(n_items, buf) if self.after_read_items: return self.after_read_items(items, nulls_map) elif nulls_map is not None: items = np.array(items, dtype=object) np.place(items, nulls_map, None) return items def prepare_items(self, items): nulls_map = pd.isnull(items) # Always replace null values to null_value for proper inserts into # non-nullable columns. if isinstance(items, np.ndarray) and self.normalize_null_value: items = np.array(items) np.place(items, nulls_map, self.null_value) return items python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/datecolumn.py000066400000000000000000000007421420676740400275330ustar00rootroot00000000000000import numpy as np from .base import NumpyColumn class NumpyDateColumn(NumpyColumn): dtype = np.dtype(np.uint16) ch_type = 'Date' null_value = np.datetime64(0, 'Y') def read_items(self, n_items, buf): data = super(NumpyDateColumn, self).read_items(n_items, buf) return data.astype('datetime64[D]') def write_items(self, items, buf): super(NumpyDateColumn, self).write_items( items.astype('datetime64[D]'), buf ) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/datetimecolumn.py000066400000000000000000000110021420676740400304010ustar00rootroot00000000000000import numpy as np import pandas as pd from pytz import timezone as get_timezone from .base import NumpyColumn from ...util.compat import get_localzone_name_compat class NumpyDateTimeColumnBase(NumpyColumn): datetime_dtype = None null_value = np.datetime64(0, 'Y') def __init__(self, timezone=None, offset_naive=True, local_timezone=None, **kwargs): self.timezone = timezone self.offset_naive = offset_naive self.local_timezone = local_timezone super(NumpyDateTimeColumnBase, self).__init__(**kwargs) def apply_timezones_after_read(self, dt): timezone = self.timezone if self.timezone else self.local_timezone ts = pd.to_datetime(dt, utc=True).tz_convert(timezone) if self.offset_naive: ts = ts.tz_localize(None) return ts.to_numpy(self.datetime_dtype) def apply_timezones_before_write(self, items): if isinstance(items, pd.DatetimeIndex): ts = items else: timezone = self.timezone if self.timezone else self.local_timezone ts = pd.to_datetime(items).tz_localize(timezone) ts = ts.tz_convert('UTC') return ts.tz_localize(None).to_numpy(self.datetime_dtype) def is_items_integer(self, items): return ( isinstance(items, np.ndarray) and np.issubdtype(items.dtype, np.integer) ) class NumpyDateTimeColumn(NumpyDateTimeColumnBase): dtype = np.dtype(np.uint32) datetime_dtype = 'datetime64[s]' def write_items(self, items, buf): # write int 'as is'. if self.is_items_integer(items): super(NumpyDateTimeColumn, self).write_items(items, buf) return items = self.apply_timezones_before_write(items) super(NumpyDateTimeColumn, self).write_items(items, buf) def read_items(self, n_items, buf): items = super(NumpyDateTimeColumn, self).read_items(n_items, buf) return self.apply_timezones_after_read(items.astype('datetime64[s]')) class NumpyDateTime64Column(NumpyDateTimeColumnBase): dtype = np.dtype(np.uint64) datetime_dtype = 'datetime64[ns]' max_scale = 6 def __init__(self, scale=0, **kwargs): self.scale = scale super(NumpyDateTime64Column, self).__init__(**kwargs) def read_items(self, n_items, buf): scale = 10 ** self.scale frac_scale = 10 ** (self.max_scale - self.scale) items = super(NumpyDateTime64Column, self).read_items(n_items, buf) seconds = (items // scale).astype('datetime64[s]') microseconds = ((items % scale) * frac_scale).astype('timedelta64[us]') dt = seconds + microseconds return self.apply_timezones_after_read(dt) def write_items(self, items, buf): # write int 'as is'. if self.is_items_integer(items): super(NumpyDateTime64Column, self).write_items(items, buf) return scale = 10 ** self.scale frac_scale = 10 ** (self.max_scale - self.scale) items = self.apply_timezones_before_write(items) seconds = items.astype('datetime64[s]') microseconds = (items - seconds).astype(dtype='timedelta64[us]') \ .astype(np.uint32) // frac_scale items = seconds.astype(self.dtype) * scale + microseconds super(NumpyDateTime64Column, self).write_items(items, buf) def create_numpy_datetime_column(spec, column_options): if spec.startswith('DateTime64'): cls = NumpyDateTime64Column spec = spec[11:-1] params = spec.split(',', 1) column_options['scale'] = int(params[0]) if len(params) > 1: spec = params[1].strip() + ')' else: cls = NumpyDateTimeColumn spec = spec[9:] context = column_options['context'] tz_name = timezone = None offset_naive = True # As Numpy do not use local timezone for converting timestamp to # datetime we need always detect local timezone for manual converting. local_timezone = get_localzone_name_compat() # Use column's timezone if it's specified. if spec and spec[-1] == ')': tz_name = spec[1:-2] offset_naive = False else: if not context.settings.get('use_client_time_zone', False): if local_timezone != context.server_info.timezone: tz_name = context.server_info.timezone if tz_name: timezone = get_timezone(tz_name) return cls(timezone=timezone, offset_naive=offset_naive, local_timezone=local_timezone, **column_options) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/floatcolumn.py000066400000000000000000000011271420676740400277210ustar00rootroot00000000000000import numpy as np from .base import NumpyColumn # normalize_null_value = False due to float('nan') # With normalization pandas.isnull will threat float('nan') as NULL value. class NumpyFloat32Column(NumpyColumn): dtype = np.dtype(np.float32) ch_type = 'Float32' normalize_null_value = False def _get_nulls_map(self, items): return [x is None for x in items] class NumpyFloat64Column(NumpyColumn): dtype = np.dtype(np.float64) ch_type = 'Float64' normalize_null_value = False def _get_nulls_map(self, items): return [x is None for x in items] python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/intcolumn.py000066400000000000000000000014301420676740400274030ustar00rootroot00000000000000import numpy as np from .base import NumpyColumn class NumpyInt8Column(NumpyColumn): dtype = np.dtype(np.int8) ch_type = 'Int8' class NumpyUInt8Column(NumpyColumn): dtype = np.dtype(np.uint8) ch_type = 'UInt8' class NumpyInt16Column(NumpyColumn): dtype = np.dtype(np.int16) ch_type = 'Int16' class NumpyUInt16Column(NumpyColumn): dtype = np.dtype(np.uint16) ch_type = 'UInt16' class NumpyInt32Column(NumpyColumn): dtype = np.dtype(np.int32) ch_type = 'Int32' class NumpyUInt32Column(NumpyColumn): dtype = np.dtype(np.uint32) ch_type = 'UInt32' class NumpyInt64Column(NumpyColumn): dtype = np.dtype(np.int64) ch_type = 'Int64' class NumpyUInt64Column(NumpyColumn): dtype = np.dtype(np.uint64) ch_type = 'UInt64' python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/lowcardinalitycolumn.py000066400000000000000000000062721420676740400316470ustar00rootroot00000000000000from math import log import numpy as np import pandas as pd from ..lowcardinalitycolumn import LowCardinalityColumn from ...reader import read_binary_uint64 from ...writer import write_binary_int64 from .intcolumn import ( NumpyUInt8Column, NumpyUInt16Column, NumpyUInt32Column, NumpyUInt64Column ) class NumpyLowCardinalityColumn(LowCardinalityColumn): int_types = { 0: NumpyUInt8Column, 1: NumpyUInt16Column, 2: NumpyUInt32Column, 3: NumpyUInt64Column } def __init__(self, nested_column, **kwargs): super(NumpyLowCardinalityColumn, self).__init__(nested_column, **kwargs) def _write_data(self, items, buf): # Do not write anything for empty column. # May happen while writing empty arrays. if not len(items): return # Replace nans with defaults if not nullabe. if isinstance(items, np.ndarray) and not self.nested_column.nullable: nulls = pd.isnull(items) items = np.where(nulls, self.nested_column.null_value, items) c = pd.Categorical(items) int_type = int(log(len(c.codes), 2) / 8) int_column = self.int_types[int_type]() serialization_type = self.serialization_type | int_type index = c.categories keys = c.codes if self.nested_column.nullable: # First element represents NULL if column is nullable. index = index.insert(0, self.nested_column.null_value) keys = keys + 1 # Prevent null map writing. Reset nested column nullable flag. self.nested_column.nullable = False write_binary_int64(serialization_type, buf) write_binary_int64(len(index), buf) self.nested_column.write_data(index.to_numpy(items.dtype), buf) write_binary_int64(len(items), buf) int_column.write_items(keys, buf) def _read_data(self, n_items, buf, nulls_map=None): if not n_items: return tuple() serialization_type = read_binary_uint64(buf) # Lowest byte contains info about key type. key_type = serialization_type & 0xf keys_column = self.int_types[key_type]() nullable = self.nested_column.nullable # Prevent null map reading. Reset nested column nullable flag. self.nested_column.nullable = False index_size = read_binary_uint64(buf) index = self.nested_column.read_data(index_size, buf) read_binary_uint64(buf) # number of keys keys = keys_column.read_data(n_items, buf) if nullable: # Shift all codes by one ("No value" code is -1 for pandas # categorical) and drop corresponding first index # this is analog of original operation: # index = (None, ) + index[1:] keys = np.array(keys, dtype='int64') # deal with possible overflow keys = keys - 1 index = index[1:] return pd.Categorical.from_codes(keys, index) def create_numpy_low_cardinality_column(spec, column_by_spec_getter): inner = spec[15:-1] nested = column_by_spec_getter(inner) return NumpyLowCardinalityColumn(nested) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/service.py000066400000000000000000000031741420676740400270420ustar00rootroot00000000000000from ... import errors from .datecolumn import NumpyDateColumn from .datetimecolumn import create_numpy_datetime_column from .floatcolumn import NumpyFloat32Column, NumpyFloat64Column from .intcolumn import ( NumpyInt8Column, NumpyInt16Column, NumpyInt32Column, NumpyInt64Column, NumpyUInt8Column, NumpyUInt16Column, NumpyUInt32Column, NumpyUInt64Column ) from .lowcardinalitycolumn import create_numpy_low_cardinality_column from .stringcolumn import create_string_column from ..nullablecolumn import create_nullable_column column_by_type = {c.ch_type: c for c in [ NumpyDateColumn, NumpyFloat32Column, NumpyFloat64Column, NumpyInt8Column, NumpyInt16Column, NumpyInt32Column, NumpyInt64Column, NumpyUInt8Column, NumpyUInt16Column, NumpyUInt32Column, NumpyUInt64Column ]} def get_numpy_column_by_spec(spec, column_options): def create_column_with_options(x): return get_numpy_column_by_spec(x, column_options) if spec == 'String' or spec.startswith('FixedString'): return create_string_column(spec, column_options) elif spec.startswith('DateTime'): return create_numpy_datetime_column(spec, column_options) elif spec.startswith('Nullable'): return create_nullable_column(spec, create_column_with_options) elif spec.startswith('LowCardinality'): return create_numpy_low_cardinality_column(spec, create_column_with_options) else: if spec in column_by_type: cls = column_by_type[spec] return cls(**column_options) raise errors.UnknownTypeError('Unknown type {}'.format(spec)) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/numpy/stringcolumn.py000066400000000000000000000046071420676740400301300ustar00rootroot00000000000000import numpy as np from ... import defines from .base import NumpyColumn class NumpyStringColumn(NumpyColumn): null_value = '' default_encoding = defines.STRINGS_ENCODING def __init__(self, encoding=default_encoding, **kwargs): self.encoding = encoding super(NumpyStringColumn, self).__init__(**kwargs) def read_items(self, n_items, buf): return np.array( buf.read_strings(n_items, encoding=self.encoding), dtype=self.dtype ) def write_items(self, items, buf): return buf.write_strings(items.tolist(), encoding=self.encoding) class NumpyByteStringColumn(NumpyColumn): null_value = b'' def read_items(self, n_items, buf): return np.array(buf.read_strings(n_items), dtype=self.dtype) def write_items(self, items, buf): return buf.write_strings(items.tolist()) class NumpyFixedString(NumpyStringColumn): def __init__(self, length, **kwargs): self.length = length super(NumpyFixedString, self).__init__(**kwargs) def read_items(self, n_items, buf): return np.array(buf.read_fixed_strings( n_items, self.length, encoding=self.encoding ), dtype=self.dtype) def write_items(self, items, buf): return buf.write_fixed_strings( items.tolist(), self.length, encoding=self.encoding ) class NumpyByteFixedString(NumpyByteStringColumn): def __init__(self, length, **kwargs): self.length = length super(NumpyByteFixedString, self).__init__(**kwargs) def read_items(self, n_items, buf): return np.array( buf.read_fixed_strings(n_items, self.length), dtype=self.dtype ) def write_items(self, items, buf): return buf.write_fixed_strings(items.tolist(), self.length) def create_string_column(spec, column_options): client_settings = column_options['context'].client_settings strings_as_bytes = client_settings['strings_as_bytes'] encoding = client_settings.get( 'strings_encoding', NumpyStringColumn.default_encoding ) if spec == 'String': cls = NumpyByteStringColumn if strings_as_bytes else NumpyStringColumn return cls(encoding=encoding, **column_options) else: length = int(spec[12:-1]) cls = NumpyByteFixedString if strings_as_bytes else NumpyFixedString return cls(length, encoding=encoding, **column_options) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/service.py000066400000000000000000000121631420676740400256700ustar00rootroot00000000000000import logging from .. import errors from .arraycolumn import create_array_column from .boolcolumn import BoolColumn from .datecolumn import DateColumn, Date32Column from .datetimecolumn import create_datetime_column from .decimalcolumn import create_decimal_column from . import exceptions as column_exceptions from .enumcolumn import create_enum_column from .floatcolumn import Float32Column, Float64Column from .intcolumn import ( Int8Column, Int16Column, Int32Column, Int64Column, Int128Column, UInt128Column, Int256Column, UInt256Column, UInt8Column, UInt16Column, UInt32Column, UInt64Column ) from .lowcardinalitycolumn import create_low_cardinality_column from .mapcolumn import create_map_column from .nothingcolumn import NothingColumn from .nullcolumn import NullColumn from .nullablecolumn import create_nullable_column from .simpleaggregatefunctioncolumn import ( create_simple_aggregate_function_column ) from .stringcolumn import create_string_column from .tuplecolumn import create_tuple_column from .nestedcolumn import create_nested_column from .uuidcolumn import UUIDColumn from .intervalcolumn import ( IntervalYearColumn, IntervalMonthColumn, IntervalWeekColumn, IntervalDayColumn, IntervalHourColumn, IntervalMinuteColumn, IntervalSecondColumn ) from .ipcolumn import IPv4Column, IPv6Column column_by_type = {c.ch_type: c for c in [ DateColumn, Date32Column, Float32Column, Float64Column, Int8Column, Int16Column, Int32Column, Int64Column, Int128Column, UInt128Column, Int256Column, UInt256Column, UInt8Column, UInt16Column, UInt32Column, UInt64Column, NothingColumn, NullColumn, UUIDColumn, IntervalYearColumn, IntervalMonthColumn, IntervalWeekColumn, IntervalDayColumn, IntervalHourColumn, IntervalMinuteColumn, IntervalSecondColumn, IPv4Column, IPv6Column, BoolColumn ]} logger = logging.getLogger(__name__) def get_column_by_spec(spec, column_options, use_numpy=None): context = column_options['context'] if use_numpy is None: use_numpy = context.client_settings['use_numpy'] if context else False if use_numpy: from .numpy.service import get_numpy_column_by_spec try: return get_numpy_column_by_spec(spec, column_options) except errors.UnknownTypeError: use_numpy = False logger.warning('NumPy support is not implemented for %s. ' 'Using generic column', spec) def create_column_with_options(x): return get_column_by_spec(x, column_options, use_numpy=use_numpy) if spec == 'String' or spec.startswith('FixedString'): return create_string_column(spec, column_options) elif spec.startswith('Enum'): return create_enum_column(spec, column_options) elif spec.startswith('DateTime'): return create_datetime_column(spec, column_options) elif spec.startswith('Decimal'): return create_decimal_column(spec, column_options) elif spec.startswith('Array'): return create_array_column(spec, create_column_with_options) elif spec.startswith('Tuple'): return create_tuple_column(spec, create_column_with_options) elif spec.startswith('Nested'): return create_nested_column(spec, create_column_with_options) elif spec.startswith('Nullable'): return create_nullable_column(spec, create_column_with_options) elif spec.startswith('LowCardinality'): return create_low_cardinality_column(spec, create_column_with_options) elif spec.startswith('SimpleAggregateFunction'): return create_simple_aggregate_function_column( spec, create_column_with_options) elif spec.startswith('Map'): return create_map_column(spec, create_column_with_options) else: try: cls = column_by_type[spec] return cls(**column_options) except KeyError: raise errors.UnknownTypeError('Unknown type {}'.format(spec)) def read_column(context, column_spec, n_items, buf): column_options = {'context': context} column = get_column_by_spec(column_spec, column_options) column.read_state_prefix(buf) return column.read_data(n_items, buf) def write_column(context, column_name, column_spec, items, buf, types_check=False): column_options = { 'context': context, 'types_check': types_check } column = get_column_by_spec(column_spec, column_options) try: column.write_state_prefix(buf) column.write_data(items, buf) except column_exceptions.ColumnTypeMismatchException as e: raise errors.TypeMismatchError( 'Type mismatch in VALUES section. ' 'Expected {} got {}: {} for column "{}".'.format( column_spec, type(e.args[0]), e.args[0], column_name ) ) except (column_exceptions.StructPackException, OverflowError) as e: error = e.args[0] raise errors.TypeMismatchError( 'Type mismatch in VALUES section. ' 'Repeat query with types_check=True for detailed info. ' 'Column {}: {}'.format( column_name, str(error) ) ) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/simpleaggregatefunctioncolumn.py000066400000000000000000000003531420676740400323520ustar00rootroot00000000000000 def create_simple_aggregate_function_column(spec, column_by_spec_getter): # SimpleAggregateFunction(Func, Type) -> Type inner = spec[24:-1].split(',', 1)[1].strip() nested = column_by_spec_getter(inner) return nested python-clickhouse-driver-0.2.3/clickhouse_driver/columns/stringcolumn.py000066400000000000000000000040131420676740400267470ustar00rootroot00000000000000 from .. import defines from .base import Column class String(Column): ch_type = 'String' py_types = (str, ) null_value = '' default_encoding = defines.STRINGS_ENCODING def __init__(self, encoding=default_encoding, **kwargs): self.encoding = encoding super(String, self).__init__(**kwargs) def write_items(self, items, buf): buf.write_strings(items, encoding=self.encoding) def read_items(self, n_items, buf): return buf.read_strings(n_items, encoding=self.encoding) class ByteString(String): py_types = (bytes, ) null_value = b'' def write_items(self, items, buf): buf.write_strings(items) def read_items(self, n_items, buf): return buf.read_strings(n_items) class FixedString(String): ch_type = 'FixedString' def __init__(self, length, **kwargs): self.length = length super(FixedString, self).__init__(**kwargs) def read_items(self, n_items, buf): return buf.read_fixed_strings( n_items, self.length, encoding=self.encoding ) def write_items(self, items, buf): buf.write_fixed_strings(items, self.length, encoding=self.encoding) class ByteFixedString(FixedString): py_types = (bytearray, bytes) null_value = b'' def read_items(self, n_items, buf): return buf.read_fixed_strings(n_items, self.length) def write_items(self, items, buf): buf.write_fixed_strings(items, self.length) def create_string_column(spec, column_options): client_settings = column_options['context'].client_settings strings_as_bytes = client_settings['strings_as_bytes'] encoding = client_settings.get('strings_encoding', String.default_encoding) if spec == 'String': cls = ByteString if strings_as_bytes else String return cls(encoding=encoding, **column_options) else: length = int(spec[12:-1]) cls = ByteFixedString if strings_as_bytes else FixedString return cls(length, encoding=encoding, **column_options) python-clickhouse-driver-0.2.3/clickhouse_driver/columns/tuplecolumn.py000066400000000000000000000031541420676740400265770ustar00rootroot00000000000000 from .base import Column class TupleColumn(Column): py_types = (list, tuple) def __init__(self, nested_columns, **kwargs): self.nested_columns = nested_columns super(TupleColumn, self).__init__(**kwargs) def write_data(self, items, buf): items = list(zip(*items)) for i, x in enumerate(self.nested_columns): x.write_data(list(items[i]), buf) def write_items(self, items, buf): return self.write_data(items, buf) def read_data(self, n_items, buf): rv = [x.read_data(n_items, buf) for x in self.nested_columns] return list(zip(*rv)) def read_items(self, n_items, buf): return self.read_data(n_items, buf) def create_tuple_column(spec, column_by_spec_getter): brackets = 0 column_begin = 0 inner_spec = get_inner_spec(spec) nested_columns = [] for i, x in enumerate(inner_spec + ','): if x == ',': if brackets == 0: nested_columns.append(inner_spec[column_begin:i]) column_begin = i + 1 elif x == '(': brackets += 1 elif x == ')': brackets -= 1 elif x == ' ': if brackets == 0: column_begin = i + 1 return TupleColumn([column_by_spec_getter(x) for x in nested_columns]) def get_inner_spec(spec): brackets = 0 offset = len('Tuple') i = offset for i, ch in enumerate(spec[offset:], offset): if ch == '(': brackets += 1 elif ch == ')': brackets -= 1 if brackets == 0: break return spec[offset + 1:i] python-clickhouse-driver-0.2.3/clickhouse_driver/columns/uuidcolumn.py000066400000000000000000000034371420676740400264200ustar00rootroot00000000000000from uuid import UUID from .base import FormatColumn from .. import errors from ..writer import MAX_UINT64 class UUIDColumn(FormatColumn): ch_type = 'UUID' py_types = (str, UUID) format = 'Q' # UUID is stored by two uint64 numbers. def write_items(self, items, buf): n_items = len(items) uint_64_pairs = [None] * 2 * n_items for i, x in enumerate(items): i2 = 2 * i uint_64_pairs[i2] = (x >> 64) & MAX_UINT64 uint_64_pairs[i2 + 1] = x & MAX_UINT64 s = self.make_struct(2 * n_items) buf.write(s.pack(*uint_64_pairs)) def read_items(self, n_items, buf): # TODO: cythonize s = self.make_struct(2 * n_items) items = s.unpack(buf.read(s.size)) uint_128_items = [None] * n_items for i in range(n_items): i2 = 2 * i uint_128_items[i] = (items[i2] << 64) + items[i2 + 1] return tuple(uint_128_items) def after_read_items(self, items, nulls_map=None): if nulls_map is None: return tuple(UUID(int=item) for item in items) else: return tuple( (None if is_null else UUID(int=items[i])) for i, is_null in enumerate(nulls_map) ) def before_write_items(self, items, nulls_map=None): null_value = self.null_value for i, item in enumerate(items): if nulls_map and nulls_map[i]: items[i] = null_value continue try: if not isinstance(item, UUID): item = UUID(item) except ValueError: raise errors.CannotParseUuidError( "Cannot parse uuid '{}'".format(item) ) items[i] = item.int python-clickhouse-driver-0.2.3/clickhouse_driver/compression/000077500000000000000000000000001420676740400245345ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/compression/__init__.py000066400000000000000000000013121420676740400266420ustar00rootroot00000000000000import importlib from .. import errors from ..protocol import CompressionMethodByte def get_compressor_cls(alg): try: module = importlib.import_module('.' + alg, __name__) return module.Compressor except ImportError: raise errors.UnknownCompressionMethod( "Unknown compression method: '{}'".format(alg) ) def get_decompressor_cls(method_type): if method_type == CompressionMethodByte.LZ4: module = importlib.import_module('.lz4', __name__) elif method_type == CompressionMethodByte.ZSTD: module = importlib.import_module('.zstd', __name__) else: raise errors.UnknownCompressionMethod() return module.Decompressor python-clickhouse-driver-0.2.3/clickhouse_driver/compression/base.py000066400000000000000000000046021420676740400260220ustar00rootroot00000000000000from io import BytesIO from ..reader import read_binary_uint32 from ..writer import write_binary_uint8, write_binary_uint32 from .. import errors try: from clickhouse_cityhash.cityhash import CityHash128 except ImportError: raise RuntimeError( 'Package clickhouse-cityhash is required to use compression' ) class BaseCompressor(object): """ Partial file-like object with write method. """ method = None method_byte = None def __init__(self): self.data = BytesIO() super(BaseCompressor, self).__init__() def get_value(self): value = self.data.getvalue() self.data.seek(0) self.data.truncate() return value def write(self, p_str): self.data.write(p_str) def compress_data(self, data): raise NotImplementedError def get_compressed_data(self, extra_header_size): rv = BytesIO() data = self.get_value() compressed = self.compress_data(data) header_size = extra_header_size + 4 + 4 # sizes write_binary_uint32(header_size + len(compressed), rv) write_binary_uint32(len(data), rv) rv.write(compressed) return rv.getvalue() class BaseDecompressor(object): method = None method_byte = None def __init__(self, real_stream): self.stream = real_stream super(BaseDecompressor, self).__init__() def decompress_data(self, data, uncompressed_size): raise NotImplementedError def check_hash(self, compressed_data, compressed_hash): if CityHash128(compressed_data) != compressed_hash: raise errors.ChecksumDoesntMatchError() def get_decompressed_data(self, method_byte, compressed_hash, extra_header_size): size_with_header = read_binary_uint32(self.stream) compressed_size = size_with_header - extra_header_size - 4 compressed = BytesIO(self.stream.read(compressed_size)) block_check = BytesIO() write_binary_uint8(method_byte, block_check) write_binary_uint32(size_with_header, block_check) block_check.write(compressed.getvalue()) self.check_hash(block_check.getvalue(), compressed_hash) uncompressed_size = read_binary_uint32(compressed) compressed = compressed.read(compressed_size - 4) return self.decompress_data(compressed, uncompressed_size) python-clickhouse-driver-0.2.3/clickhouse_driver/compression/lz4.py000066400000000000000000000011671420676740400256240ustar00rootroot00000000000000from lz4 import block from .base import BaseCompressor, BaseDecompressor from ..protocol import CompressionMethod, CompressionMethodByte class Compressor(BaseCompressor): method = CompressionMethod.LZ4 method_byte = CompressionMethodByte.LZ4 mode = 'default' def compress_data(self, data): return block.compress(data, store_size=False, mode=self.mode) class Decompressor(BaseDecompressor): method = CompressionMethod.LZ4 method_byte = CompressionMethodByte.LZ4 def decompress_data(self, data, uncompressed_size): return block.decompress(data, uncompressed_size=uncompressed_size) python-clickhouse-driver-0.2.3/clickhouse_driver/compression/lz4hc.py000066400000000000000000000003031420676740400261260ustar00rootroot00000000000000from .lz4 import Compressor as BaseCompressor, Decompressor as BaseDecompressor class Compressor(BaseCompressor): mode = 'high_compression' class Decompressor(BaseDecompressor): pass python-clickhouse-driver-0.2.3/clickhouse_driver/compression/zstd.py000066400000000000000000000010231420676740400260660ustar00rootroot00000000000000import zstd from .base import BaseCompressor, BaseDecompressor from ..protocol import CompressionMethod, CompressionMethodByte class Compressor(BaseCompressor): method = CompressionMethod.ZSTD method_byte = CompressionMethodByte.ZSTD def compress_data(self, data): return zstd.compress(data) class Decompressor(BaseDecompressor): method = CompressionMethod.ZSTD method_byte = CompressionMethodByte.ZSTD def decompress_data(self, data, uncompressed_size): return zstd.decompress(data) python-clickhouse-driver-0.2.3/clickhouse_driver/connection.py000066400000000000000000000552431420676740400247150ustar00rootroot00000000000000import logging import socket import ssl from collections import deque from contextlib import contextmanager from time import time from urllib.parse import urlparse from . import defines from . import errors from .block import RowOrientedBlock from .blockstreamprofileinfo import BlockStreamProfileInfo from .bufferedreader import BufferedSocketReader from .bufferedwriter import BufferedSocketWriter from .clientinfo import ClientInfo from .compression import get_compressor_cls from .context import Context from .log import log_block from .progress import Progress from .protocol import Compression, ClientPacketTypes, ServerPacketTypes from .queryprocessingstage import QueryProcessingStage from .reader import read_binary_str from .readhelpers import read_exception from .settings.writer import write_settings from .streams.native import BlockInputStream, BlockOutputStream from .util.compat import threading from .varint import write_varint, read_varint from .writer import write_binary_str logger = logging.getLogger(__name__) class Packet(object): def __init__(self): self.type = None self.block = None self.exception = None self.progress = None self.profile_info = None self.multistring_message = None super(Packet, self).__init__() class ServerInfo(object): def __init__(self, name, version_major, version_minor, version_patch, revision, timezone, display_name): self.name = name self.version_major = version_major self.version_minor = version_minor self.version_patch = version_patch self.revision = revision self.timezone = timezone self.display_name = display_name super(ServerInfo, self).__init__() def version_tuple(self): return self.version_major, self.version_minor, self.version_patch def __repr__(self): version = '%s.%s.%s' % ( self.version_major, self.version_minor, self.version_patch ) items = [ ('name', self.name), ('version', version), ('revision', self.revision), ('timezone', self.timezone), ('display_name', self.display_name) ] params = ', '.join('{}={}'.format(key, value) for key, value in items) return '' % (params) class Connection(object): """ Represents connection between client and ClickHouse server. :param host: host with running ClickHouse server. :param port: port ClickHouse server is bound to. Defaults to ``9000`` if connection is not secured and to ``9440`` if connection is secured. :param database: database connect to. Defaults to ``'default'``. :param user: database user. Defaults to ``'default'``. :param password: user's password. Defaults to ``''`` (no password). :param client_name: this name will appear in server logs. Defaults to ``'python-driver'``. :param connect_timeout: timeout for establishing connection. Defaults to ``10`` seconds. :param send_receive_timeout: timeout for sending and receiving data. Defaults to ``300`` seconds. :param sync_request_timeout: timeout for server ping. Defaults to ``5`` seconds. :param compress_block_size: size of compressed block to send. Defaults to ``1048576``. :param compression: specifies whether or not use compression. Defaults to ``False``. Possible choices: * ``True`` is equivalent to ``'lz4'``. * ``'lz4'``. * ``'lz4hc'`` high-compression variant of ``'lz4'``. * ``'zstd'``. :param secure: establish secure connection. Defaults to ``False``. :param verify: specifies whether a certificate is required and whether it will be validated after connection. Defaults to ``True``. :param ssl_version: see :func:`ssl.wrap_socket` docs. :param ca_certs: see :func:`ssl.wrap_socket` docs. :param ciphers: see :func:`ssl.wrap_socket` docs. :param keyfile: see :func:`ssl.wrap_socket` docs. :param certfile: see :func:`ssl.wrap_socket` docs. :param alt_hosts: list of alternative hosts for connection. Example: alt_hosts=host1:port1,host2:port2. :param settings_is_important: ``False`` means unknown settings will be ignored, ``True`` means that the query will fail with UNKNOWN_SETTING error. Defaults to ``False``. """ def __init__( self, host, port=None, database=defines.DEFAULT_DATABASE, user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD, client_name=defines.CLIENT_NAME, connect_timeout=defines.DBMS_DEFAULT_CONNECT_TIMEOUT_SEC, send_receive_timeout=defines.DBMS_DEFAULT_TIMEOUT_SEC, sync_request_timeout=defines.DBMS_DEFAULT_SYNC_REQUEST_TIMEOUT_SEC, compress_block_size=defines.DEFAULT_COMPRESS_BLOCK_SIZE, compression=False, secure=False, # Secure socket parameters. verify=True, ssl_version=None, ca_certs=None, ciphers=None, keyfile=None, certfile=None, alt_hosts=None, settings_is_important=False, ): if secure: default_port = defines.DEFAULT_SECURE_PORT else: default_port = defines.DEFAULT_PORT self.hosts = deque([(host, port or default_port)]) if alt_hosts: for host in alt_hosts.split(','): url = urlparse('clickhouse://' + host) self.hosts.append((url.hostname, url.port or default_port)) self.database = database self.user = user self.password = password self.client_name = defines.DBMS_NAME + ' ' + client_name self.connect_timeout = connect_timeout self.send_receive_timeout = send_receive_timeout self.sync_request_timeout = sync_request_timeout self.settings_is_important = settings_is_important self.secure_socket = secure self.verify_cert = verify ssl_options = {} if ssl_version is not None: ssl_options['ssl_version'] = ssl_version if ca_certs is not None: ssl_options['ca_certs'] = ca_certs if ciphers is not None: ssl_options['ciphers'] = ciphers if keyfile is not None: ssl_options['keyfile'] = keyfile if certfile is not None: ssl_options['certfile'] = certfile self.ssl_options = ssl_options # Use LZ4 compression by default. if compression is True: compression = 'lz4' if compression is False: self.compression = Compression.DISABLED self.compressor_cls = None self.compress_block_size = None else: self.compression = Compression.ENABLED self.compressor_cls = get_compressor_cls(compression) self.compress_block_size = compress_block_size self.socket = None self.fin = None self.fout = None self.connected = False self.client_trace_context = None self.server_info = None self.context = Context() # Block writer/reader self.block_in = None self.block_out = None self.block_in_raw = None # log blocks are always not compressed self._lock = threading.Lock() self.is_query_executing = False super(Connection, self).__init__() def get_description(self): return '{}:{}'.format(self.host, self.port) def force_connect(self): self.check_query_execution() if not self.connected: self.connect() elif not self.ping(): logger.warning('Connection was closed, reconnecting.') self.connect() def _create_socket(self, host, port): """ Acts like socket.create_connection, but wraps socket with SSL if connection is secure. """ ssl_options = {} if self.secure_socket: if self.verify_cert: cert_reqs = ssl.CERT_REQUIRED else: cert_reqs = ssl.CERT_NONE ssl_options = self.ssl_options.copy() ssl_options['cert_reqs'] = cert_reqs err = None for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res sock = None try: sock = socket.socket(af, socktype, proto) sock.settimeout(self.connect_timeout) if self.secure_socket: ssl_context = self._create_ssl_context(ssl_options) sock = ssl_context.wrap_socket(sock, server_hostname=host) sock.connect(sa) return sock except socket.error as _: err = _ if sock is not None: sock.close() if err is not None: raise err else: raise socket.error("getaddrinfo returns an empty list") def _create_ssl_context(self, ssl_options): purpose = ssl.Purpose.SERVER_AUTH version = ssl_options.get('ssl_version', ssl.PROTOCOL_TLS) context = ssl.SSLContext(version) if 'ca_certs' in ssl_options: context.load_verify_locations(ssl_options['ca_certs']) elif ssl_options.get('cert_reqs') != ssl.CERT_NONE: context.load_default_certs(purpose ) if 'ciphers' in ssl_options: context.set_ciphers(ssl_options['ciphers']) if 'cert_reqs' in ssl_options: context.options = ssl_options['cert_reqs'] if 'certfile' in ssl_options: keyfile = ssl_options.get('keyfile') context.load_cert_chain(ssl_options['certfile'], keyfile=keyfile) return context def _init_connection(self, host, port): self.socket = self._create_socket(host, port) self.connected = True self.host, self.port = host, port self.socket.settimeout(self.send_receive_timeout) # performance tweak self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self.fin = BufferedSocketReader(self.socket, defines.BUFFER_SIZE) self.fout = BufferedSocketWriter(self.socket, defines.BUFFER_SIZE) self.send_hello() self.receive_hello() self.block_in = self.get_block_in_stream() self.block_in_raw = BlockInputStream(self.fin, self.context) self.block_out = self.get_block_out_stream() def _format_connection_error(self, e, host, port): err = (e.strerror + ' ') if e.strerror else '' return err + '({}:{})'.format(host, port) def connect(self): if self.connected: self.disconnect() logger.debug( 'Connecting. Database: %s. User: %s', self.database, self.user ) err = None for i in range(len(self.hosts)): host, port = self.hosts[0] logger.debug('Connecting to %s:%s', host, port) try: return self._init_connection(host, port) except socket.timeout as e: self.disconnect() logger.warning( 'Failed to connect to %s:%s', host, port, exc_info=True ) err_str = self._format_connection_error(e, host, port) err = errors.SocketTimeoutError(err_str) except socket.error as e: self.disconnect() logger.warning( 'Failed to connect to %s:%s', host, port, exc_info=True ) err_str = self._format_connection_error(e, host, port) err = errors.NetworkError(err_str) self.hosts.rotate(-1) if err is not None: raise err def reset_state(self): self.host = None self.port = None self.socket = None self.fin = None self.fout = None self.connected = False self.client_trace_context = None self.server_info = None self.block_in = None self.block_in_raw = None self.block_out = None self.is_query_executing = False def disconnect(self): """ Closes connection between server and client. Frees resources: e.g. closes socket. """ if self.connected: # There can be errors on shutdown. # We need to close socket and reset state even if it happens. try: self.socket.shutdown(socket.SHUT_RDWR) except socket.error as e: logger.warning('Error on socket shutdown: %s', e) self.socket.close() # Socket can be constructed but not connected. elif self.socket: self.socket.close() self.reset_state() def send_hello(self): write_varint(ClientPacketTypes.HELLO, self.fout) write_binary_str(self.client_name, self.fout) write_varint(defines.CLIENT_VERSION_MAJOR, self.fout) write_varint(defines.CLIENT_VERSION_MINOR, self.fout) # NOTE For backward compatibility of the protocol, # client cannot send its version_patch. write_varint(defines.CLIENT_REVISION, self.fout) write_binary_str(self.database, self.fout) write_binary_str(self.user, self.fout) write_binary_str(self.password, self.fout) self.fout.flush() def receive_hello(self): packet_type = read_varint(self.fin) if packet_type == ServerPacketTypes.HELLO: server_name = read_binary_str(self.fin) server_version_major = read_varint(self.fin) server_version_minor = read_varint(self.fin) server_revision = read_varint(self.fin) server_timezone = None if server_revision >= \ defines.DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE: server_timezone = read_binary_str(self.fin) server_display_name = '' if server_revision >= \ defines.DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME: server_display_name = read_binary_str(self.fin) server_version_patch = server_revision if server_revision >= \ defines.DBMS_MIN_REVISION_WITH_VERSION_PATCH: server_version_patch = read_varint(self.fin) self.server_info = ServerInfo( server_name, server_version_major, server_version_minor, server_version_patch, server_revision, server_timezone, server_display_name ) self.context.server_info = self.server_info logger.debug( 'Connected to %s server version %s.%s.%s, revision: %s', server_name, server_version_major, server_version_minor, server_version_patch, server_revision ) elif packet_type == ServerPacketTypes.EXCEPTION: raise self.receive_exception() else: message = self.unexpected_packet_message('Hello or Exception', packet_type) self.disconnect() raise errors.UnexpectedPacketFromServerError(message) def ping(self): timeout = self.sync_request_timeout with self.timeout_setter(timeout): try: write_varint(ClientPacketTypes.PING, self.fout) self.fout.flush() packet_type = read_varint(self.fin) while packet_type == ServerPacketTypes.PROGRESS: self.receive_progress() packet_type = read_varint(self.fin) if packet_type != ServerPacketTypes.PONG: msg = self.unexpected_packet_message('Pong', packet_type) raise errors.UnexpectedPacketFromServerError(msg) except errors.Error: raise except (socket.error, EOFError) as e: # It's just a warning now. # Current connection will be closed, new will be established. logger.warning( 'Error on %s ping: %s', self.get_description(), e ) return False return True def receive_packet(self): packet = Packet() packet.type = packet_type = read_varint(self.fin) if packet_type == ServerPacketTypes.DATA: packet.block = self.receive_data() elif packet_type == ServerPacketTypes.EXCEPTION: packet.exception = self.receive_exception() elif packet_type == ServerPacketTypes.PROGRESS: packet.progress = self.receive_progress() elif packet_type == ServerPacketTypes.PROFILE_INFO: packet.profile_info = self.receive_profile_info() elif packet_type == ServerPacketTypes.TOTALS: packet.block = self.receive_data() elif packet_type == ServerPacketTypes.EXTREMES: packet.block = self.receive_data() elif packet_type == ServerPacketTypes.LOG: block = self.receive_data(raw=True) log_block(block) elif packet_type == ServerPacketTypes.END_OF_STREAM: self.is_query_executing = False pass elif packet_type == ServerPacketTypes.TABLE_COLUMNS: packet.multistring_message = self.receive_multistring_message( packet_type ) else: message = 'Unknown packet {} from server {}'.format( packet_type, self.get_description() ) self.disconnect() raise errors.UnknownPacketFromServerError(message) return packet def get_block_in_stream(self): if self.compression: from .streams.compressed import CompressedBlockInputStream return CompressedBlockInputStream(self.fin, self.context) else: return BlockInputStream(self.fin, self.context) def get_block_out_stream(self): if self.compression: from .streams.compressed import CompressedBlockOutputStream return CompressedBlockOutputStream( self.compressor_cls, self.compress_block_size, self.fout, self.context ) else: return BlockOutputStream(self.fout, self.context) def receive_data(self, raw=False): revision = self.server_info.revision if revision >= defines.DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES: read_binary_str(self.fin) return (self.block_in_raw if raw else self.block_in).read() def receive_exception(self): return read_exception(self.fin) def receive_progress(self): progress = Progress() progress.read(self.server_info.revision, self.fin) return progress def receive_profile_info(self): profile_info = BlockStreamProfileInfo() profile_info.read(self.fin) return profile_info def receive_multistring_message(self, packet_type): num = ServerPacketTypes.strings_in_message(packet_type) return [read_binary_str(self.fin) for _i in range(num)] def send_data(self, block, table_name=''): start = time() write_varint(ClientPacketTypes.DATA, self.fout) revision = self.server_info.revision if revision >= defines.DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES: write_binary_str(table_name, self.fout) self.block_out.write(block) logger.debug('Block "%s" send time: %f', table_name, time() - start) def send_query(self, query, query_id=None): if not self.connected: self.connect() write_varint(ClientPacketTypes.QUERY, self.fout) write_binary_str(query_id or '', self.fout) revision = self.server_info.revision if revision >= defines.DBMS_MIN_REVISION_WITH_CLIENT_INFO: client_info = ClientInfo(self.client_name, self.context) client_info.query_kind = ClientInfo.QueryKind.INITIAL_QUERY client_info.write(revision, self.fout) settings_as_strings = ( revision >= defines .DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS ) write_settings(self.context.settings, self.fout, settings_as_strings, self.settings_is_important) if revision >= defines.DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET: write_binary_str('', self.fout) write_varint(QueryProcessingStage.COMPLETE, self.fout) write_varint(self.compression, self.fout) write_binary_str(query, self.fout) logger.debug('Query: %s', query) self.fout.flush() def send_cancel(self): write_varint(ClientPacketTypes.CANCEL, self.fout) self.fout.flush() def send_external_tables(self, tables, types_check=False): for table in tables or []: if not table['structure']: raise ValueError( 'Empty table "{}" structure'.format(table['name']) ) data = table['data'] block_cls = RowOrientedBlock if self.context.client_settings['use_numpy']: from .numpy.block import NumpyColumnOrientedBlock columns = [x[0] for x in table['structure']] data = [data[column].values for column in columns] block_cls = NumpyColumnOrientedBlock block = block_cls(table['structure'], data, types_check=types_check) self.send_data(block, table_name=table['name']) # Empty block, end of data transfer. self.send_data(RowOrientedBlock()) @contextmanager def timeout_setter(self, new_timeout): old_timeout = self.socket.gettimeout() self.socket.settimeout(new_timeout) yield self.socket.settimeout(old_timeout) def unexpected_packet_message(self, expected, packet_type): packet_type = ServerPacketTypes.to_str(packet_type) return ( 'Unexpected packet from server {} (expected {}, got {})' .format(self.get_description(), expected, packet_type) ) def check_query_execution(self): self._lock.acquire(blocking=False) if self.is_query_executing: raise errors.PartiallyConsumedQueryError() self.is_query_executing = True self._lock.release() python-clickhouse-driver-0.2.3/clickhouse_driver/context.py000066400000000000000000000016151420676740400242340ustar00rootroot00000000000000 class Context(object): def __init__(self): self._server_info = None self._settings = None self._client_settings = None super(Context, self).__init__() @property def server_info(self): return self._server_info @server_info.setter def server_info(self, value): self._server_info = value @property def settings(self): return self._settings.copy() @settings.setter def settings(self, value): self._settings = value.copy() @property def client_settings(self): return self._client_settings.copy() @client_settings.setter def client_settings(self, value): self._client_settings = value.copy() def __repr__(self): return '' % ( self._server_info, self._client_settings, self._settings ) python-clickhouse-driver-0.2.3/clickhouse_driver/dbapi/000077500000000000000000000000001420676740400232525ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/dbapi/__init__.py000066400000000000000000000033371420676740400253710ustar00rootroot00000000000000from .connection import Connection from .errors import ( Warning, Error, DataError, DatabaseError, ProgrammingError, IntegrityError, InterfaceError, InternalError, NotSupportedError, OperationalError ) from .. import defines apilevel = '2.0' threadsafety = 2 paramstyle = 'pyformat' def connect(dsn=None, host=None, user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD, port=defines.DEFAULT_PORT, database=defines.DEFAULT_DATABASE, **kwargs): """ Create a new database connection. The connection can be specified via DSN: ``conn = connect("clickhouse://localhost/test?param1=value1&...")`` or using database and credentials arguments: ``conn = connect(database="test", user="default", password="default", host="localhost", **kwargs)`` The basic connection parameters are: - *host*: host with running ClickHouse server. - *port*: port ClickHouse server is bound to. - *database*: database connect to. - *user*: database user. - *password*: user's password. See defaults in :data:`~clickhouse_driver.connection.Connection` constructor. DSN or host is required. Any other keyword parameter will be passed to the underlying Connection class. :return: a new connection. """ if dsn is None and host is None: raise ValueError('host or dsn is required') return Connection(dsn=dsn, user=user, password=password, host=host, port=port, database=database, **kwargs) __all__ = [ 'connect', 'Warning', 'Error', 'DataError', 'DatabaseError', 'ProgrammingError', 'IntegrityError', 'InterfaceError', 'InternalError', 'NotSupportedError', 'OperationalError' ] python-clickhouse-driver-0.2.3/clickhouse_driver/dbapi/connection.py000066400000000000000000000054261420676740400257720ustar00rootroot00000000000000from ..client import Client from .. import defines from .cursor import Cursor from .errors import InterfaceError class Connection(object): """ Creates new Connection for accessing ClickHouse database. Connection is just wrapper for handling multiple cursors (clients) and do not initiate actual connections to the ClickHouse server. See parameters description in :data:`~clickhouse_driver.connection.Connection`. """ def __init__(self, dsn=None, host=None, user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD, port=defines.DEFAULT_PORT, database=defines.DEFAULT_DATABASE, **kwargs): self.cursors = [] self.dsn = dsn self.user = user self.password = password self.host = host self.port = port self.database = database self.connection_kwargs = kwargs self.is_closed = False self._hosts = None super(Connection, self).__init__() def __repr__(self): return ''.format( id(self), self.is_closed ) # Context manager integrations. def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.close() def _make_client(self): """ :return: a new Client instance. """ if self.dsn is not None: return Client.from_url(self.dsn) return Client(self.host, port=self.port, user=self.user, password=self.password, database=self.database, **self.connection_kwargs) def close(self): """ Close the connection now. The connection will be unusable from this point forward; an :data:`~clickhouse_driver.dbapi.Error` (or subclass) exception will be raised if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection. """ for cursor in self.cursors: cursor.close() self.is_closed = True def commit(self): """ Do nothing since ClickHouse has no transactions. """ pass def rollback(self): """ Do nothing since ClickHouse has no transactions. """ pass def cursor(self): """ :return: a new Cursor Object using the connection. """ if self.is_closed: raise InterfaceError('connection already closed') client = self._make_client() if self._hosts is None: self._hosts = client.connection.hosts else: client.connection.hosts = self._hosts cursor = Cursor(client, self) self.cursors.append(cursor) return cursor python-clickhouse-driver-0.2.3/clickhouse_driver/dbapi/cursor.py000066400000000000000000000244251420676740400251500ustar00rootroot00000000000000from collections import namedtuple from itertools import islice from ..errors import Error as DriverError from .errors import InterfaceError, OperationalError, ProgrammingError Column = namedtuple( 'Column', 'name type_code display_size internal_size precision scale null_ok' ) class Cursor(object): class States(object): ( NONE, RUNNING, FINISHED, CURSOR_CLOSED ) = range(4) _states = States() def __init__(self, client, connection): self._client = client self._connection = connection self._reset_state() self.arraysize = 1 # Begin non-PEP attributes self._columns_with_types = None # End non-PEP attributes super(Cursor, self).__init__() def __repr__(self): is_closed = self._state == self._states.CURSOR_CLOSED return ''.format( id(self), is_closed ) # Iteration support. def __iter__(self): while True: one = self.fetchone() if one is None: return yield one # Context manager integrations. def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.close() @property def description(self): if self._state == self._states.NONE: return None columns = self._columns or [] types = self._types or [] return [ Column(name, type_code, None, None, None, None, True) for name, type_code in zip(columns, types) ] @property def rowcount(self): """ :return: the number of rows that the last .execute*() produced. """ return self._rowcount def close(self): """ Close the cursor now. The cursor will be unusable from this point forward; an :data:`~clickhouse_driver.dbapi.Error` (or subclass) exception will be raised if any operation is attempted with the cursor. """ self._client.disconnect() self._state = self._states.CURSOR_CLOSED try: # cursor can be already closed self._connection.cursors.remove(self) except ValueError: pass def execute(self, operation, parameters=None): """ Prepare and execute a database operation (query or command). :param operation: query or command to execute. :param parameters: sequence or mapping that will be bound to variables in the operation. :return: None """ self._check_cursor_closed() self._begin_query() try: execute, execute_kwargs = self._prepare() response = execute( operation, params=parameters, with_column_types=True, **execute_kwargs ) except DriverError as orig: raise OperationalError(orig) self._process_response(response) self._end_query() def executemany(self, operation, seq_of_parameters): """ Prepare a database operation (query or command) and then execute it against all parameter sequences found in the sequence `seq_of_parameters`. :param operation: query or command to execute. :param seq_of_parameters: sequences or mappings for execution. :return: None """ self._check_cursor_closed() self._begin_query() try: execute, execute_kwargs = self._prepare() response = execute( operation, params=seq_of_parameters, **execute_kwargs ) except DriverError as orig: raise OperationalError(orig) self._process_response(response, executemany=True) self._end_query() def fetchone(self): """ Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. :return: the next row of a query result set or None. """ self._check_query_started() if self._stream_results: return next(self._rows, None) else: if not self._rows: return None return self._rows.pop(0) def fetchmany(self, size=None): """ Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available. :param size: amount of rows to return. :return: list of fetched rows or empty list. """ self._check_query_started() if size is None: size = self.arraysize if self._stream_results: if size == -1: return list(self._rows) else: return list(islice(self._rows, size)) if size < 0: rv = self._rows self._rows = [] else: rv = self._rows[:size] self._rows = self._rows[size:] return rv def fetchall(self): """ Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). :return: list of fetched rows. """ self._check_query_started() if self._stream_results: return list(self._rows) rv = self._rows self._rows = [] return rv def setinputsizes(self, sizes): # Do nothing. pass def setoutputsize(self, size, column=None): # Do nothing. pass # Begin non-PEP methods @property def columns_with_types(self): """ :return: list of column names with corresponding types of the last .execute*(). E.g. [('x', 'UInt64')]. """ return self._columns_with_types def set_stream_results(self, stream_results, max_row_buffer): """ Toggles results streaming from server. Driver will consume block-by-block of `max_row_buffer` size and yield row-by-row from each block. :param stream_results: enable or disable results streaming. :param max_row_buffer: specifies the maximum number of rows to buffer at a time. :return: None """ self._stream_results = stream_results self._max_row_buffer = max_row_buffer def set_settings(self, settings): """ Specifies settings for cursor. :param settings: dictionary of query settings :return: None """ self._settings = settings def set_types_check(self, types_check): """ Toggles type checking for sequence of INSERT parameters. Disabled by default. :param types_check: new types check value. :return: None """ self._types_check = types_check def set_external_table(self, name, structure, data): """ Adds external table to cursor context. If the same table is specified more than once the last one is used. :param name: name of external table :param structure: list of tuples (name, type) that defines table structure. Example [(x, 'Int32')]. :param data: sequence of rows of tuples or dicts for transmission. :return: None """ self._external_tables[name] = (structure, data) def set_query_id(self, query_id): """ Specifies the query identifier for cursor. :param query_id: the query identifier. :return: None """ self._query_id = query_id # End non-PEP methods # Private methods. def _prepare(self): external_tables = [ {'name': name, 'structure': structure, 'data': data} for name, (structure, data) in self._external_tables.items() ] or None execute = self._client.execute if self._stream_results: execute = self._client.execute_iter self._settings = self._settings or {} self._settings['max_block_size'] = self._max_row_buffer execute_kwargs = { 'settings': self._settings, 'external_tables': external_tables, 'types_check': self._types_check, 'query_id': self._query_id } return execute, execute_kwargs def _process_response(self, response, executemany=False): if executemany: self._rowcount = response response = None if not response or isinstance(response, int): self._columns = self._types = self._rows = [] if isinstance(response, int): self._rowcount = response return if self._stream_results: columns_with_types = next(response) rows = response else: rows, columns_with_types = response self._columns_with_types = columns_with_types # Only SELECT queries have columns_with_types. # DDL and INSERT INTO ... SELECT queries have empty columns header. # We need to obtain rows count only during non-streaming SELECTs. if columns_with_types: self._columns, self._types = zip(*columns_with_types) if not self._stream_results: self._rowcount = len(rows) else: self._columns = self._types = [] self._rows = rows def _reset_state(self): """ Resets query state and get ready for another query. """ self._state = self._states.NONE self._columns = None self._types = None self._rows = None self._rowcount = -1 self._stream_results = False self._max_row_buffer = 0 self._settings = None self._query_id = None self._external_tables = {} self._types_check = False def _begin_query(self): self._state = self._states.RUNNING def _end_query(self): self._state = self._states.FINISHED def _check_cursor_closed(self): if self._state == self._states.CURSOR_CLOSED: raise InterfaceError('cursor already closed') def _check_query_started(self): if self._state == self._states.NONE: raise ProgrammingError('no results to fetch') python-clickhouse-driver-0.2.3/clickhouse_driver/dbapi/errors.py000066400000000000000000000006701420676740400251430ustar00rootroot00000000000000 class Warning(Exception): pass class Error(Exception): pass class InterfaceError(Error): pass class DatabaseError(Error): pass class InternalError(DatabaseError): pass class OperationalError(DatabaseError): pass class ProgrammingError(DatabaseError): pass class IntegrityError(DatabaseError): pass class DataError(DatabaseError): pass class NotSupportedError(DatabaseError): pass python-clickhouse-driver-0.2.3/clickhouse_driver/defines.py000066400000000000000000000023301420676740400241600ustar00rootroot00000000000000 DEFAULT_DATABASE = 'default' DEFAULT_USER = 'default' DEFAULT_PASSWORD = '' DEFAULT_PORT = 9000 DEFAULT_SECURE_PORT = 9440 DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES = 50264 DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS = 51554 DBMS_MIN_REVISION_WITH_BLOCK_INFO = 51903 # Legacy above. DBMS_MIN_REVISION_WITH_CLIENT_INFO = 54032 DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE = 54058 DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO = 54060 DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME = 54372 DBMS_MIN_REVISION_WITH_VERSION_PATCH = 54401 DBMS_MIN_REVISION_WITH_SERVER_LOGS = 54406 DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA = 54410 DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO = 54420 DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS = 54429 DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET = 54441 DBMS_MIN_REVISION_WITH_OPENTELEMETRY = 54442 # Timeouts DBMS_DEFAULT_CONNECT_TIMEOUT_SEC = 10 DBMS_DEFAULT_TIMEOUT_SEC = 300 DBMS_DEFAULT_SYNC_REQUEST_TIMEOUT_SEC = 5 DEFAULT_COMPRESS_BLOCK_SIZE = 1048576 DEFAULT_INSERT_BLOCK_SIZE = 1048576 DBMS_NAME = 'ClickHouse' CLIENT_NAME = 'python-driver' CLIENT_VERSION_MAJOR = 20 CLIENT_VERSION_MINOR = 10 CLIENT_VERSION_PATCH = 2 CLIENT_REVISION = 54442 BUFFER_SIZE = 1048576 STRINGS_ENCODING = 'utf-8' python-clickhouse-driver-0.2.3/clickhouse_driver/errors.py000066400000000000000000000340071420676740400240650ustar00rootroot00000000000000 class ErrorCodes(object): UNSUPPORTED_METHOD = 1 UNSUPPORTED_PARAMETER = 2 UNEXPECTED_END_OF_FILE = 3 EXPECTED_END_OF_FILE = 4 CANNOT_PARSE_TEXT = 6 INCORRECT_NUMBER_OF_COLUMNS = 7 THERE_IS_NO_COLUMN = 8 SIZES_OF_COLUMNS_DOESNT_MATCH = 9 NOT_FOUND_COLUMN_IN_BLOCK = 10 POSITION_OUT_OF_BOUND = 11 PARAMETER_OUT_OF_BOUND = 12 SIZES_OF_COLUMNS_IN_TUPLE_DOESNT_MATCH = 13 DUPLICATE_COLUMN = 15 NO_SUCH_COLUMN_IN_TABLE = 16 DELIMITER_IN_STRING_LITERAL_DOESNT_MATCH = 17 CANNOT_INSERT_ELEMENT_INTO_CONSTANT_COLUMN = 18 SIZE_OF_FIXED_STRING_DOESNT_MATCH = 19 NUMBER_OF_COLUMNS_DOESNT_MATCH = 20 CANNOT_READ_ALL_DATA_FROM_TAB_SEPARATED_INPUT = 21 CANNOT_PARSE_ALL_VALUE_FROM_TAB_SEPARATED_INPUT = 22 CANNOT_READ_FROM_ISTREAM = 23 CANNOT_WRITE_TO_OSTREAM = 24 CANNOT_PARSE_ESCAPE_SEQUENCE = 25 CANNOT_PARSE_QUOTED_STRING = 26 CANNOT_PARSE_INPUT_ASSERTION_FAILED = 27 CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER = 28 CANNOT_PRINT_INTEGER = 29 CANNOT_READ_SIZE_OF_COMPRESSED_CHUNK = 30 CANNOT_READ_COMPRESSED_CHUNK = 31 ATTEMPT_TO_READ_AFTER_EOF = 32 CANNOT_READ_ALL_DATA = 33 TOO_MANY_ARGUMENTS_FOR_FUNCTION = 34 TOO_LESS_ARGUMENTS_FOR_FUNCTION = 35 BAD_ARGUMENTS = 36 UNKNOWN_ELEMENT_IN_AST = 37 CANNOT_PARSE_DATE = 38 TOO_LARGE_SIZE_COMPRESSED = 39 CHECKSUM_DOESNT_MATCH = 40 CANNOT_PARSE_DATETIME = 41 NUMBER_OF_ARGUMENTS_DOESNT_MATCH = 42 ILLEGAL_TYPE_OF_ARGUMENT = 43 ILLEGAL_COLUMN = 44 ILLEGAL_NUMBER_OF_RESULT_COLUMNS = 45 UNKNOWN_FUNCTION = 46 UNKNOWN_IDENTIFIER = 47 NOT_IMPLEMENTED = 48 LOGICAL_ERROR = 49 UNKNOWN_TYPE = 50 EMPTY_LIST_OF_COLUMNS_QUERIED = 51 COLUMN_QUERIED_MORE_THAN_ONCE = 52 TYPE_MISMATCH = 53 STORAGE_DOESNT_ALLOW_PARAMETERS = 54 STORAGE_REQUIRES_PARAMETER = 55 UNKNOWN_STORAGE = 56 TABLE_ALREADY_EXISTS = 57 TABLE_METADATA_ALREADY_EXISTS = 58 ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER = 59 UNKNOWN_TABLE = 60 ONLY_FILTER_COLUMN_IN_BLOCK = 61 SYNTAX_ERROR = 62 UNKNOWN_AGGREGATE_FUNCTION = 63 CANNOT_READ_AGGREGATE_FUNCTION_FROM_TEXT = 64 CANNOT_WRITE_AGGREGATE_FUNCTION_AS_TEXT = 65 NOT_A_COLUMN = 66 ILLEGAL_KEY_OF_AGGREGATION = 67 CANNOT_GET_SIZE_OF_FIELD = 68 ARGUMENT_OUT_OF_BOUND = 69 CANNOT_CONVERT_TYPE = 70 CANNOT_WRITE_AFTER_END_OF_BUFFER = 71 CANNOT_PARSE_NUMBER = 72 UNKNOWN_FORMAT = 73 CANNOT_READ_FROM_FILE_DESCRIPTOR = 74 CANNOT_WRITE_TO_FILE_DESCRIPTOR = 75 CANNOT_OPEN_FILE = 76 CANNOT_CLOSE_FILE = 77 UNKNOWN_TYPE_OF_QUERY = 78 INCORRECT_FILE_NAME = 79 INCORRECT_QUERY = 80 UNKNOWN_DATABASE = 81 DATABASE_ALREADY_EXISTS = 82 DIRECTORY_DOESNT_EXIST = 83 DIRECTORY_ALREADY_EXISTS = 84 FORMAT_IS_NOT_SUITABLE_FOR_INPUT = 85 RECEIVED_ERROR_FROM_REMOTE_IO_SERVER = 86 CANNOT_SEEK_THROUGH_FILE = 87 CANNOT_TRUNCATE_FILE = 88 UNKNOWN_COMPRESSION_METHOD = 89 EMPTY_LIST_OF_COLUMNS_PASSED = 90 SIZES_OF_MARKS_FILES_ARE_INCONSISTENT = 91 EMPTY_DATA_PASSED = 92 UNKNOWN_AGGREGATED_DATA_VARIANT = 93 CANNOT_MERGE_DIFFERENT_AGGREGATED_DATA_VARIANTS = 94 CANNOT_READ_FROM_SOCKET = 95 CANNOT_WRITE_TO_SOCKET = 96 CANNOT_READ_ALL_DATA_FROM_CHUNKED_INPUT = 97 CANNOT_WRITE_TO_EMPTY_BLOCK_OUTPUT_STREAM = 98 UNKNOWN_PACKET_FROM_CLIENT = 99 UNKNOWN_PACKET_FROM_SERVER = 100 UNEXPECTED_PACKET_FROM_CLIENT = 101 UNEXPECTED_PACKET_FROM_SERVER = 102 RECEIVED_DATA_FOR_WRONG_QUERY_ID = 103 TOO_SMALL_BUFFER_SIZE = 104 CANNOT_READ_HISTORY = 105 CANNOT_APPEND_HISTORY = 106 FILE_DOESNT_EXIST = 107 NO_DATA_TO_INSERT = 108 CANNOT_BLOCK_SIGNAL = 109 CANNOT_UNBLOCK_SIGNAL = 110 CANNOT_MANIPULATE_SIGSET = 111 CANNOT_WAIT_FOR_SIGNAL = 112 THERE_IS_NO_SESSION = 113 CANNOT_CLOCK_GETTIME = 114 UNKNOWN_SETTING = 115 THERE_IS_NO_DEFAULT_VALUE = 116 INCORRECT_DATA = 117 ENGINE_REQUIRED = 119 CANNOT_INSERT_VALUE_OF_DIFFERENT_SIZE_INTO_TUPLE = 120 UNKNOWN_SET_DATA_VARIANT = 121 INCOMPATIBLE_COLUMNS = 122 UNKNOWN_TYPE_OF_AST_NODE = 123 INCORRECT_ELEMENT_OF_SET = 124 INCORRECT_RESULT_OF_SCALAR_SUBQUERY = 125 CANNOT_GET_RETURN_TYPE = 126 ILLEGAL_INDEX = 127 TOO_LARGE_ARRAY_SIZE = 128 FUNCTION_IS_SPECIAL = 129 CANNOT_READ_ARRAY_FROM_TEXT = 130 TOO_LARGE_STRING_SIZE = 131 CANNOT_CREATE_TABLE_FROM_METADATA = 132 AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS = 133 PARAMETERS_TO_AGGREGATE_FUNCTIONS_MUST_BE_LITERALS = 134 ZERO_ARRAY_OR_TUPLE_INDEX = 135 UNKNOWN_ELEMENT_IN_CONFIG = 137 EXCESSIVE_ELEMENT_IN_CONFIG = 138 NO_ELEMENTS_IN_CONFIG = 139 ALL_REQUESTED_COLUMNS_ARE_MISSING = 140 SAMPLING_NOT_SUPPORTED = 141 NOT_FOUND_NODE = 142 FOUND_MORE_THAN_ONE_NODE = 143 FIRST_DATE_IS_BIGGER_THAN_LAST_DATE = 144 UNKNOWN_OVERFLOW_MODE = 145 QUERY_SECTION_DOESNT_MAKE_SENSE = 146 NOT_FOUND_FUNCTION_ELEMENT_FOR_AGGREGATE = 147 NOT_FOUND_RELATION_ELEMENT_FOR_CONDITION = 148 NOT_FOUND_RHS_ELEMENT_FOR_CONDITION = 149 NO_ATTRIBUTES_LISTED = 150 INDEX_OF_COLUMN_IN_SORT_CLAUSE_IS_OUT_OF_RANGE = 151 UNKNOWN_DIRECTION_OF_SORTING = 152 ILLEGAL_DIVISION = 153 AGGREGATE_FUNCTION_NOT_APPLICABLE = 154 UNKNOWN_RELATION = 155 DICTIONARIES_WAS_NOT_LOADED = 156 ILLEGAL_OVERFLOW_MODE = 157 TOO_MANY_ROWS = 158 TIMEOUT_EXCEEDED = 159 TOO_SLOW = 160 TOO_MANY_COLUMNS = 161 TOO_DEEP_SUBQUERIES = 162 TOO_DEEP_PIPELINE = 163 READONLY = 164 TOO_MANY_TEMPORARY_COLUMNS = 165 TOO_MANY_TEMPORARY_NON_CONST_COLUMNS = 166 TOO_DEEP_AST = 167 TOO_BIG_AST = 168 BAD_TYPE_OF_FIELD = 169 BAD_GET = 170 BLOCKS_HAVE_DIFFERENT_STRUCTURE = 171 CANNOT_CREATE_DIRECTORY = 172 CANNOT_ALLOCATE_MEMORY = 173 CYCLIC_ALIASES = 174 CHUNK_NOT_FOUND = 176 DUPLICATE_CHUNK_NAME = 177 MULTIPLE_ALIASES_FOR_EXPRESSION = 178 MULTIPLE_EXPRESSIONS_FOR_ALIAS = 179 THERE_IS_NO_PROFILE = 180 ILLEGAL_FINAL = 181 ILLEGAL_PREWHERE = 182 UNEXPECTED_EXPRESSION = 183 ILLEGAL_AGGREGATION = 184 UNSUPPORTED_MYISAM_BLOCK_TYPE = 185 UNSUPPORTED_COLLATION_LOCALE = 186 COLLATION_COMPARISON_FAILED = 187 UNKNOWN_ACTION = 188 TABLE_MUST_NOT_BE_CREATED_MANUALLY = 189 SIZES_OF_ARRAYS_DOESNT_MATCH = 190 SET_SIZE_LIMIT_EXCEEDED = 191 UNKNOWN_USER = 192 WRONG_PASSWORD = 193 REQUIRED_PASSWORD = 194 IP_ADDRESS_NOT_ALLOWED = 195 UNKNOWN_ADDRESS_PATTERN_TYPE = 196 SERVER_REVISION_IS_TOO_OLD = 197 DNS_ERROR = 198 UNKNOWN_QUOTA = 199 QUOTA_DOESNT_ALLOW_KEYS = 200 QUOTA_EXPIRED = 201 TOO_MANY_SIMULTANEOUS_QUERIES = 202 NO_FREE_CONNECTION = 203 CANNOT_FSYNC = 204 NESTED_TYPE_TOO_DEEP = 205 ALIAS_REQUIRED = 206 AMBIGUOUS_IDENTIFIER = 207 EMPTY_NESTED_TABLE = 208 SOCKET_TIMEOUT = 209 NETWORK_ERROR = 210 EMPTY_QUERY = 211 UNKNOWN_LOAD_BALANCING = 212 UNKNOWN_TOTALS_MODE = 213 CANNOT_STATVFS = 214 NOT_AN_AGGREGATE = 215 QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING = 216 CLIENT_HAS_CONNECTED_TO_WRONG_PORT = 217 TABLE_IS_DROPPED = 218 DATABASE_NOT_EMPTY = 219 DUPLICATE_INTERSERVER_IO_ENDPOINT = 220 NO_SUCH_INTERSERVER_IO_ENDPOINT = 221 ADDING_REPLICA_TO_NON_EMPTY_TABLE = 222 UNEXPECTED_AST_STRUCTURE = 223 REPLICA_IS_ALREADY_ACTIVE = 224 NO_ZOOKEEPER = 225 NO_FILE_IN_DATA_PART = 226 UNEXPECTED_FILE_IN_DATA_PART = 227 BAD_SIZE_OF_FILE_IN_DATA_PART = 228 QUERY_IS_TOO_LARGE = 229 NOT_FOUND_EXPECTED_DATA_PART = 230 TOO_MANY_UNEXPECTED_DATA_PARTS = 231 NO_SUCH_DATA_PART = 232 BAD_DATA_PART_NAME = 233 NO_REPLICA_HAS_PART = 234 DUPLICATE_DATA_PART = 235 ABORTED = 236 NO_REPLICA_NAME_GIVEN = 237 FORMAT_VERSION_TOO_OLD = 238 CANNOT_MUNMAP = 239 CANNOT_MREMAP = 240 MEMORY_LIMIT_EXCEEDED = 241 TABLE_IS_READ_ONLY = 242 NOT_ENOUGH_SPACE = 243 UNEXPECTED_ZOOKEEPER_ERROR = 244 CORRUPTED_DATA = 246 INCORRECT_MARK = 247 INVALID_PARTITION_VALUE = 248 NOT_ENOUGH_BLOCK_NUMBERS = 250 NO_SUCH_REPLICA = 251 TOO_MANY_PARTS = 252 REPLICA_IS_ALREADY_EXIST = 253 NO_ACTIVE_REPLICAS = 254 TOO_MANY_RETRIES_TO_FETCH_PARTS = 255 PARTITION_ALREADY_EXISTS = 256 PARTITION_DOESNT_EXIST = 257 UNION_ALL_RESULT_STRUCTURES_MISMATCH = 258 CLIENT_OUTPUT_FORMAT_SPECIFIED = 260 UNKNOWN_BLOCK_INFO_FIELD = 261 BAD_COLLATION = 262 CANNOT_COMPILE_CODE = 263 INCOMPATIBLE_TYPE_OF_JOIN = 264 NO_AVAILABLE_REPLICA = 265 MISMATCH_REPLICAS_DATA_SOURCES = 266 STORAGE_DOESNT_SUPPORT_PARALLEL_REPLICAS = 267 CPUID_ERROR = 268 INFINITE_LOOP = 269 CANNOT_COMPRESS = 270 CANNOT_DECOMPRESS = 271 AIO_SUBMIT_ERROR = 272 AIO_COMPLETION_ERROR = 273 AIO_READ_ERROR = 274 AIO_WRITE_ERROR = 275 INDEX_NOT_USED = 277 LEADERSHIP_LOST = 278 ALL_CONNECTION_TRIES_FAILED = 279 NO_AVAILABLE_DATA = 280 DICTIONARY_IS_EMPTY = 281 INCORRECT_INDEX = 282 UNKNOWN_DISTRIBUTED_PRODUCT_MODE = 283 UNKNOWN_GLOBAL_SUBQUERIES_METHOD = 284 TOO_LESS_LIVE_REPLICAS = 285 UNSATISFIED_QUORUM_FOR_PREVIOUS_WRITE = 286 UNKNOWN_FORMAT_VERSION = 287 DISTRIBUTED_IN_JOIN_SUBQUERY_DENIED = 288 REPLICA_IS_NOT_IN_QUORUM = 289 LIMIT_EXCEEDED = 290 DATABASE_ACCESS_DENIED = 291 LEADERSHIP_CHANGED = 292 MONGODB_CANNOT_AUTHENTICATE = 293 INVALID_BLOCK_EXTRA_INFO = 294 RECEIVED_EMPTY_DATA = 295 NO_REMOTE_SHARD_FOUND = 296 SHARD_HAS_NO_CONNECTIONS = 297 CANNOT_PIPE = 298 CANNOT_FORK = 299 CANNOT_DLSYM = 300 CANNOT_CREATE_CHILD_PROCESS = 301 CHILD_WAS_NOT_EXITED_NORMALLY = 302 CANNOT_SELECT = 303 CANNOT_WAITPID = 304 TABLE_WAS_NOT_DROPPED = 305 TOO_DEEP_RECURSION = 306 TOO_MANY_BYTES = 307 UNEXPECTED_NODE_IN_ZOOKEEPER = 308 FUNCTION_CANNOT_HAVE_PARAMETERS = 309 INVALID_SHARD_WEIGHT = 317 INVALID_CONFIG_PARAMETER = 318 UNKNOWN_STATUS_OF_INSERT = 319 VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE = 321 BARRIER_TIMEOUT = 335 UNKNOWN_DATABASE_ENGINE = 336 DDL_GUARD_IS_ACTIVE = 337 UNFINISHED = 341 METADATA_MISMATCH = 342 SUPPORT_IS_DISABLED = 344 TABLE_DIFFERS_TOO_MUCH = 345 CANNOT_CONVERT_CHARSET = 346 CANNOT_LOAD_CONFIG = 347 CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN = 349 INCOMPATIBLE_SOURCE_TABLES = 350 AMBIGUOUS_TABLE_NAME = 351 AMBIGUOUS_COLUMN_NAME = 352 INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE = 353 ZLIB_INFLATE_FAILED = 354 ZLIB_DEFLATE_FAILED = 355 BAD_LAMBDA = 356 RESERVED_IDENTIFIER_NAME = 357 INTO_OUTFILE_NOT_ALLOWED = 358 TABLE_SIZE_EXCEEDS_MAX_DROP_SIZE_LIMIT = 359 CANNOT_CREATE_CHARSET_CONVERTER = 360 SEEK_POSITION_OUT_OF_BOUND = 361 CURRENT_WRITE_BUFFER_IS_EXHAUSTED = 362 CANNOT_CREATE_IO_BUFFER = 363 RECEIVED_ERROR_TOO_MANY_REQUESTS = 364 OUTPUT_IS_NOT_SORTED = 365 SIZES_OF_NESTED_COLUMNS_ARE_INCONSISTENT = 366 TOO_MANY_FETCHES = 367 BAD_CAST = 368 ALL_REPLICAS_ARE_STALE = 369 DATA_TYPE_CANNOT_BE_USED_IN_TABLES = 370 INCONSISTENT_CLUSTER_DEFINITION = 371 SESSION_NOT_FOUND = 372 SESSION_IS_LOCKED = 373 INVALID_SESSION_TIMEOUT = 374 CANNOT_DLOPEN = 375 CANNOT_PARSE_UUID = 376 ILLEGAL_SYNTAX_FOR_DATA_TYPE = 377 DATA_TYPE_CANNOT_HAVE_ARGUMENTS = 378 UNKNOWN_STATUS_OF_DISTRIBUTED_DDL_TASK = 379 CANNOT_KILL = 380 HTTP_LENGTH_REQUIRED = 381 CANNOT_LOAD_CATBOOST_MODEL = 382 CANNOT_APPLY_CATBOOST_MODEL = 383 PART_IS_TEMPORARILY_LOCKED = 384 MULTIPLE_STREAMS_REQUIRED = 385 NO_COMMON_TYPE = 386 EXTERNAL_LOADABLE_ALREADY_EXISTS = 387 CANNOT_ASSIGN_OPTIMIZE = 388 INSERT_WAS_DEDUPLICATED = 389 CANNOT_GET_CREATE_TABLE_QUERY = 390 EXTERNAL_LIBRARY_ERROR = 391 QUERY_IS_PROHIBITED = 392 THERE_IS_NO_QUERY = 393 QUERY_WAS_CANCELLED = 394 FUNCTION_THROW_IF_VALUE_IS_NON_ZERO = 395 TOO_MANY_ROWS_OR_BYTES = 396 QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW = 397 CANNOT_PARSE_DOMAIN_VALUE_FROM_STRING = 441 KEEPER_EXCEPTION = 999 POCO_EXCEPTION = 1000 STD_EXCEPTION = 1001 UNKNOWN_EXCEPTION = 1002 CONDITIONAL_TREE_PARENT_NOT_FOUND = 2001 ILLEGAL_PROJECTION_MANIPULATOR = 2002 class Error(Exception): code = None def __init__(self, message=None): self.message = message super(Error, self).__init__(message) def __str__(self): message = ' ' + self.message if self.message is not None else '' return 'Code: {}.{}'.format(self.code, message) class ServerException(Error): def __init__(self, message, code=None, nested=None): self.message = message self.code = code self.nested = nested super(ServerException, self).__init__(message) def __str__(self): nested = '\nNested: {}'.format(self.nested) if self.nested else '' return 'Code: {}.{}\n{}'.format(self.code, nested, self.message) class LogicalError(Error): code = ErrorCodes.LOGICAL_ERROR class UnknownTypeError(Error): code = ErrorCodes.UNKNOWN_TYPE class ChecksumDoesntMatchError(Error): code = ErrorCodes.CHECKSUM_DOESNT_MATCH class TypeMismatchError(Error): code = ErrorCodes.TYPE_MISMATCH class UnknownCompressionMethod(Error): code = ErrorCodes.UNKNOWN_COMPRESSION_METHOD class TooLargeStringSize(Error): code = ErrorCodes.TOO_LARGE_STRING_SIZE class NetworkError(Error): code = ErrorCodes.NETWORK_ERROR class SocketTimeoutError(Error): code = ErrorCodes.SOCKET_TIMEOUT class UnexpectedPacketFromServerError(Error): code = ErrorCodes.UNEXPECTED_PACKET_FROM_SERVER class UnknownPacketFromServerError(Error): code = ErrorCodes.UNKNOWN_PACKET_FROM_SERVER class CannotParseUuidError(Error): code = ErrorCodes.CANNOT_PARSE_UUID class CannotParseDomainError(Error): code = ErrorCodes.CANNOT_PARSE_DOMAIN_VALUE_FROM_STRING class PartiallyConsumedQueryError(Error): code = -1 def __str__(self): return 'Simultaneous queries on single connection detected' python-clickhouse-driver-0.2.3/clickhouse_driver/log.py000066400000000000000000000015701420676740400233310ustar00rootroot00000000000000import logging logger = logging.getLogger(__name__) log_priorities = ( 'Unknown', 'Fatal', 'Critical', 'Error', 'Warning', 'Notice', 'Information', 'Debug', 'Trace' ) def log_block(block): if block is None: return column_names = [x[0] for x in block.columns_with_types] for row in block.get_rows(): row = dict(zip(column_names, row)) if 1 <= row['priority'] <= 8: priority = log_priorities[row['priority']] else: priority = row[0] # thread_number in servers prior 20.x thread_id = row.get('thread_id') or row['thread_number'] logger.info( '[ %s ] [ %s ] {%s} <%s> %s: %s', row['host_name'], thread_id, row['query_id'], priority, row['source'], row['text'] ) python-clickhouse-driver-0.2.3/clickhouse_driver/numpy/000077500000000000000000000000001420676740400233435ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/numpy/__init__.py000066400000000000000000000000001420676740400254420ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/numpy/block.py000066400000000000000000000002641420676740400250110ustar00rootroot00000000000000import numpy as np from ..block import ColumnOrientedBlock class NumpyColumnOrientedBlock(ColumnOrientedBlock): def transposed(self): return np.transpose(self.data) python-clickhouse-driver-0.2.3/clickhouse_driver/numpy/helpers.py000066400000000000000000000013001420676740400253510ustar00rootroot00000000000000import numpy as np import pandas as pd def column_chunks(columns, n): for column in columns: if not isinstance(column, (np.ndarray, pd.DatetimeIndex)): raise TypeError( 'Unsupported column type: {}. ' 'ndarray/DatetimeIndex is expected.' .format(type(column)) ) # create chunk generator for every column chunked = [ iter(np.array_split(c, len(c) // n) if len(c) > n else [c]) for c in columns ] while True: # get next chunk for every column item = [next(column, []) for column in chunked] if not any(len(x) for x in item): break yield item python-clickhouse-driver-0.2.3/clickhouse_driver/numpy/result.py000066400000000000000000000067531420676740400252460ustar00rootroot00000000000000from itertools import chain import numpy as np import pandas as pd from pandas.api.types import union_categoricals from ..progress import Progress from ..result import QueryResult class NumpyQueryResult(QueryResult): """ Stores query result from multiple blocks as numpy arrays. """ def store(self, packet): block = getattr(packet, 'block', None) if block is None: return # Header block contains no rows. Pick columns from it. if block.num_rows: if self.columnar: self.data.append(block.get_columns()) else: self.data.extend(block.get_rows()) elif not self.columns_with_types: self.columns_with_types = block.columns_with_types def get_result(self): """ :return: stored query result. """ for packet in self.packet_generator: self.store(packet) if self.columnar: data = [] # Transpose to a list of columns, each column is list of chunks for column_chunks in zip(*self.data): # Concatenate chunks for each column if isinstance(column_chunks[0], np.ndarray): column = np.concatenate(column_chunks) elif isinstance(column_chunks[0], pd.Categorical): column = union_categoricals(column_chunks) else: column = tuple(chain.from_iterable(column_chunks)) data.append(column) else: data = self.data if self.with_column_types: return data, self.columns_with_types else: return data class NumpyProgressQueryResult(NumpyQueryResult): """ Stores query result and progress information from multiple blocks. Provides iteration over query progress. """ def __init__(self, *args, **kwargs): self.progress_totals = Progress() super(NumpyProgressQueryResult, self).__init__(*args, **kwargs) def __iter__(self): return self def __next__(self): while True: packet = next(self.packet_generator) progress_packet = getattr(packet, 'progress', None) if progress_packet: self.progress_totals.increment(progress_packet) return ( self.progress_totals.rows, self.progress_totals.total_rows ) else: self.store(packet) def get_result(self): # Read all progress packets. for _ in self: pass return super(NumpyProgressQueryResult, self).get_result() class NumpyIterQueryResult(object): """ Provides iteration over returned data by chunks (streaming by chunks). """ def __init__( self, packet_generator, with_column_types=False): self.packet_generator = packet_generator self.with_column_types = with_column_types self.first_block = True super(NumpyIterQueryResult, self).__init__() def __iter__(self): return self def __next__(self): packet = next(self.packet_generator) block = getattr(packet, 'block', None) if block is None: return [] if self.first_block and self.with_column_types: self.first_block = False rv = [block.columns_with_types] rv.extend(block.get_rows()) return rv else: return block.get_rows() python-clickhouse-driver-0.2.3/clickhouse_driver/opentelemetry.py000066400000000000000000000031261420676740400254430ustar00rootroot00000000000000 class OpenTelemetryTraceContext(object): traceparent_tpl = 'xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx' translation = str.maketrans('1234567890abcdef', 'xxxxxxxxxxxxxxxx') def __init__(self, traceparent, tracestate): # xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xx # ^ ^ ^ ^ # version trace_id span_id flags self.trace_id = None # UUID self.span_id = None # UInt64 self.tracestate = tracestate # String self.trace_flags = None # UInt8 if traceparent is not None: self.parse_traceparent(traceparent) super(OpenTelemetryTraceContext, self).__init__() def parse_traceparent(self, traceparent): traceparent = traceparent.lower() if len(traceparent) != len(self.traceparent_tpl): raise ValueError('unexpected length {}, expected {}'.format( len(traceparent), len(self.traceparent_tpl) )) if traceparent.translate(self.translation) != self.traceparent_tpl: raise ValueError( 'Malformed traceparant header: {}'.format(traceparent) ) parts = traceparent.split('-') version = int(parts[0], 16) if version != 0: raise ValueError( 'unexpected version {}, expected 00'.format(parts[0]) ) self.trace_id = (int(parts[1][16:], 16) << 64) + int(parts[1][:16], 16) self.span_id = int(parts[2], 16) self.trace_flags = int(parts[3], 16) python-clickhouse-driver-0.2.3/clickhouse_driver/progress.py000066400000000000000000000020171420676740400244110ustar00rootroot00000000000000from . import defines from .varint import read_varint class Progress(object): def __init__(self): self.rows = 0 self.bytes = 0 self.total_rows = 0 self.written_rows = 0 self.written_bytes = 0 super(Progress, self).__init__() def read(self, server_revision, fin): self.rows = read_varint(fin) self.bytes = read_varint(fin) revision = server_revision if revision >= defines.DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS: self.total_rows = read_varint(fin) if revision >= defines.DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO: self.written_rows = read_varint(fin) self.written_bytes = read_varint(fin) def increment(self, another_progress): self.rows += another_progress.rows self.bytes += another_progress.bytes self.total_rows += another_progress.total_rows self.written_rows += another_progress.written_rows self.written_bytes += another_progress.written_bytes python-clickhouse-driver-0.2.3/clickhouse_driver/protocol.py000066400000000000000000000043621420676740400244130ustar00rootroot00000000000000 class ClientPacketTypes(object): """ Packet types that client transmits """ # Name, version, revision, default DB HELLO = 0 # Query id, query settings, stage up to which the query must be executed, # whether the compression must be used, query text # (without data for INSERTs). QUERY = 1 # A block of data (compressed or not). DATA = 2 # Cancel the query execution. CANCEL = 3 # Check that connection to the server is alive. PING = 4 # Check status of tables on the server. TABLES_STATUS_REQUEST = 5 _types_str = [ 'Hello', 'Query', 'Data', 'Cancel', 'Ping', 'TablesStatusRequest' ] @classmethod def to_str(cls, packet): return 'Unknown packet' if packet > 5 else cls._types_str[packet] class ServerPacketTypes(object): """ Packet types that server transmits. """ # Name, version, revision. HELLO = 0 # A block of data (compressed or not). DATA = 1 # The exception during query execution. EXCEPTION = 2 # Query execution progress: rows read, bytes read. PROGRESS = 3 # Ping response PONG = 4 # All packets were transmitted END_OF_STREAM = 5 # Packet with profiling info. PROFILE_INFO = 6 # A block with totals (compressed or not). TOTALS = 7 # A block with minimums and maximums (compressed or not). EXTREMES = 8 # A response to TablesStatus request. TABLES_STATUS_RESPONSE = 9 # System logs of the query execution LOG = 10 # Columns' description for default values calculation TABLE_COLUMNS = 11 _types_str = [ 'Hello', 'Data', 'Exception', 'Progress', 'Pong', 'EndOfStream', 'ProfileInfo', 'Totals', 'Extremes', 'TablesStatusResponse', 'Log', 'TableColumns' ] @classmethod def to_str(cls, packet): return 'Unknown packet' if packet > 11 else cls._types_str[packet] @classmethod def strings_in_message(cls, packet): if packet == cls.TABLE_COLUMNS: return 2 return 0 class Compression(object): DISABLED = 0 ENABLED = 1 class CompressionMethod(object): LZ4 = 1 LZ4HC = 2 ZSTD = 3 class CompressionMethodByte(object): LZ4 = 0x82 ZSTD = 0x90 python-clickhouse-driver-0.2.3/clickhouse_driver/queryprocessingstage.py000066400000000000000000000002721420676740400270340ustar00rootroot00000000000000 class QueryProcessingStage(object): """ Determines till which state SELECT query should be executed. """ FETCH_COLUMNS = 0 WITH_MERGEABLE_STATE = 1 COMPLETE = 2 python-clickhouse-driver-0.2.3/clickhouse_driver/reader.py000066400000000000000000000024521420676740400240120ustar00rootroot00000000000000from struct import Struct from .varint import read_varint def read_binary_str(buf): length = read_varint(buf) return read_binary_str_fixed_len(buf, length) def read_binary_bytes(buf): length = read_varint(buf) return read_binary_bytes_fixed_len(buf, length) def read_binary_str_fixed_len(buf, length): return read_binary_bytes_fixed_len(buf, length).decode('utf-8') def read_binary_bytes_fixed_len(buf, length): return buf.read(length) def read_binary_int(buf, fmt): """ Reads int from buffer with provided format. """ # Little endian. s = Struct('<' + fmt) return s.unpack(buf.read(s.size))[0] def read_binary_int8(buf): return read_binary_int(buf, 'b') def read_binary_int16(buf): return read_binary_int(buf, 'h') def read_binary_int32(buf): return read_binary_int(buf, 'i') def read_binary_int64(buf): return read_binary_int(buf, 'q') def read_binary_uint8(buf): return read_binary_int(buf, 'B') def read_binary_uint16(buf): return read_binary_int(buf, 'H') def read_binary_uint32(buf): return read_binary_int(buf, 'I') def read_binary_uint64(buf): return read_binary_int(buf, 'Q') def read_binary_uint128(buf): hi = read_binary_int(buf, 'Q') lo = read_binary_int(buf, 'Q') return (hi << 64) + lo python-clickhouse-driver-0.2.3/clickhouse_driver/readhelpers.py000066400000000000000000000013151420676740400250430ustar00rootroot00000000000000from .errors import ServerException from .reader import read_binary_str, read_binary_uint8, read_binary_int32 def read_exception(buf, additional_message=None): code = read_binary_int32(buf) name = read_binary_str(buf) message = read_binary_str(buf) stack_trace = read_binary_str(buf) has_nested = bool(read_binary_uint8(buf)) new_message = '' if additional_message: new_message += additional_message + '. ' if name != 'DB::Exception': new_message += name + ". " new_message += message + ". Stack trace:\n\n" + stack_trace nested = None if has_nested: nested = read_exception(buf) return ServerException(new_message, code, nested=nested) python-clickhouse-driver-0.2.3/clickhouse_driver/result.py000066400000000000000000000100021420676740400240540ustar00rootroot00000000000000from .blockstreamprofileinfo import BlockStreamProfileInfo from .progress import Progress class QueryResult(object): """ Stores query result from multiple blocks. """ def __init__( self, packet_generator, with_column_types=False, columnar=False): self.packet_generator = packet_generator self.with_column_types = with_column_types self.data = [] self.columns_with_types = [] self.columnar = columnar super(QueryResult, self).__init__() def store(self, packet): block = getattr(packet, 'block', None) if block is None: return # Header block contains no rows. Pick columns from it. if block.num_rows: if self.columnar: columns = block.get_columns() if self.data: # Extend corresponding column. for i, column in enumerate(columns): self.data[i].extend(column) else: # Cast tuples to lists for further extending. # Concatenating tuples produce new tuple. It's slow. self.data = [list(c) for c in columns] else: self.data.extend(block.get_rows()) elif not self.columns_with_types: self.columns_with_types = block.columns_with_types def get_result(self): """ :return: stored query result. """ for packet in self.packet_generator: self.store(packet) data = self.data if self.columnar: data = [tuple(c) for c in self.data] if self.with_column_types: return data, self.columns_with_types else: return data class ProgressQueryResult(QueryResult): """ Stores query result and progress information from multiple blocks. Provides iteration over query progress. """ def __init__(self, *args, **kwargs): self.progress_totals = Progress() super(ProgressQueryResult, self).__init__(*args, **kwargs) def __iter__(self): return self def __next__(self): while True: packet = next(self.packet_generator) progress_packet = getattr(packet, 'progress', None) if progress_packet: self.progress_totals.increment(progress_packet) return ( self.progress_totals.rows, self.progress_totals.total_rows ) else: self.store(packet) def get_result(self): # Read all progress packets. for _ in self: pass return super(ProgressQueryResult, self).get_result() class IterQueryResult(object): """ Provides iteration over returned data by chunks (streaming by chunks). """ def __init__( self, packet_generator, with_column_types=False): self.packet_generator = packet_generator self.with_column_types = with_column_types self.first_block = True super(IterQueryResult, self).__init__() def __iter__(self): return self def __next__(self): packet = next(self.packet_generator) block = getattr(packet, 'block', None) if block is None: return [] if self.first_block and self.with_column_types: self.first_block = False rv = [block.columns_with_types] rv.extend(block.get_rows()) return rv else: return block.get_rows() class QueryInfo(object): def __init__(self): self.profile_info = BlockStreamProfileInfo() self.progress = Progress() self.elapsed = 0 def store_profile(self, profile_info): self.profile_info = profile_info def store_progress(self, progress): if self.progress: self.progress.increment(progress) else: self.progress = progress def store_elapsed(self, elapsed): self.elapsed = elapsed python-clickhouse-driver-0.2.3/clickhouse_driver/settings/000077500000000000000000000000001420676740400240335ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/settings/__init__.py000066400000000000000000000000001420676740400261320ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/settings/available.py000066400000000000000000000403451420676740400263330ustar00rootroot00000000000000from .types import ( SettingUInt64, SettingBool, SettingFloat, SettingString, SettingMaxThreads, SettingChar ) SettingInt64 = SettingUInt64 # Seconds and milliseconds should be set as ints. SettingSeconds = SettingMilliseconds = SettingUInt64 # Server cares about possible choices validation. # See https://github.com/yandex/ClickHouse/blob/master/dbms/src/ # Interpreters/Settings.h for all choices. SettingLoadBalancing = SettingTotalsMode = SettingCompressionMethod = \ SettingDistributedProductMode = SettingGlobalSubqueriesMethod = \ SettingDateTimeInputFormat = \ SettingURI = \ SettingJoinAlgorithm = \ SettingSpecialSort = \ SettingLogQueriesType = \ SettingDefaultDatabaseEngine = \ SettingString settings = { # Settings 'min_compress_block_size': SettingUInt64, 'max_compress_block_size': SettingUInt64, 'max_block_size': SettingUInt64, 'max_insert_block_size': SettingUInt64, 'min_insert_block_size_rows': SettingUInt64, 'min_insert_block_size_bytes': SettingUInt64, 'max_partitions_per_insert_block': SettingUInt64, 'max_threads': SettingMaxThreads, 'max_alter_threads': SettingMaxThreads, 'max_read_buffer_size': SettingUInt64, 'max_distributed_connections': SettingUInt64, 'max_query_size': SettingUInt64, 'interactive_delay': SettingUInt64, 'connect_timeout': SettingSeconds, 'connect_timeout_with_failover_ms': SettingMilliseconds, 'receive_timeout': SettingSeconds, 'send_timeout': SettingSeconds, 'queue_max_wait_ms': SettingMilliseconds, 'poll_interval': SettingUInt64, 'distributed_connections_pool_size': SettingUInt64, 'connections_with_failover_max_tries': SettingUInt64, 'extremes': SettingBool, 'use_uncompressed_cache': SettingBool, 'replace_running_query': SettingBool, 'background_pool_size': SettingUInt64, 'background_schedule_pool_size': SettingUInt64, 'distributed_directory_monitor_sleep_time_ms': SettingMilliseconds, 'distributed_directory_monitor_batch_inserts': SettingBool, 'distributed_directory_monitor_max_sleep_time_ms': SettingMilliseconds, 'optimize_move_to_prewhere': SettingBool, 'optimize_skip_unused_shards': SettingBool, 'optimize_read_in_order': SettingBool, 'optimize_min_equality_disjunction_chain_length': SettingUInt64, 'enable_optimize_predicate_expression': SettingBool, 'replication_alter_partitions_sync': SettingUInt64, 'replication_alter_columns_timeout': SettingUInt64, 'load_balancing': SettingLoadBalancing, 'totals_mode': SettingTotalsMode, 'totals_auto_threshold': SettingFloat, 'compile': SettingBool, 'compile_expressions': SettingBool, 'min_count_to_compile': SettingUInt64, 'group_by_two_level_threshold': SettingUInt64, 'group_by_two_level_threshold_bytes': SettingUInt64, 'distributed_aggregation_memory_efficient': SettingBool, 'aggregation_memory_efficient_merge_threads': SettingUInt64, 'max_parallel_replicas': SettingUInt64, 'parallel_replicas_count': SettingUInt64, 'parallel_replica_offset': SettingUInt64, 'skip_unavailable_shards': SettingBool, 'distributed_group_by_no_merge': SettingBool, 'merge_tree_min_rows_for_concurrent_read': SettingUInt64, 'merge_tree_min_rows_for_seek': SettingUInt64, 'merge_tree_coarse_index_granularity': SettingUInt64, 'merge_tree_max_rows_to_use_cache': SettingUInt64, 'merge_tree_min_bytes_for_concurrent_read': SettingUInt64, 'merge_tree_min_bytes_for_seek': SettingUInt64, 'merge_tree_max_bytes_to_use_cache': SettingUInt64, 'merge_tree_uniform_read_distribution': SettingBool, 'mysql_max_rows_to_insert': SettingUInt64, 'min_bytes_to_use_direct_io': SettingUInt64, 'force_index_by_date': SettingBool, 'force_primary_key': SettingBool, 'mark_cache_min_lifetime': SettingUInt64, 'max_streams_to_max_threads_ratio': SettingFloat, 'network_compression_method': SettingCompressionMethod, 'network_zstd_compression_level': SettingInt64, 'priority': SettingUInt64, 'log_queries': SettingBool, 'log_queries_cut_to_length': SettingUInt64, 'query_profiler_real_time_period_ns': SettingUInt64, 'query_profiler_cpu_time_period_ns': SettingUInt64, 'enable_debug_queries': SettingBool, 'distributed_product_mode': SettingDistributedProductMode, 'max_concurrent_queries_for_user': SettingUInt64, 'insert_deduplicate': SettingBool, 'insert_quorum': SettingUInt64, 'insert_quorum_timeout': SettingMilliseconds, 'select_sequential_consistency': SettingUInt64, 'table_function_remote_max_addresses': SettingUInt64, 'read_backoff_min_latency_ms': SettingMilliseconds, 'read_backoff_max_throughput': SettingUInt64, 'read_backoff_min_interval_between_events_ms': SettingMilliseconds, 'read_backoff_min_events': SettingUInt64, 'memory_tracker_fault_probability': SettingFloat, 'enable_http_compression': SettingBool, 'http_zlib_compression_level': SettingInt64, 'http_native_compression_disable_checksumming_on_decompress': SettingBool, 'count_distinct_implementation': SettingString, 'add_http_cors_header': SettingBool, 'input_format_skip_unknown_fields': SettingBool, 'input_format_import_nested_json': SettingBool, 'input_format_values_interpret_expressions': SettingBool, 'input_format_with_names_use_header': SettingBool, 'input_format_defaults_for_omitted_fields': SettingBool, 'input_format_null_as_default': SettingBool, 'input_format_values_deduce_templates_of_expressions': SettingBool, 'input_format_values_accurate_types_of_literals': SettingBool, 'input_format_allow_errors_num': SettingUInt64, 'input_format_allow_errors_ratio': SettingFloat, 'input_format_csv_unquoted_null_literal_as_null': SettingBool, 'output_format_write_statistics': SettingBool, 'output_format_json_quote_64bit_integers': SettingBool, 'output_format_json_quote_denormals': SettingBool, 'output_format_json_escape_forward_slashes': SettingBool, 'output_format_pretty_max_rows': SettingUInt64, 'output_format_pretty_max_column_pad_width': SettingUInt64, 'output_format_pretty_color': SettingBool, 'output_format_parquet_row_group_size': SettingUInt64, 'use_client_time_zone': SettingBool, 'send_progress_in_http_headers': SettingBool, 'http_headers_progress_interval_ms': SettingUInt64, 'fsync_metadata': SettingBool, 'join_use_nulls': SettingBool, 'join_default_strictness': SettingString, 'preferred_block_size_bytes': SettingUInt64, 'max_replica_delay_for_distributed_queries': SettingUInt64, 'fallback_to_stale_replicas_for_distributed_queries': SettingBool, 'preferred_max_column_in_block_size_bytes': SettingUInt64, 'insert_distributed_sync': SettingBool, 'insert_distributed_timeout': SettingUInt64, 'distributed_ddl_task_timeout': SettingInt64, 'stream_flush_interval_ms': SettingMilliseconds, 'format_schema': SettingString, 'insert_allow_materialized_columns': SettingBool, 'http_connection_timeout': SettingSeconds, 'http_send_timeout': SettingSeconds, 'http_receive_timeout': SettingSeconds, 'optimize_throw_if_noop': SettingBool, 'use_index_for_in_with_subqueries': SettingBool, 'empty_result_for_aggregation_by_empty_set': SettingBool, 'allow_distributed_ddl': SettingBool, 'odbc_max_field_size': SettingUInt64, # Limits 'max_rows_to_read': SettingUInt64, 'max_bytes_to_read': SettingUInt64, 'read_overflow_mode': SettingString, 'max_rows_to_group_by': SettingUInt64, 'group_by_overflow_mode': SettingString, 'max_bytes_before_external_group_by': SettingUInt64, 'max_rows_to_sort': SettingUInt64, 'max_bytes_to_sort': SettingUInt64, 'sort_overflow_mode': SettingString, 'max_bytes_before_external_sort': SettingUInt64, 'max_bytes_before_remerge_sort': SettingUInt64, 'max_result_rows': SettingUInt64, 'max_result_bytes': SettingUInt64, 'result_overflow_mode': SettingString, 'max_execution_time': SettingSeconds, 'timeout_overflow_mode': SettingString, 'min_execution_speed': SettingUInt64, 'timeout_before_checking_execution_speed': SettingSeconds, 'max_columns_to_read': SettingUInt64, 'max_temporary_columns': SettingUInt64, 'max_temporary_non_const_columns': SettingUInt64, 'max_subquery_depth': SettingUInt64, 'max_pipeline_depth': SettingUInt64, 'max_ast_depth': SettingUInt64, 'max_ast_elements': SettingUInt64, 'max_expanded_ast_elements': SettingUInt64, 'readonly': SettingUInt64, 'max_rows_in_set': SettingUInt64, 'max_bytes_in_set': SettingUInt64, 'set_overflow_mode': SettingString, 'max_rows_in_join': SettingUInt64, 'max_bytes_in_join': SettingUInt64, 'join_overflow_mode': SettingString, 'max_rows_to_transfer': SettingUInt64, 'max_bytes_to_transfer': SettingUInt64, 'transfer_overflow_mode': SettingString, 'max_rows_in_distinct': SettingUInt64, 'max_bytes_in_distinct': SettingUInt64, 'distinct_overflow_mode': SettingString, 'max_memory_usage': SettingUInt64, 'max_memory_usage_for_user': SettingUInt64, 'max_memory_usage_for_all_queries': SettingUInt64, 'max_network_bandwidth': SettingUInt64, 'max_network_bytes': SettingUInt64, 'max_network_bandwidth_for_user': SettingUInt64, 'max_network_bandwidth_for_all_users': SettingUInt64, 'max_streams_multiplier_for_merge_tables': SettingFloat, 'max_http_get_redirects': SettingUInt64, 'max_execution_speed': SettingUInt64, 'max_execution_speed_bytes': SettingUInt64, 'format_csv_delimiter': SettingChar, 'format_csv_allow_single_quotes': SettingBool, 'format_csv_allow_double_quotes': SettingBool, 'format_template_resultset': SettingString, 'format_template_row': SettingString, 'format_template_rows_between_delimiter': SettingString, 'format_custom_escaping_rule': SettingString, 'format_custom_field_delimiter': SettingString, 'format_custom_row_before_delimiter': SettingString, 'format_custom_row_after_delimiter': SettingString, 'format_custom_row_between_delimiter': SettingString, 'format_custom_result_before_delimiter': SettingString, 'format_custom_result_after_delimiter': SettingString, 'enable_conditional_computation': SettingUInt64, 'date_time_input_format': SettingDateTimeInputFormat, 'log_profile_events': SettingBool, 'log_query_settings': SettingBool, 'log_query_threads': SettingBool, 'send_logs_level': SettingString, 'low_cardinality_max_dictionary_size': SettingUInt64, 'low_cardinality_use_single_dictionary_for_part': SettingBool, 'decimal_check_overflow': SettingBool, 'prefer_localhost_replica': SettingBool, 'max_fetch_partition_retries_count': SettingUInt64, 'asterisk_left_columns_only': SettingBool, 'http_max_multipart_form_data_size': SettingUInt64, 'calculate_text_stack_trace': SettingBool, 'parallel_view_processing': SettingBool, 'allow_experimental_low_cardinality_type': SettingBool, 'allow_experimental_decimal_type': SettingBool, 'allow_suspicious_low_cardinality_types': SettingBool, 'allow_experimental_multiple_joins_emulation': SettingBool, 'allow_experimental_cross_to_join_conversion': SettingBool, 'allow_experimental_data_skipping_indices': SettingBool, 'allow_hyperscan': SettingBool, 'allow_simdjson': SettingBool, 'allow_introspection_functions': SettingBool, 'allow_drop_detached': SettingBool, 'allow_experimental_live_view': SettingBool, 'allow_ddl': SettingBool, 'partial_merge_join': SettingBool, 'partial_merge_join_optimizations': SettingBool, 'partial_merge_join_rows_in_right_blocks': SettingUInt64, 'partial_merge_join_rows_in_left_blocks': SettingFloat, 'distributed_replica_error_half_life': SettingSeconds, 'distributed_replica_error_cap': SettingUInt64, 'min_free_disk_space_for_temporary_data': SettingUInt64, 'tcp_keep_alive_timeout': SettingSeconds, 'connection_pool_max_wait_ms': SettingMilliseconds, 'kafka_max_wait_ms': SettingMilliseconds, 'idle_connection_timeout': SettingUInt64, 's3_min_upload_part_size': SettingUInt64, 'any_join_distinct_right_table_keys': SettingBool, 'join_any_take_last_row': SettingBool, 'stream_poll_timeout_ms': SettingMilliseconds, 'joined_subquery_requires_alias': SettingBool, 'enable_unaligned_array_join': SettingBool, 'low_cardinality_allow_in_native_format': SettingBool, 'external_table_functions_use_nulls': SettingBool, 'experimental_use_processors': SettingBool, 'check_query_single_value_result': SettingBool, 'live_view_heartbeat_interval': SettingSeconds, 'temporary_live_view_timeout': SettingSeconds, 'max_live_view_insert_blocks_before_refresh': SettingUInt64, 'max_insert_threads': SettingUInt64, 'replace_running_query_max_wait_ms': SettingMilliseconds, 'background_move_pool_size': SettingUInt64, 'min_count_to_compile_expression': SettingUInt64, 'force_optimize_skip_unused_shards': SettingUInt64, 'input_format_parallel_parsing': SettingBool, 'min_chunk_bytes_for_parallel_parsing': SettingUInt64, 'min_bytes_to_use_mmap_io': SettingUInt64, 'os_thread_priority': SettingInt64, 'input_format_tsv_empty_as_default': SettingBool, 'input_format_avro_schema_registry_url': SettingString, 'output_format_avro_codec': SettingString, 'output_format_avro_sync_interval': SettingUInt64, 'min_execution_speed_bytes': SettingUInt64, 'default_max_bytes_in_join': SettingUInt64, 'enable_optimize_predicate_expression_to_final_subquery': SettingBool, 'cancel_http_readonly_queries_on_client_close': SettingBool, 'enable_scalar_subquery_optimization': SettingBool, 'optimize_trivial_count_query': SettingBool, 'mutations_sync': SettingUInt64, 'optimize_if_chain_to_miltiif': SettingBool, 'max_parser_depth': SettingUInt64, 'max_joined_block_size_rows': SettingUInt64, 'connect_timeout_with_failover_secure_ms': SettingMilliseconds, 'parallel_distributed_insert_select': SettingBool, 'force_optimize_skip_unused_shards_no_nested': SettingBool, 'format_avro_schema_registry_url': SettingURI, 'output_format_tsv_crlf_end_of_line': SettingBool, 'join_algorithm': SettingJoinAlgorithm, 'memory_profiler_step': SettingUInt64, 'output_format_csv_crlf_end_of_line': SettingBool, 'allow_experimental_alter_materialized_view_structure': SettingBool, 'enable_early_constant_folding': SettingBool, 'deduplicate_blocks_in_dependent_materialized_views': SettingBool, 'use_compact_format_in_distributed_parts_names': SettingBool, 'multiple_joins_rewriter_version': SettingUInt64, 'min_insert_block_size_rows_for_materialized_views': SettingUInt64, 'min_insert_block_size_bytes_for_materialized_views': SettingUInt64, 'max_final_threads': SettingUInt64, 'background_buffer_flush_schedule_pool_size': SettingUInt64, 'background_distributed_schedule_pool_size': SettingUInt64, 'special_sort': SettingSpecialSort, 'optimize_distributed_group_by_sharding_key': SettingBool, 'log_queries_min_type': SettingLogQueriesType, 'allow_suspicious_codecs': SettingBool, 'metrics_perf_events_enabled': SettingBool, 'metrics_perf_events_list': SettingString, 'join_on_disk_max_files_to_merge': SettingUInt64, 'temporary_files_codec': SettingString, 'max_untracked_memory': SettingUInt64, 'memory_profiler_sample_probability': SettingFloat, 'optimize_aggregation_in_order': SettingBool, 'default_database_engine': SettingDefaultDatabaseEngine, 'allow_experimental_database_atomic': SettingBool, 'show_table_uuid_in_table_create_query_if_not_nil': SettingBool, 'optimize_arithmetic_operations_in_aggregate_functions': SettingBool, 'validate_polygons': SettingBool, 'transform_null_in': SettingBool, 'allow_nondeterministic_mutations': SettingBool, 'lock_acquire_timeout': SettingSeconds, 'materialize_ttl_after_modify': SettingBool, 'allow_experimental_geo_types': SettingBool, 'output_format_pretty_max_value_width': SettingUInt64, 'format_regexp': SettingString, 'format_regexp_escaping_rule': SettingString, 'format_regexp_skip_unmatched': SettingBool, 'output_format_enable_streaming': SettingBool, } python-clickhouse-driver-0.2.3/clickhouse_driver/settings/types.py000066400000000000000000000021241420676740400255500ustar00rootroot00000000000000from ..util.helpers import asbool from ..varint import write_varint from ..writer import write_binary_str class SettingType(object): @classmethod def write(cls, value, buf): raise NotImplementedError class SettingUInt64(SettingType): @classmethod def write(cls, value, buf): write_varint(int(value), buf) class SettingBool(SettingType): @classmethod def write(cls, value, buf): write_varint(asbool(value), buf) class SettingString(SettingType): @classmethod def write(cls, value, buf): write_binary_str(value, buf) class SettingChar(SettingType): @classmethod def write(cls, value, buf): write_binary_str(value[0], buf) class SettingFloat(SettingType): @classmethod def write(cls, value, buf): """ Float is written in string representation. """ write_binary_str(str(value), buf) class SettingMaxThreads(SettingUInt64): @classmethod def write(cls, value, buf): if value == 'auto': value = 0 super(SettingMaxThreads, cls).write(value, buf) python-clickhouse-driver-0.2.3/clickhouse_driver/settings/writer.py000066400000000000000000000020501420676740400257160ustar00rootroot00000000000000import logging from ..writer import write_binary_str, write_binary_uint8 from .available import settings as available_settings logger = logging.getLogger(__name__) def write_settings(settings, buf, settings_as_strings, is_important=False): for setting, value in (settings or {}).items(): # If the server support settings as string we do not need to know # anything about them, so we can write any setting. if settings_as_strings: write_binary_str(setting, buf) write_binary_uint8(int(is_important), buf) write_binary_str(str(value), buf) else: # If the server requires string in binary, # then they cannot be written without type. setting_writer = available_settings.get(setting) if not setting_writer: logger.warning('Unknown setting %s. Skipping', setting) continue write_binary_str(setting, buf) setting_writer.write(value, buf) write_binary_str('', buf) # end of settings python-clickhouse-driver-0.2.3/clickhouse_driver/streams/000077500000000000000000000000001420676740400236515ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/streams/__init__.py000066400000000000000000000000001420676740400257500ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/streams/compressed.py000066400000000000000000000054611420676740400263750ustar00rootroot00000000000000from io import BytesIO try: from clickhouse_cityhash.cityhash import CityHash128 except ImportError: raise RuntimeError( 'Package clickhouse-cityhash is required to use compression' ) from .native import BlockOutputStream, BlockInputStream from ..bufferedreader import CompressedBufferedReader from ..bufferedwriter import CompressedBufferedWriter from ..compression import get_decompressor_cls from ..defines import BUFFER_SIZE from ..reader import read_binary_uint8, read_binary_uint128 from ..writer import write_binary_uint8, write_binary_uint128 class CompressedBlockOutputStream(BlockOutputStream): def __init__(self, compressor_cls, compress_block_size, fout, context): self.compressor_cls = compressor_cls self.compress_block_size = compress_block_size self.raw_fout = fout self.compressor = self.compressor_cls() self.fout = CompressedBufferedWriter(self.compressor, BUFFER_SIZE) super(CompressedBlockOutputStream, self).__init__(self.fout, context) def get_compressed_hash(self, data): return CityHash128(data) def finalize(self): self.fout.flush() compressed = self.get_compressed() compressed_size = len(compressed) compressed_hash = self.get_compressed_hash(compressed) write_binary_uint128(compressed_hash, self.raw_fout) block_size = self.compress_block_size i = 0 while i < compressed_size: self.raw_fout.write(compressed[i:i + block_size]) i += block_size self.raw_fout.flush() def get_compressed(self): compressed = BytesIO() if self.compressor.method_byte is not None: write_binary_uint8(self.compressor.method_byte, compressed) extra_header_size = 1 # method else: extra_header_size = 0 data = self.compressor.get_compressed_data(extra_header_size) compressed.write(data) return compressed.getvalue() class CompressedBlockInputStream(BlockInputStream): def __init__(self, fin, context): self.raw_fin = fin fin = CompressedBufferedReader(self.read_block, BUFFER_SIZE) super(CompressedBlockInputStream, self).__init__(fin, context) def get_compressed_hash(self, data): return CityHash128(data) def read_block(self): compressed_hash = read_binary_uint128(self.raw_fin) method_byte = read_binary_uint8(self.raw_fin) decompressor_cls = get_decompressor_cls(method_byte) decompressor = decompressor_cls(self.raw_fin) if decompressor.method_byte is not None: extra_header_size = 1 # method else: extra_header_size = 0 return decompressor.get_decompressed_data( method_byte, compressed_hash, extra_header_size ) python-clickhouse-driver-0.2.3/clickhouse_driver/streams/native.py000066400000000000000000000052031420676740400255110ustar00rootroot00000000000000from ..block import ColumnOrientedBlock, BlockInfo from ..columns.service import read_column, write_column from ..reader import read_binary_str from ..varint import write_varint, read_varint from ..writer import write_binary_str from .. import defines class BlockOutputStream(object): def __init__(self, fout, context): self.fout = fout self.context = context super(BlockOutputStream, self).__init__() def write(self, block): revision = self.context.server_info.revision if revision >= defines.DBMS_MIN_REVISION_WITH_BLOCK_INFO: block.info.write(self.fout) # We write transposed data. n_columns = block.num_columns n_rows = block.num_rows write_varint(n_columns, self.fout) write_varint(n_rows, self.fout) for i, (col_name, col_type) in enumerate(block.columns_with_types): write_binary_str(col_name, self.fout) write_binary_str(col_type, self.fout) if n_columns: try: items = block.get_column_by_index(i) except IndexError: raise ValueError('Different rows length') write_column(self.context, col_name, col_type, items, self.fout, types_check=block.types_check) self.finalize() def finalize(self): self.fout.flush() class BlockInputStream(object): def __init__(self, fin, context): self.fin = fin self.context = context super(BlockInputStream, self).__init__() def read(self): info = BlockInfo() revision = self.context.server_info.revision if revision >= defines.DBMS_MIN_REVISION_WITH_BLOCK_INFO: info.read(self.fin) n_columns = read_varint(self.fin) n_rows = read_varint(self.fin) data, names, types = [], [], [] for i in range(n_columns): column_name = read_binary_str(self.fin) column_type = read_binary_str(self.fin) names.append(column_name) types.append(column_type) if n_rows: column = read_column(self.context, column_type, n_rows, self.fin) data.append(column) if self.context.client_settings['use_numpy']: from ..numpy.block import NumpyColumnOrientedBlock block_cls = NumpyColumnOrientedBlock else: block_cls = ColumnOrientedBlock block = block_cls( columns_with_types=list(zip(names, types)), data=data, info=info, ) return block python-clickhouse-driver-0.2.3/clickhouse_driver/util/000077500000000000000000000000001420676740400231505ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/util/__init__.py000066400000000000000000000000001420676740400252470ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/clickhouse_driver/util/compat.py000066400000000000000000000012671420676740400250130ustar00rootroot00000000000000 # Drop this when minimum supported version will be 3.7. try: import threading except ImportError: import dummy_threading as threading # noqa: F401 try: # since tzlocal 4.0+ # this will avoid warning for get_localzone().key from tzlocal import get_localzone_name def get_localzone_name_compat(): try: return get_localzone_name() except Exception: return None except ImportError: from tzlocal import get_localzone def get_localzone_name_compat(): try: return get_localzone().key except AttributeError: return get_localzone().zone except Exception: return None python-clickhouse-driver-0.2.3/clickhouse_driver/util/escape.py000066400000000000000000000026551420676740400247720ustar00rootroot00000000000000from datetime import date, datetime from enum import Enum from uuid import UUID from pytz import timezone escape_chars_map = { "\b": "\\b", "\f": "\\f", "\r": "\\r", "\n": "\\n", "\t": "\\t", "\0": "\\0", "\a": "\\a", "\v": "\\v", "\\": "\\\\", "'": "\\'" } def escape_datetime(item, context): server_tz = timezone(context.server_info.timezone) if item.tzinfo is not None: item = item.astimezone(server_tz) return "'%s'" % item.strftime('%Y-%m-%d %H:%M:%S') def escape_param(item, context): if item is None: return 'NULL' elif isinstance(item, datetime): return escape_datetime(item, context) elif isinstance(item, date): return "'%s'" % item.strftime('%Y-%m-%d') elif isinstance(item, str): return "'%s'" % ''.join(escape_chars_map.get(c, c) for c in item) elif isinstance(item, list): return "[%s]" % ', '.join(str(escape_param(x, context)) for x in item) elif isinstance(item, tuple): return "(%s)" % ', '.join(str(escape_param(x, context)) for x in item) elif isinstance(item, Enum): return escape_param(item.value, context) elif isinstance(item, UUID): return "'%s'" % str(item) else: return item def escape_params(params, context): escaped = {} for key, value in params.items(): escaped[key] = escape_param(value, context) return escaped python-clickhouse-driver-0.2.3/clickhouse_driver/util/helpers.py000066400000000000000000000026501420676740400251670ustar00rootroot00000000000000from itertools import islice, tee def chunks(seq, n): # islice is MUCH slower than slice for lists and tuples. if isinstance(seq, (list, tuple)): i = 0 item = seq[i:i+n] while item: yield list(item) i += n item = seq[i:i+n] else: it = iter(seq) item = list(islice(it, n)) while item: yield item item = list(islice(it, n)) def pairwise(iterable): a, b = tee(iterable) next(b, None) return zip(a, b) def column_chunks(columns, n): for column in columns: if not isinstance(column, (list, tuple)): raise TypeError( 'Unsupported column type: {}. list or tuple is expected.' .format(type(column)) ) # create chunk generator for every column g = [chunks(column, n) for column in columns] while True: # get next chunk for every column item = [next(column, []) for column in g] if not any(item): break yield item # from paste.deploy.converters def asbool(obj): if isinstance(obj, str): obj = obj.strip().lower() if obj in ['true', 'yes', 'on', 'y', 't', '1']: return True elif obj in ['false', 'no', 'off', 'n', 'f', '0']: return False else: raise ValueError('String is not true/false: %r' % obj) return bool(obj) python-clickhouse-driver-0.2.3/clickhouse_driver/varint.c000066400000000000000000004757351420676740400236670ustar00rootroot00000000000000/* Generated by Cython 0.29.21 */ /* BEGIN: Cython Metadata { "distutils": { "depends": [], "name": "clickhouse_driver.varint", "sources": [ "clickhouse_driver/varint.pyx" ] }, "module_name": "clickhouse_driver.varint" } END: Cython Metadata */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else #define CYTHON_ABI "0_29_21" #define CYTHON_HEX_VERSION 0x001D15F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #define __PYX_COMMA , #ifndef HAVE_LONG_LONG #if PY_VERSION_HEX >= 0x02070000 #define HAVE_LONG_LONG #endif #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #if PY_VERSION_HEX < 0x03050000 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #undef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #undef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 1 #undef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 0 #undef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 0 #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #undef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 0 #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #undef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 0 #undef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 0 #undef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYTYPE_LOOKUP #define CYTHON_USE_PYTYPE_LOOKUP 0 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) #define CYTHON_USE_PYTYPE_LOOKUP 1 #endif #if PY_MAJOR_VERSION < 3 #undef CYTHON_USE_ASYNC_SLOTS #define CYTHON_USE_ASYNC_SLOTS 0 #elif !defined(CYTHON_USE_ASYNC_SLOTS) #define CYTHON_USE_ASYNC_SLOTS 1 #endif #if PY_VERSION_HEX < 0x02070000 #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 #endif #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif #if PY_VERSION_HEX < 0x030300F0 #undef CYTHON_USE_UNICODE_WRITER #define CYTHON_USE_UNICODE_WRITER 0 #elif !defined(CYTHON_USE_UNICODE_WRITER) #define CYTHON_USE_UNICODE_WRITER 1 #endif #ifndef CYTHON_AVOID_BORROWED_REFS #define CYTHON_AVOID_BORROWED_REFS 0 #endif #ifndef CYTHON_ASSUME_SAFE_MACROS #define CYTHON_ASSUME_SAFE_MACROS 1 #endif #ifndef CYTHON_UNPACK_METHODS #define CYTHON_UNPACK_METHODS 1 #endif #ifndef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 1 #endif #ifndef CYTHON_FAST_PYCALL #define CYTHON_FAST_PYCALL 1 #endif #ifndef CYTHON_PEP489_MULTI_PHASE_INIT #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) #endif #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #ifndef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) #endif #endif #if !defined(CYTHON_FAST_PYCCALL) #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) #endif #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #undef SHIFT #undef BASE #undef MASK #ifdef SIZEOF_VOID_P enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; #endif #endif #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_cpp_attribute #define __has_cpp_attribute(x) 0 #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif #ifndef CYTHON_MAYBE_UNUSED_VAR # if defined(__cplusplus) template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } # else # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) # endif #endif #ifndef CYTHON_NCP_UNUSED # if CYTHON_COMPILING_IN_CPYTHON # define CYTHON_NCP_UNUSED # else # define CYTHON_NCP_UNUSED CYTHON_UNUSED # endif #endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifdef _MSC_VER #ifndef _MSC_STDINT_H_ #if _MSC_VER < 1300 typedef unsigned char uint8_t; typedef unsigned int uint32_t; #else typedef unsigned __int8 uint8_t; typedef unsigned __int32 uint32_t; #endif #endif #else #include #endif #ifndef CYTHON_FALLTHROUGH #if defined(__cplusplus) && __cplusplus >= 201103L #if __has_cpp_attribute(fallthrough) #define CYTHON_FALLTHROUGH [[fallthrough]] #elif __has_cpp_attribute(clang::fallthrough) #define CYTHON_FALLTHROUGH [[clang::fallthrough]] #elif __has_cpp_attribute(gnu::fallthrough) #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] #endif #endif #ifndef CYTHON_FALLTHROUGH #if __has_attribute(fallthrough) #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) #else #define CYTHON_FALLTHROUGH #endif #endif #if defined(__clang__ ) && defined(__apple_build_version__) #if __apple_build_version__ < 7000000 #undef CYTHON_FALLTHROUGH #define CYTHON_FALLTHROUGH #endif #endif #endif #ifndef CYTHON_INLINE #if defined(__clang__) #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) #elif defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif #ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif #ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #ifndef METH_STACKLESS #define METH_STACKLESS 0 #endif #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) #ifndef METH_FASTCALL #define METH_FASTCALL 0x80 #endif typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames); #else #define __Pyx_PyCFunctionFast _PyCFunctionFast #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) #define PyObject_Realloc(p) PyMem_Realloc(p) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 #define PyMem_RawMalloc(n) PyMem_Malloc(n) #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) #define PyMem_RawFree(p) PyMem_Free(p) #endif #if CYTHON_COMPILING_IN_PYSTON #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) #else #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) #endif #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #elif PY_VERSION_HEX >= 0x03060000 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() #elif PY_VERSION_HEX >= 0x03000000 #define __Pyx_PyThreadState_Current PyThreadState_GET() #else #define __Pyx_PyThreadState_Current _PyThreadState_Current #endif #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) #include "pythread.h" #define Py_tss_NEEDS_INIT 0 typedef int Py_tss_t; static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { *key = PyThread_create_key(); return 0; } static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); *key = Py_tss_NEEDS_INIT; return key; } static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { PyObject_Free(key); } static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { return *key != Py_tss_NEEDS_INIT; } static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { PyThread_delete_key(*key); *key = Py_tss_NEEDS_INIT; } static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { return PyThread_set_key_value(*key, value); } static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { return PyThread_get_key_value(*key); } #endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else #define __Pyx_PyDict_NewPresized(n) PyDict_New() #endif #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) #else #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) #else #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 #define PyUnicode_1BYTE_KIND 1 #define PyUnicode_2BYTE_KIND 2 #define PyUnicode_4BYTE_KIND 4 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #endif #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)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) #define PyObject_ASCII(o) PyObject_Repr(o) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #if PY_VERSION_HEX >= 0x030900A4 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) #else #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) #endif #if CYTHON_ASSUME_SAFE_MACROS #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) #else #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) #endif #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #if CYTHON_USE_ASYNC_SLOTS #if PY_VERSION_HEX >= 0x030500B1 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #else #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #endif #else #define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef __Pyx_PyAsyncMethodsStruct typedef struct { unaryfunc am_await; unaryfunc am_aiter; unaryfunc am_anext; } __Pyx_PyAsyncMethodsStruct; #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) #define __Pyx_truncl trunc #else #define __Pyx_truncl truncl #endif #define __PYX_MARK_ERR_POS(f_index, lineno) \ { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } #define __PYX_ERR(f_index, lineno, Ln_error) \ { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #define __PYX_HAVE__clickhouse_driver__varint #define __PYX_HAVE_API__clickhouse_driver__varint /* Early includes */ #include #include #include "pythread.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) #define CYTHON_WITHOUT_ASSERTIONS #endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_uchar_cast(c) ((unsigned char)c) #define __Pyx_long_cast(x) ((long)x) #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ (sizeof(type) < sizeof(Py_ssize_t)) ||\ (sizeof(type) > sizeof(Py_ssize_t) &&\ likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX) &&\ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ v == (type)PY_SSIZE_T_MIN))) ||\ (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { return (size_t) i < (size_t) limit; } #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) #elif SIZEOF_INT >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) #elif defined (_MSC_VER) #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) #define __Pyx_sst_abs(value) __builtin_llabs(value) #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); #define __Pyx_PySequence_Tuple(obj)\ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_ASSUME_SAFE_MACROS #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) #else #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) #endif #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } static PyObject *__pyx_m = NULL; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_cython_runtime = NULL; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "clickhouse_driver/varint.pyx", "type.pxd", "bool.pxd", "complex.pxd", }; /*--- Type declarations ---*/ /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil)\ if (acquire_gil) {\ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ PyGILState_Release(__pyx_gilstate_save);\ } else {\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_XDECREF(tmp);\ } while (0) #define __Pyx_DECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); /* PyObjectGetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif /* PyCFunctionFastCall.proto */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); #else #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) #endif /* PyFunctionFastCall.proto */ #if CYTHON_FAST_PYCALL #define __Pyx_PyFunction_FastCall(func, args, nargs)\ __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); #else #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) #endif #define __Pyx_BUILD_ASSERT_EXPR(cond)\ (sizeof(char [1 - 2*!(cond)]) - 1) #ifndef Py_MEMBER_SIZE #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) #endif static size_t __pyx_pyframe_localsplus_offset = 0; #include "frameobject.h" #define __Pxy_PyFrame_Initialize_Offsets()\ ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) #define __Pyx_PyFrame_GetLocalsplus(frame)\ (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) #endif /* PyObjectCall.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif /* PyObjectCall2Args.proto */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /* PyObjectCallMethO.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); #endif /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyObjectCallNoArg.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #else #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* PyDictVersioning.proto */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ (version_var) = __PYX_GET_DICT_VERSION(dict);\ (cache_var) = (value); #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ (VAR) = __pyx_dict_cached_value;\ } else {\ (VAR) = __pyx_dict_cached_value = (LOOKUP);\ __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ }\ } static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); #else #define __PYX_GET_DICT_VERSION(dict) (0) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); #endif /* PyThreadStateGet.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type #else #define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_assign #define __Pyx_PyErr_Occurred() PyErr_Occurred() #endif /* PyErrFetchRestore.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) #else #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #endif #else #define __Pyx_PyErr_Clear() PyErr_Clear() #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) #endif /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) #else static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); #endif /* CodeObjectCache.proto */ typedef struct { PyCodeObject* code_object; int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); /* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value); /* CIntFromPy.proto */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* FastTypeChecks.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); #else #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /* Module declarations from 'cpython.version' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.type' */ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'libc.string' */ /* Module declarations from 'libc.stdio' */ /* Module declarations from 'cpython.object' */ /* Module declarations from 'cpython.ref' */ /* Module declarations from 'cpython.exc' */ /* Module declarations from 'cpython.module' */ /* Module declarations from 'cpython.mem' */ /* Module declarations from 'cpython.tuple' */ /* Module declarations from 'cpython.list' */ /* Module declarations from 'cpython.sequence' */ /* Module declarations from 'cpython.mapping' */ /* Module declarations from 'cpython.iterator' */ /* Module declarations from 'cpython.number' */ /* Module declarations from 'cpython.int' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; /* Module declarations from 'cpython.long' */ /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ /* Module declarations from 'cpython.complex' */ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.string' */ /* Module declarations from 'cpython.unicode' */ /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ /* Module declarations from 'cpython.function' */ /* Module declarations from 'cpython.method' */ /* Module declarations from 'cpython.weakref' */ /* Module declarations from 'cpython.getargs' */ /* Module declarations from 'cpython.pythread' */ /* Module declarations from 'cpython.pystate' */ /* Module declarations from 'cpython.cobject' */ /* Module declarations from 'cpython.oldbuffer' */ /* Module declarations from 'cpython.set' */ /* Module declarations from 'cpython.buffer' */ /* Module declarations from 'cpython.bytes' */ /* Module declarations from 'cpython.pycapsule' */ /* Module declarations from 'cpython' */ /* Module declarations from 'clickhouse_driver.varint' */ #define __Pyx_MODULE_NAME "clickhouse_driver.varint" extern int __pyx_module_is_main_clickhouse_driver__varint; int __pyx_module_is_main_clickhouse_driver__varint = 0; /* Implementation of 'clickhouse_driver.varint' */ static const char __pyx_k_f[] = "f"; static const char __pyx_k_i[] = "i"; static const char __pyx_k_buf[] = "buf"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_shift[] = "shift"; static const char __pyx_k_write[] = "write"; static const char __pyx_k_number[] = "number"; static const char __pyx_k_result[] = "result"; static const char __pyx_k_num_buf[] = "num_buf"; static const char __pyx_k_read_one[] = "read_one"; static const char __pyx_k_to_write[] = "to_write"; static const char __pyx_k_make_varint[] = "make_varint"; static const char __pyx_k_read_varint[] = "read_varint"; static const char __pyx_k_write_varint[] = "write_varint"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_clickhouse_driver_varint[] = "clickhouse_driver.varint"; static const char __pyx_k_clickhouse_driver_varint_pyx[] = "clickhouse_driver/varint.pyx"; static PyObject *__pyx_n_s_buf; static PyObject *__pyx_n_s_clickhouse_driver_varint; static PyObject *__pyx_kp_s_clickhouse_driver_varint_pyx; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_f; static PyObject *__pyx_n_s_i; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_make_varint; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_num_buf; static PyObject *__pyx_n_s_number; static PyObject *__pyx_n_s_read_one; static PyObject *__pyx_n_s_read_varint; static PyObject *__pyx_n_s_result; static PyObject *__pyx_n_s_shift; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_to_write; static PyObject *__pyx_n_s_write; static PyObject *__pyx_n_s_write_varint; static PyObject *__pyx_pf_17clickhouse_driver_6varint_make_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2write_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number, PyObject *__pyx_v_buf); /* proto */ static PyObject *__pyx_pf_17clickhouse_driver_6varint_4read_varint(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f); /* proto */ static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__5; static PyObject *__pyx_codeobj__2; static PyObject *__pyx_codeobj__4; static PyObject *__pyx_codeobj__6; /* Late includes */ /* "clickhouse_driver/varint.pyx":4 * * * def make_varint(unsigned long long number): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_6varint_1make_varint(PyObject *__pyx_self, PyObject *__pyx_arg_number); /*proto*/ static char __pyx_doc_17clickhouse_driver_6varint_make_varint[] = "\n Writes integer of variable length using LEB128.\n "; static PyMethodDef __pyx_mdef_17clickhouse_driver_6varint_1make_varint = {"make_varint", (PyCFunction)__pyx_pw_17clickhouse_driver_6varint_1make_varint, METH_O, __pyx_doc_17clickhouse_driver_6varint_make_varint}; static PyObject *__pyx_pw_17clickhouse_driver_6varint_1make_varint(PyObject *__pyx_self, PyObject *__pyx_arg_number) { unsigned PY_LONG_LONG __pyx_v_number; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("make_varint (wrapper)", 0); assert(__pyx_arg_number); { __pyx_v_number = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_arg_number); if (unlikely((__pyx_v_number == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 4, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.varint.make_varint", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_6varint_make_varint(__pyx_self, ((unsigned PY_LONG_LONG)__pyx_v_number)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_6varint_make_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number) { unsigned char __pyx_v_to_write; unsigned char __pyx_v_i; unsigned char __pyx_v_num_buf[32]; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("make_varint", 0); /* "clickhouse_driver/varint.pyx":8 * Writes integer of variable length using LEB128. * """ * cdef unsigned char to_write, i = 0 # <<<<<<<<<<<<<< * # unsigned PY_LONG_LONG checks integer on function call and * # raises OverflowError if integer overflows unsigned PY_LONG_LONG. */ __pyx_v_i = 0; /* "clickhouse_driver/varint.pyx":14 * cdef unsigned char num_buf[32] * * while True: # <<<<<<<<<<<<<< * to_write = number & 0x7f * number >>= 7 */ while (1) { /* "clickhouse_driver/varint.pyx":15 * * while True: * to_write = number & 0x7f # <<<<<<<<<<<<<< * number >>= 7 * if number: */ __pyx_v_to_write = (__pyx_v_number & 0x7f); /* "clickhouse_driver/varint.pyx":16 * while True: * to_write = number & 0x7f * number >>= 7 # <<<<<<<<<<<<<< * if number: * num_buf[i] = to_write | 0x80 */ __pyx_v_number = (__pyx_v_number >> 7); /* "clickhouse_driver/varint.pyx":17 * to_write = number & 0x7f * number >>= 7 * if number: # <<<<<<<<<<<<<< * num_buf[i] = to_write | 0x80 * i += 1 */ __pyx_t_1 = (__pyx_v_number != 0); if (__pyx_t_1) { /* "clickhouse_driver/varint.pyx":18 * number >>= 7 * if number: * num_buf[i] = to_write | 0x80 # <<<<<<<<<<<<<< * i += 1 * else: */ (__pyx_v_num_buf[__pyx_v_i]) = (__pyx_v_to_write | 0x80); /* "clickhouse_driver/varint.pyx":19 * if number: * num_buf[i] = to_write | 0x80 * i += 1 # <<<<<<<<<<<<<< * else: * num_buf[i] = to_write */ __pyx_v_i = (__pyx_v_i + 1); /* "clickhouse_driver/varint.pyx":17 * to_write = number & 0x7f * number >>= 7 * if number: # <<<<<<<<<<<<<< * num_buf[i] = to_write | 0x80 * i += 1 */ goto __pyx_L5; } /* "clickhouse_driver/varint.pyx":21 * i += 1 * else: * num_buf[i] = to_write # <<<<<<<<<<<<<< * i += 1 * break */ /*else*/ { (__pyx_v_num_buf[__pyx_v_i]) = __pyx_v_to_write; /* "clickhouse_driver/varint.pyx":22 * else: * num_buf[i] = to_write * i += 1 # <<<<<<<<<<<<<< * break * */ __pyx_v_i = (__pyx_v_i + 1); /* "clickhouse_driver/varint.pyx":23 * num_buf[i] = to_write * i += 1 * break # <<<<<<<<<<<<<< * * return PyBytes_FromStringAndSize(num_buf, i) */ goto __pyx_L4_break; } __pyx_L5:; } __pyx_L4_break:; /* "clickhouse_driver/varint.pyx":25 * break * * return PyBytes_FromStringAndSize(num_buf, i) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyBytes_FromStringAndSize(((char *)__pyx_v_num_buf), __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "clickhouse_driver/varint.pyx":4 * * * def make_varint(unsigned long long number): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("clickhouse_driver.varint.make_varint", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/varint.pyx":28 * * * def write_varint(unsigned long long number, buf): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_6varint_3write_varint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_17clickhouse_driver_6varint_2write_varint[] = "\n Writes integer of variable length using LEB128.\n "; static PyMethodDef __pyx_mdef_17clickhouse_driver_6varint_3write_varint = {"write_varint", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_6varint_3write_varint, METH_VARARGS|METH_KEYWORDS, __pyx_doc_17clickhouse_driver_6varint_2write_varint}; static PyObject *__pyx_pw_17clickhouse_driver_6varint_3write_varint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned PY_LONG_LONG __pyx_v_number; PyObject *__pyx_v_buf = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_varint (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_buf,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_buf)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("write_varint", 1, 2, 2, 1); __PYX_ERR(0, 28, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "write_varint") < 0)) __PYX_ERR(0, 28, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_number = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_number == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) __pyx_v_buf = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("write_varint", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 28, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("clickhouse_driver.varint.write_varint", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_17clickhouse_driver_6varint_2write_varint(__pyx_self, __pyx_v_number, __pyx_v_buf); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_6varint_2write_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number, PyObject *__pyx_v_buf) { unsigned char __pyx_v_to_write; unsigned char __pyx_v_i; unsigned char __pyx_v_num_buf[32]; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_varint", 0); /* "clickhouse_driver/varint.pyx":32 * Writes integer of variable length using LEB128. * """ * cdef unsigned char to_write, i = 0 # <<<<<<<<<<<<<< * # unsigned PY_LONG_LONG checks integer on function call and * # raises OverflowError if integer overflows unsigned PY_LONG_LONG. */ __pyx_v_i = 0; /* "clickhouse_driver/varint.pyx":38 * cdef unsigned char num_buf[32] * * while True: # <<<<<<<<<<<<<< * to_write = number & 0x7f * number >>= 7 */ while (1) { /* "clickhouse_driver/varint.pyx":39 * * while True: * to_write = number & 0x7f # <<<<<<<<<<<<<< * number >>= 7 * if number: */ __pyx_v_to_write = (__pyx_v_number & 0x7f); /* "clickhouse_driver/varint.pyx":40 * while True: * to_write = number & 0x7f * number >>= 7 # <<<<<<<<<<<<<< * if number: * num_buf[i] = to_write | 0x80 */ __pyx_v_number = (__pyx_v_number >> 7); /* "clickhouse_driver/varint.pyx":41 * to_write = number & 0x7f * number >>= 7 * if number: # <<<<<<<<<<<<<< * num_buf[i] = to_write | 0x80 * i += 1 */ __pyx_t_1 = (__pyx_v_number != 0); if (__pyx_t_1) { /* "clickhouse_driver/varint.pyx":42 * number >>= 7 * if number: * num_buf[i] = to_write | 0x80 # <<<<<<<<<<<<<< * i += 1 * else: */ (__pyx_v_num_buf[__pyx_v_i]) = (__pyx_v_to_write | 0x80); /* "clickhouse_driver/varint.pyx":43 * if number: * num_buf[i] = to_write | 0x80 * i += 1 # <<<<<<<<<<<<<< * else: * num_buf[i] = to_write */ __pyx_v_i = (__pyx_v_i + 1); /* "clickhouse_driver/varint.pyx":41 * to_write = number & 0x7f * number >>= 7 * if number: # <<<<<<<<<<<<<< * num_buf[i] = to_write | 0x80 * i += 1 */ goto __pyx_L5; } /* "clickhouse_driver/varint.pyx":45 * i += 1 * else: * num_buf[i] = to_write # <<<<<<<<<<<<<< * i += 1 * break */ /*else*/ { (__pyx_v_num_buf[__pyx_v_i]) = __pyx_v_to_write; /* "clickhouse_driver/varint.pyx":46 * else: * num_buf[i] = to_write * i += 1 # <<<<<<<<<<<<<< * break * */ __pyx_v_i = (__pyx_v_i + 1); /* "clickhouse_driver/varint.pyx":47 * num_buf[i] = to_write * i += 1 * break # <<<<<<<<<<<<<< * * buf.write(PyBytes_FromStringAndSize(num_buf, i)) */ goto __pyx_L4_break; } __pyx_L5:; } __pyx_L4_break:; /* "clickhouse_driver/varint.pyx":49 * break * * buf.write(PyBytes_FromStringAndSize(num_buf, i)) # <<<<<<<<<<<<<< * * */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_buf, __pyx_n_s_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyBytes_FromStringAndSize(((char *)__pyx_v_num_buf), __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "clickhouse_driver/varint.pyx":28 * * * def write_varint(unsigned long long number, buf): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("clickhouse_driver.varint.write_varint", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "clickhouse_driver/varint.pyx":52 * * * def read_varint(f): # <<<<<<<<<<<<<< * """ * Reads integer of variable length using LEB128. */ /* Python wrapper */ static PyObject *__pyx_pw_17clickhouse_driver_6varint_5read_varint(PyObject *__pyx_self, PyObject *__pyx_v_f); /*proto*/ static char __pyx_doc_17clickhouse_driver_6varint_4read_varint[] = "\n Reads integer of variable length using LEB128.\n "; static PyMethodDef __pyx_mdef_17clickhouse_driver_6varint_5read_varint = {"read_varint", (PyCFunction)__pyx_pw_17clickhouse_driver_6varint_5read_varint, METH_O, __pyx_doc_17clickhouse_driver_6varint_4read_varint}; static PyObject *__pyx_pw_17clickhouse_driver_6varint_5read_varint(PyObject *__pyx_self, PyObject *__pyx_v_f) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_varint (wrapper)", 0); __pyx_r = __pyx_pf_17clickhouse_driver_6varint_4read_varint(__pyx_self, ((PyObject *)__pyx_v_f)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_17clickhouse_driver_6varint_4read_varint(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f) { unsigned char __pyx_v_shift; unsigned PY_LONG_LONG __pyx_v_i; unsigned PY_LONG_LONG __pyx_v_result; PyObject *__pyx_v_read_one = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; unsigned PY_LONG_LONG __pyx_t_4; int __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_varint", 0); /* "clickhouse_driver/varint.pyx":56 * Reads integer of variable length using LEB128. * """ * cdef unsigned char shift = 0 # <<<<<<<<<<<<<< * cdef unsigned long long i, result = 0 * */ __pyx_v_shift = 0; /* "clickhouse_driver/varint.pyx":57 * """ * cdef unsigned char shift = 0 * cdef unsigned long long i, result = 0 # <<<<<<<<<<<<<< * * read_one = f.read_one */ __pyx_v_result = 0; /* "clickhouse_driver/varint.pyx":59 * cdef unsigned long long i, result = 0 * * read_one = f.read_one # <<<<<<<<<<<<<< * * while True: */ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_read_one); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_read_one = __pyx_t_1; __pyx_t_1 = 0; /* "clickhouse_driver/varint.pyx":61 * read_one = f.read_one * * while True: # <<<<<<<<<<<<<< * i = read_one() * result |= (i & 0x7f) << shift */ while (1) { /* "clickhouse_driver/varint.pyx":62 * * while True: * i = read_one() # <<<<<<<<<<<<<< * result |= (i & 0x7f) << shift * shift += 7 */ __Pyx_INCREF(__pyx_v_read_one); __pyx_t_2 = __pyx_v_read_one; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_4 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_i = __pyx_t_4; /* "clickhouse_driver/varint.pyx":63 * while True: * i = read_one() * result |= (i & 0x7f) << shift # <<<<<<<<<<<<<< * shift += 7 * if i < 0x80: */ __pyx_v_result = (__pyx_v_result | ((__pyx_v_i & 0x7f) << __pyx_v_shift)); /* "clickhouse_driver/varint.pyx":64 * i = read_one() * result |= (i & 0x7f) << shift * shift += 7 # <<<<<<<<<<<<<< * if i < 0x80: * break */ __pyx_v_shift = (__pyx_v_shift + 7); /* "clickhouse_driver/varint.pyx":65 * result |= (i & 0x7f) << shift * shift += 7 * if i < 0x80: # <<<<<<<<<<<<<< * break * */ __pyx_t_5 = ((__pyx_v_i < 0x80) != 0); if (__pyx_t_5) { /* "clickhouse_driver/varint.pyx":66 * shift += 7 * if i < 0x80: * break # <<<<<<<<<<<<<< * * return result */ goto __pyx_L4_break; /* "clickhouse_driver/varint.pyx":65 * result |= (i & 0x7f) << shift * shift += 7 * if i < 0x80: # <<<<<<<<<<<<<< * break * */ } } __pyx_L4_break:; /* "clickhouse_driver/varint.pyx":68 * break * * return result # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "clickhouse_driver/varint.pyx":52 * * * def read_varint(f): # <<<<<<<<<<<<<< * """ * Reads integer of variable length using LEB128. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("clickhouse_driver.varint.read_varint", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_read_one); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 #if CYTHON_PEP489_MULTI_PHASE_INIT static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ static int __pyx_pymod_exec_varint(PyObject* module); /*proto*/ static PyModuleDef_Slot __pyx_moduledef_slots[] = { {Py_mod_create, (void*)__pyx_pymod_create}, {Py_mod_exec, (void*)__pyx_pymod_exec_varint}, {0, NULL} }; #endif static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, "varint", 0, /* m_doc */ #if CYTHON_PEP489_MULTI_PHASE_INIT 0, /* m_size */ #else -1, /* m_size */ #endif __pyx_methods /* m_methods */, #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_moduledef_slots, /* m_slots */ #else NULL, /* m_reload */ #endif NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif #ifndef CYTHON_SMALL_CODE #if defined(__clang__) #define CYTHON_SMALL_CODE #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) #define CYTHON_SMALL_CODE __attribute__((cold)) #else #define CYTHON_SMALL_CODE #endif #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_buf, __pyx_k_buf, sizeof(__pyx_k_buf), 0, 0, 1, 1}, {&__pyx_n_s_clickhouse_driver_varint, __pyx_k_clickhouse_driver_varint, sizeof(__pyx_k_clickhouse_driver_varint), 0, 0, 1, 1}, {&__pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_k_clickhouse_driver_varint_pyx, sizeof(__pyx_k_clickhouse_driver_varint_pyx), 0, 0, 1, 0}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_make_varint, __pyx_k_make_varint, sizeof(__pyx_k_make_varint), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_num_buf, __pyx_k_num_buf, sizeof(__pyx_k_num_buf), 0, 0, 1, 1}, {&__pyx_n_s_number, __pyx_k_number, sizeof(__pyx_k_number), 0, 0, 1, 1}, {&__pyx_n_s_read_one, __pyx_k_read_one, sizeof(__pyx_k_read_one), 0, 0, 1, 1}, {&__pyx_n_s_read_varint, __pyx_k_read_varint, sizeof(__pyx_k_read_varint), 0, 0, 1, 1}, {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, {&__pyx_n_s_shift, __pyx_k_shift, sizeof(__pyx_k_shift), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_to_write, __pyx_k_to_write, sizeof(__pyx_k_to_write), 0, 0, 1, 1}, {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1}, {&__pyx_n_s_write_varint, __pyx_k_write_varint, sizeof(__pyx_k_write_varint), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { return 0; } static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "clickhouse_driver/varint.pyx":4 * * * def make_varint(unsigned long long number): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ __pyx_tuple_ = PyTuple_Pack(5, __pyx_n_s_number, __pyx_n_s_number, __pyx_n_s_to_write, __pyx_n_s_i, __pyx_n_s_num_buf); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_make_varint, 4, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 4, __pyx_L1_error) /* "clickhouse_driver/varint.pyx":28 * * * def write_varint(unsigned long long number, buf): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ __pyx_tuple__3 = PyTuple_Pack(5, __pyx_n_s_number, __pyx_n_s_buf, __pyx_n_s_to_write, __pyx_n_s_i, __pyx_n_s_num_buf); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_write_varint, 28, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 28, __pyx_L1_error) /* "clickhouse_driver/varint.pyx":52 * * * def read_varint(f): # <<<<<<<<<<<<<< * """ * Reads integer of variable length using LEB128. */ __pyx_tuple__5 = PyTuple_Pack(5, __pyx_n_s_f, __pyx_n_s_shift, __pyx_n_s_i, __pyx_n_s_result, __pyx_n_s_read_one); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_read_varint, 52, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); return 0; __pyx_L1_error:; return -1; } static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ static int __Pyx_modinit_global_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); /*--- Global init code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_variable_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); /*--- Variable export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_export_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); /*--- Function export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_type_import_code(void) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); /*--- Type import code ---*/ __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), #else sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(2, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(3, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_modinit_variable_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); /*--- Variable import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } static int __Pyx_modinit_function_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __Pyx_RefNannyFinishContext(); return 0; } #ifndef CYTHON_NO_PYINIT_EXPORT #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC #elif PY_MAJOR_VERSION < 3 #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" void #else #define __Pyx_PyMODINIT_FUNC void #endif #else #ifdef __cplusplus #define __Pyx_PyMODINIT_FUNC extern "C" PyObject * #else #define __Pyx_PyMODINIT_FUNC PyObject * #endif #endif #if PY_MAJOR_VERSION < 3 __Pyx_PyMODINIT_FUNC initvarint(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC initvarint(void) #else __Pyx_PyMODINIT_FUNC PyInit_varint(void) CYTHON_SMALL_CODE; /*proto*/ __Pyx_PyMODINIT_FUNC PyInit_varint(void) #if CYTHON_PEP489_MULTI_PHASE_INIT { return PyModuleDef_Init(&__pyx_moduledef); } static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { #if PY_VERSION_HEX >= 0x030700A1 static PY_INT64_T main_interpreter_id = -1; PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); if (main_interpreter_id == -1) { main_interpreter_id = current_id; return (unlikely(current_id == -1)) ? -1 : 0; } else if (unlikely(main_interpreter_id != current_id)) #else static PyInterpreterState *main_interpreter = NULL; PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; if (!main_interpreter) { main_interpreter = current_interpreter; } else if (unlikely(main_interpreter != current_interpreter)) #endif { PyErr_SetString( PyExc_ImportError, "Interpreter change detected - this module can only be loaded into one interpreter per process."); return -1; } return 0; } 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) { PyObject *value = PyObject_GetAttrString(spec, from_name); int result = 0; if (likely(value)) { if (allow_none || value != Py_None) { result = PyDict_SetItemString(moddict, to_name, value); } Py_DECREF(value); } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); } else { result = -1; } return result; } static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { PyObject *module = NULL, *moddict, *modname; if (__Pyx_check_single_interpreter()) return NULL; if (__pyx_m) return __Pyx_NewRef(__pyx_m); modname = PyObject_GetAttrString(spec, "name"); if (unlikely(!modname)) goto bad; module = PyModule_NewObject(modname); Py_DECREF(modname); if (unlikely(!module)) goto bad; moddict = PyModule_GetDict(module); if (unlikely(!moddict)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; return module; bad: Py_XDECREF(module); return NULL; } static CYTHON_SMALL_CODE int __pyx_pymod_exec_varint(PyObject *__pyx_pyinit_module) #endif #endif { PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m) { if (__pyx_m == __pyx_pyinit_module) return 0; PyErr_SetString(PyExc_RuntimeError, "Module 'varint' has already been imported. Re-initialisation is not supported."); return -1; } #elif PY_MAJOR_VERSION >= 3 if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_varint(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pxy_PyFrame_Initialize_Offsets __Pxy_PyFrame_Initialize_Offsets(); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_AsyncGen_USED if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if CYTHON_PEP489_MULTI_PHASE_INIT __pyx_m = __pyx_pyinit_module; Py_INCREF(__pyx_m); #else #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("varint", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) #endif __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_clickhouse_driver__varint) { if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "clickhouse_driver.varint")) { if (unlikely(PyDict_SetItemString(modules, "clickhouse_driver.varint", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Global type/function init code ---*/ (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); (void)__Pyx_modinit_function_export_code(); (void)__Pyx_modinit_type_init_code(); if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_variable_import_code(); (void)__Pyx_modinit_function_import_code(); /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /* "clickhouse_driver/varint.pyx":4 * * * def make_varint(unsigned long long number): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_6varint_1make_varint, NULL, __pyx_n_s_clickhouse_driver_varint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_make_varint, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/varint.pyx":28 * * * def write_varint(unsigned long long number, buf): # <<<<<<<<<<<<<< * """ * Writes integer of variable length using LEB128. */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_6varint_3write_varint, NULL, __pyx_n_s_clickhouse_driver_varint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_write_varint, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/varint.pyx":52 * * * def read_varint(f): # <<<<<<<<<<<<<< * """ * Reads integer of variable length using LEB128. */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_6varint_5read_varint, NULL, __pyx_n_s_clickhouse_driver_varint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_varint, __pyx_t_1) < 0) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "clickhouse_driver/varint.pyx":1 * from cpython cimport PyBytes_FromStringAndSize # <<<<<<<<<<<<<< * * */ __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init clickhouse_driver.varint", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init clickhouse_driver.varint"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if CYTHON_PEP489_MULTI_PHASE_INIT return (__pyx_m != NULL) ? 0 : -1; #elif PY_MAJOR_VERSION >= 3 return __pyx_m; #else return; #endif } /* --- Runtime support code --- */ /* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule(modname); if (!m) goto end; p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } /* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } /* PyObjectGetAttrStr */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #endif /* PyCFunctionFastCall */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { PyCFunctionObject *func = (PyCFunctionObject*)func_obj; PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); int flags = PyCFunction_GET_FLAGS(func); assert(PyCFunction_Check(func)); assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); assert(nargs >= 0); assert(nargs == 0 || args != NULL); /* _PyCFunction_FastCallDict() must not be called with an exception set, because it may clear it (directly or indirectly) and so the caller loses its exception */ assert(!PyErr_Occurred()); if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); } else { return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); } } #endif /* PyFunctionFastCall */ #if CYTHON_FAST_PYCALL static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, PyObject *globals) { PyFrameObject *f; PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject **fastlocals; Py_ssize_t i; PyObject *result; assert(globals != NULL); /* XXX Perhaps we should create a specialized PyFrame_New() that doesn't take locals, but does take builtins without sanity checking them. */ assert(tstate != NULL); f = PyFrame_New(tstate, co, globals, NULL); if (f == NULL) { return NULL; } fastlocals = __Pyx_PyFrame_GetLocalsplus(f); for (i = 0; i < na; i++) { Py_INCREF(*args); fastlocals[i] = *args++; } result = PyEval_EvalFrameEx(f,0); ++tstate->recursion_depth; Py_DECREF(f); --tstate->recursion_depth; return result; } #if 1 || PY_VERSION_HEX < 0x030600B1 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *argdefs = PyFunction_GET_DEFAULTS(func); PyObject *closure; #if PY_MAJOR_VERSION >= 3 PyObject *kwdefs; #endif PyObject *kwtuple, **k; PyObject **d; Py_ssize_t nd; Py_ssize_t nk; PyObject *result; assert(kwargs == NULL || PyDict_Check(kwargs)); nk = kwargs ? PyDict_Size(kwargs) : 0; if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { return NULL; } if ( #if PY_MAJOR_VERSION >= 3 co->co_kwonlyargcount == 0 && #endif likely(kwargs == NULL || nk == 0) && co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { if (argdefs == NULL && co->co_argcount == nargs) { result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); goto done; } else if (nargs == 0 && argdefs != NULL && co->co_argcount == Py_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ args = &PyTuple_GET_ITEM(argdefs, 0); result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); goto done; } } if (kwargs != NULL) { Py_ssize_t pos, i; kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) { result = NULL; goto done; } k = &PyTuple_GET_ITEM(kwtuple, 0); pos = i = 0; while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { Py_INCREF(k[i]); Py_INCREF(k[i+1]); i += 2; } nk = i / 2; } else { kwtuple = NULL; k = NULL; } closure = PyFunction_GET_CLOSURE(func); #if PY_MAJOR_VERSION >= 3 kwdefs = PyFunction_GET_KW_DEFAULTS(func); #endif if (argdefs != NULL) { d = &PyTuple_GET_ITEM(argdefs, 0); nd = Py_SIZE(argdefs); } else { d = NULL; nd = 0; } #if PY_MAJOR_VERSION >= 3 result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, kwdefs, closure); #else result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, args, (int)nargs, k, (int)nk, d, (int)nd, closure); #endif Py_XDECREF(kwtuple); done: Py_LeaveRecursiveCall(); return result; } #endif #endif /* PyObjectCall */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; ternaryfunc call = func->ob_type->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCall2Args */ static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { PyObject *args, *result = NULL; #if CYTHON_FAST_PYCALL if (PyFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyFunction_FastCall(function, args, 2); } #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(function)) { PyObject *args[2] = {arg1, arg2}; return __Pyx_PyCFunction_FastCall(function, args, 2); } #endif args = PyTuple_New(2); if (unlikely(!args)) goto done; Py_INCREF(arg1); PyTuple_SET_ITEM(args, 0, arg1); Py_INCREF(arg2); PyTuple_SET_ITEM(args, 1, arg2); Py_INCREF(function); result = __Pyx_PyObject_Call(function, args, NULL); Py_DECREF(args); Py_DECREF(function); done: return result; } /* PyObjectCallMethO */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { PyObject *self, *result; PyCFunction cfunc; cfunc = PyCFunction_GET_FUNCTION(func); self = PyCFunction_GET_SELF(func); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = cfunc(self, arg); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCallOneArg */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_New(1); if (unlikely(!args)) return NULL; Py_INCREF(arg); PyTuple_SET_ITEM(args, 0, arg); result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, &arg, 1); } #endif if (likely(PyCFunction_Check(func))) { if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { return __Pyx_PyObject_CallMethO(func, arg); #if CYTHON_FAST_PYCCALL } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { return __Pyx_PyCFunction_FastCall(func, &arg, 1); #endif } } return __Pyx__PyObject_CallOneArg(func, arg); } #else static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_Pack(1, arg); if (unlikely(!args)) return NULL; result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } #endif /* PyObjectCallNoArg */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) #endif { if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } } return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); } #endif /* TypeImport */ #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) goto bad; basicsize = PyLong_AsSsize_t(py_basicsize); Py_DECREF(py_basicsize); py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; #endif if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); goto bad; } else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { PyOS_snprintf(warning, sizeof(warning), "%s.%s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", module_name, class_name, size, basicsize); if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; } return (PyTypeObject *)result; bad: Py_XDECREF(result); return NULL; } #endif /* PyDictVersioning */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { PyObject *dict = Py_TYPE(obj)->tp_dict; return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; } static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { PyObject **dictptr = NULL; Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; if (offset) { #if CYTHON_COMPILING_IN_CPYTHON dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); #else dictptr = _PyObject_GetDictPtr(obj); #endif } return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; } static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { PyObject *dict = Py_TYPE(obj)->tp_dict; if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) return 0; return obj_dict_version == __Pyx_get_object_dict_version(obj); } #endif /* PyErrFetchRestore */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #endif /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON PyObject **cython_runtime_dict; #endif if (unlikely(!__pyx_cython_runtime)) { return c_line; } __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); #if CYTHON_COMPILING_IN_CPYTHON cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); if (likely(cython_runtime_dict)) { __PYX_PY_DICT_LOOKUP_IF_MODIFIED( use_cline, *cython_runtime_dict, __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) } else #endif { PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); if (use_cline_obj) { use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; Py_DECREF(use_cline_obj); } else { PyErr_Clear(); use_cline = NULL; } } if (!use_cline) { c_line = 0; PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); } else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { c_line = 0; } __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); return c_line; } #endif /* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = start + (end - start) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } /* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; PyThreadState *tstate = __Pyx_PyThreadState_Current; if (c_line) { c_line = __Pyx_CLineForTraceback(tstate, c_line); } py_code = __pyx_find_code_object(c_line ? -c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); } py_frame = PyFrame_New( tstate, /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; __Pyx_PyFrame_SetLineNumber(py_frame, py_line); PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } /* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ {\ func_type value = func_value;\ if (sizeof(target_type) < sizeof(func_type)) {\ if (unlikely(value != (func_type) (target_type) value)) {\ func_type zero = 0;\ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ return (target_type) -1;\ if (is_unsigned && unlikely(value < zero))\ goto raise_neg_overflow;\ else\ goto raise_overflow;\ }\ }\ return (target_type) value;\ } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) { 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; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) { 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; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (unsigned PY_LONG_LONG) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0]) case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) { 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])); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) { 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])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (unsigned PY_LONG_LONG) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (unsigned PY_LONG_LONG) 0; case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, +digits[0]) case -2: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case 2: if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]))); } } break; case -3: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case 3: if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { 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]))); } } break; case -4: if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; case 4: if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { 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]))); } } break; } #endif if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else unsigned PY_LONG_LONG val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (unsigned PY_LONG_LONG) -1; } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (unsigned PY_LONG_LONG) -1; val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG) -1; } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (long) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -3: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -4: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; } #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (int) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -3: if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -4: if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __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]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; } #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } /* FastTypeChecks */ #if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; if (a == b) return 1; } return b == &PyBaseObject_Type; } static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { PyObject *mro; if (a == b) return 1; mro = a->tp_mro; if (likely(mro)) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(mro); for (i = 0; i < n; i++) { if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) return 1; } return 0; } return __Pyx_InBases(a, b); } #if PY_MAJOR_VERSION == 2 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { PyObject *exception, *value, *tb; int res; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&exception, &value, &tb); res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } if (!res) { res = PyObject_IsSubclass(err, exc_type2); if (unlikely(res == -1)) { PyErr_WriteUnraisable(err); res = 0; } } __Pyx_ErrRestore(exception, value, tb); return res; } #else static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; if (!res) { res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); } return res; } #endif static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; assert(PyExceptionClass_Check(exc_type)); n = PyTuple_GET_SIZE(tuple); #if PY_MAJOR_VERSION >= 3 for (i=0; ip) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; if (PyObject_Hash(*t->p) == -1) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT #if !CYTHON_PEP393_ENABLED static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; } #else static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (likely(PyUnicode_IS_ASCII(o))) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif } #endif #endif static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { return __Pyx_PyUnicode_AsStringAndSize(o, length); } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { int retval; if (unlikely(!x)) return -1; retval = __Pyx_PyObject_IsTrue(x); Py_DECREF(x); return retval; } static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(result)) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "__int__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } return result; } #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", type_name, type_name, Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { #if CYTHON_USE_TYPE_SLOTS PyNumberMethods *m; #endif const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x) || PyLong_Check(x))) #else if (likely(PyLong_Check(x))) #endif return __Pyx_NewRef(x); #if CYTHON_USE_TYPE_SLOTS m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = m->nb_int(x); } else if (m && m->nb_long) { name = "long"; res = m->nb_long(x); } #else if (likely(m && m->nb_int)) { name = "int"; res = m->nb_int(x); } #endif #else if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { res = PyNumber_Int(x); } #endif if (likely(res)) { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { #else if (unlikely(!PyLong_CheckExact(res))) { #endif return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)b)->ob_digit; const Py_ssize_t size = Py_SIZE(b); if (likely(__Pyx_sst_abs(size) <= 1)) { ival = likely(size) ? digits[0] : 0; if (size == -1) ival = -ival; return ival; } else { switch (size) { case 2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; case -4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 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])); } break; } } #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ python-clickhouse-driver-0.2.3/clickhouse_driver/varint.pyx000066400000000000000000000033171420676740400242440ustar00rootroot00000000000000from cpython cimport PyBytes_FromStringAndSize def make_varint(unsigned long long number): """ Writes integer of variable length using LEB128. """ cdef unsigned char to_write, i = 0 # unsigned PY_LONG_LONG checks integer on function call and # raises OverflowError if integer overflows unsigned PY_LONG_LONG. # Long enough for handling unsigned PY_LONG_LONG. cdef unsigned char num_buf[32] while True: to_write = number & 0x7f number >>= 7 if number: num_buf[i] = to_write | 0x80 i += 1 else: num_buf[i] = to_write i += 1 break return PyBytes_FromStringAndSize(num_buf, i) def write_varint(unsigned long long number, buf): """ Writes integer of variable length using LEB128. """ cdef unsigned char to_write, i = 0 # unsigned PY_LONG_LONG checks integer on function call and # raises OverflowError if integer overflows unsigned PY_LONG_LONG. # Long enough for handling unsigned PY_LONG_LONG. cdef unsigned char num_buf[32] while True: to_write = number & 0x7f number >>= 7 if number: num_buf[i] = to_write | 0x80 i += 1 else: num_buf[i] = to_write i += 1 break buf.write(PyBytes_FromStringAndSize(num_buf, i)) def read_varint(f): """ Reads integer of variable length using LEB128. """ cdef unsigned char shift = 0 cdef unsigned long long i, result = 0 read_one = f.read_one while True: i = read_one() result |= (i & 0x7f) << shift shift += 7 if i < 0x80: break return result python-clickhouse-driver-0.2.3/clickhouse_driver/writer.py000066400000000000000000000024061420676740400240630ustar00rootroot00000000000000import struct from .varint import write_varint MAX_UINT64 = (1 << 64) - 1 MAX_INT64 = (1 << 63) - 1 def _byte(b): return bytes((b, )) def write_binary_str(text, buf): text = text.encode('utf-8') write_binary_bytes(text, buf) def write_binary_bytes(text, buf): write_varint(len(text), buf) buf.write(text) def write_binary_int(number, buf, fmt): """ Writes int from buffer with provided format. """ fmt = '<' + fmt buf.write(struct.pack(fmt, number)) def write_binary_int8(number, buf): write_binary_int(number, buf, 'b') def write_binary_int16(number, buf): write_binary_int(number, buf, 'h') def write_binary_int32(number, buf): write_binary_int(number, buf, 'i') def write_binary_int64(number, buf): write_binary_int(number, buf, 'q') def write_binary_uint8(number, buf): write_binary_int(number, buf, 'B') def write_binary_uint16(number, buf): write_binary_int(number, buf, 'H') def write_binary_uint32(number, buf): write_binary_int(number, buf, 'I') def write_binary_uint64(number, buf): write_binary_int(number, buf, 'Q') def write_binary_uint128(number, buf): fmt = '> 64) & MAX_UINT64, number & MAX_UINT64) buf.write(packed) python-clickhouse-driver-0.2.3/docs/000077500000000000000000000000001420676740400174175ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/docs/Makefile000066400000000000000000000011041420676740400210530ustar00rootroot00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build SOURCEDIR = . BUILDDIR = _build # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)python-clickhouse-driver-0.2.3/docs/_static/000077500000000000000000000000001420676740400210455ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/docs/_static/css/000077500000000000000000000000001420676740400216355ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/docs/_static/css/custom.css000066400000000000000000000004371420676740400236650ustar00rootroot00000000000000 table.table-small-text { font-size: small; } table.table-center-header thead tr th { text-align: center; } table.table-right-text-align-results tbody tr td { text-align: right; } table.table-right-text-align-results tbody tr td:first-child { text-align: inherit; } python-clickhouse-driver-0.2.3/docs/_static/mymarilyn-icon.png000066400000000000000000000017341420676740400245270ustar00rootroot00000000000000PNG  IHDR@@% pHYs  tIME 9{IDAThKLAwgvFi(( D"zЋ0D1!M GXN4AD=7_sV++6nܤ%eY|p9]=66=_Nx^`4fggOMMimXELkK B(A3 AqBƋu{ HJJf2N[Gecy~EJh4nGǝ*hmm \lCVzɊdZDivk ènҒa-/arrrw!ˣG022Vn3``Y6J~>_m?B?6:^GEdu|R '" " &,D?r iZִ5_6U-a?FPw,$IR ˅e%@ @ ;ePIENDB`python-clickhouse-driver-0.2.3/docs/_templates/000077500000000000000000000000001420676740400215545ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/docs/_templates/layout.html000066400000000000000000000002421420676740400237550ustar00rootroot00000000000000{% extends "!layout.html" %} {% block extrahead %} {% endblock %} python-clickhouse-driver-0.2.3/docs/api.rst000066400000000000000000000014501420676740400207220ustar00rootroot00000000000000.. _api: API === .. module:: clickhouse_driver This part of the documentation covers basic classes of the driver: Client, Connection and others. .. _api-client: Client ------ .. autoclass:: Client :members: :inherited-members: Connection ---------- .. autoclass:: clickhouse_driver.connection.Connection :members: :inherited-members: .. _query-result: QueryResult ----------- .. autoclass:: clickhouse_driver.result.QueryResult :members: :inherited-members: .. _progress-query-result: ProgressQueryResult ------------------- .. autoclass:: clickhouse_driver.result.ProgressQueryResult :members: :inherited-members: .. _iter-query-result: IterQueryResult --------------- .. autoclass:: clickhouse_driver.result.IterQueryResult :members: :inherited-members: python-clickhouse-driver-0.2.3/docs/changelog.rst000066400000000000000000000002111420676740400220720ustar00rootroot00000000000000Changelog ========= Changelog is available in `github repo `_. python-clickhouse-driver-0.2.3/docs/conf.py000066400000000000000000000133151420676740400207210ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/master/config # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) from clickhouse_driver import __version__, VERSION # -- Project information ----------------------------------------------------- project = u'clickhouse-driver' copyright = u'2017-2020, clickhouse-driver authors' author = u'clickhouse-driver authors' # The short X.Y version version = '.'.join(str(x) for x in VERSION[:2]) # The full version, including alpha/beta/rc tags release = __version__ # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx' ] intersphinx_mapping = { 'python3': ('http://docs.python.org/3', None), 'python2': ('http://docs.python.org/2', None), } # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = [u'_build'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = None # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_favicon = "_static/mymarilyn-icon.png" html_logo = "" html_static_path = ['_static'] html_theme_options = { "description": "Python driver for ClickHouse", "github_user": "mymarilyn", "github_repo": "clickhouse-driver", "fixed_sidebar": True, "sidebar_width": '300px', "page_width": '1000px' } html_css_files = [ 'css/custom.css', ] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # The default sidebars (for documents that don't match any pattern) are # defined by theme itself. Builtin themes are using these templates by # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', # 'searchbox.html']``. # # html_sidebars = {} # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. htmlhelp_basename = 'clickhouse-driverdoc' # -- Options for LaTeX output ------------------------------------------------ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'clickhouse-driver.tex', u'clickhouse-driver Documentation', author, 'manual'), ] # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'clickhouse-driver', u'clickhouse-driver Documentation', [author], 1) ] # -- Options for Texinfo output ---------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'clickhouse-driver', u'clickhouse-driver Documentation', author, 'clickhouse-driver', 'One line description of project.', 'Miscellaneous'), ] # -- Options for Epub output ------------------------------------------------- # Bibliographic Dublin Core info. epub_title = project # The unique identifier of the text. This can be a ISBN number # or the project homepage. # # epub_identifier = '' # A unique identification for the text. # # epub_uid = '' # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] python-clickhouse-driver-0.2.3/docs/contents.rst.inc000066400000000000000000000032671420676740400225660ustar00rootroot00000000000000User's Guide ------------ This part of the documentation focuses on step-by-step instructions for development with clickhouse-driver. Clickhouse-driver is designed to communicate with ClickHouse server from Python over native protocol. ClickHouse server provides two protocols for communication: * HTTP protocol (port 8123 by default); * Native (TCP) protocol (port 9000 by default). Each protocol has own advantages and disadvantages. Here we focus on advantages of native protocol: * Native protocol is more configurable by various settings. * Binary data transfer is more compact than text data. * Building python types from binary data is more effective than from text data. * LZ4 compression is `faster than gzip `_. Gzip compression is used in HTTP protocol. * Query profile info is available over native protocol. We can read rows before limit metric for example. Once again: clickhouse-driver uses native protocol (port 9000). There is an asynchronous wrapper for clickhouse-driver: aioch. It's available `here `_. .. toctree:: :maxdepth: 2 installation quickstart features types performance misc unsupportedserverversions API Reference ------------- If you are looking for information on a specific function, class or method, this part of the documentation is for you. .. toctree:: :maxdepth: 2 api dbapi Additional Notes ---------------- Legal information, changelog and contributing are here for the interested. .. toctree:: :maxdepth: 2 development changelog license contributing python-clickhouse-driver-0.2.3/docs/contributing.rst000066400000000000000000000000411420676740400226530ustar00rootroot00000000000000.. include:: ../CONTRIBUTING.rst python-clickhouse-driver-0.2.3/docs/dbapi.rst000066400000000000000000000006621420676740400212340ustar00rootroot00000000000000.. _dbapi: DB API 2.0 ========== This part of the documentation covers driver DB API. .. automodule:: clickhouse_driver.dbapi :members: :inherited-members: .. _dbapi-connection: Connection ---------- .. autoclass:: clickhouse_driver.dbapi.connection.Connection :members: :inherited-members: .. _dbapi-cursor: Cursor ------ .. autoclass:: clickhouse_driver.dbapi.cursor.Cursor :members: :inherited-members: python-clickhouse-driver-0.2.3/docs/development.rst000066400000000000000000000044571420676740400225050ustar00rootroot00000000000000.. _development: Development =========== Test configuration ------------------ In ``setup.cfg`` you can find ClickHouse server port, credentials, logging level and another options than can be tuned during local testing. Running tests locally --------------------- Install desired Python version with system package manager/pyenv/another manager. Install test requirements and build package: .. code-block:: bash python testsrequire.py && python setup.py develop You should install cython if you want to change ``*.pyx`` files: .. code-block:: bash pip install cython ClickHouse on host machine ^^^^^^^^^^^^^^^^^^^^^^^^^^ Install desired versions of ``clickhouse-server`` and ``clickhouse-client`` on your machine. Run tests: .. code-block:: bash py.test -v ClickHouse in docker ^^^^^^^^^^^^^^^^^^^^ Create container desired version of ``clickhouse-server``: .. code-block:: bash docker run --rm -e "TZ=Europe/Moscow" -p 127.0.0.1:9000:9000 --name test-clickhouse-server yandex/clickhouse-server:$VERSION Create container with the same version of ``clickhouse-client``: .. code-block:: bash 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' Create ``clickhouse-client`` script on your host machine: .. code-block:: bash 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 sudo chmod +x /usr/local/bin/clickhouse-client After it container ``test-clickhouse-client`` will communicate with ``test-clickhouse-server`` transparently from host machine. Set ``host=clickhouse-server`` in ``setup.cfg``. Add entry in hosts file: .. code-block:: bash echo '127.0.0.1 clickhouse-server' | sudo tee -a /etc/hosts > /dev/null Set ``TZ=UTC`` and run tests: .. code-block:: bash export TZ=UTC py.test -v GitHub Actions in forked repository ----------------------------------- Workflows in forked repositories can be used for running tests. Workflows don't run in forked repositories by default. You must enable GitHub Actions in the **Actions** tab of the forked repository. python-clickhouse-driver-0.2.3/docs/features.rst000066400000000000000000000370621420676740400217770ustar00rootroot00000000000000.. _features: Features ======== - Compression support: * `LZ4/LZ4HC `_ * `ZSTD `_ - TLS support (since server version 1.1.54304). .. _external-tables: External data for query processing ---------------------------------- You can pass `external data `_ alongside with query: .. code-block:: python >>> tables = [{ ... 'name': 'ext', ... 'structure': [('x', 'Int32'), ('y', 'Array(Int32)')], ... 'data': [ ... {'x': 100, 'y': [2, 4, 6, 8]}, ... {'x': 500, 'y': [1, 3, 5, 7]}, ... ] ... }] >>> client.execute( ... 'SELECT sum(x) FROM ext', external_tables=tables ... ) [(600,)] Settings -------- There are a lot of ClickHouse server `settings `_. Settings can be specified during Client initialization: .. code-block:: python # Set max number threads for all queries execution. >>> settings = {'max_threads': 2} >>> client = Client('localhost', settings=settings) Each setting can be overridden in an ``execute``, ``execute_with_progress`` and ``execute_iter`` statement: .. code-block:: python # Set lower priority to query and limit max number threads # to execute the request. >>> settings = {'max_threads': 2, 'priority': 10} >>> client.execute('SHOW TABLES', settings=settings) [('first_table',)] Compression ----------- Native protocol supports two types of compression: `LZ4 `_ and `ZSTD `_. When compression is enabled compressed data should be hashed using `CityHash algorithm `_. Additional packages should be installed in order by enable compression support, see :ref:`installation-pypi`. Enabled client-side compression can save network traffic. Client with compression support can be constructed as follows: .. code-block:: python >>> from clickhouse_driver import Client >>> client_with_lz4 = Client('localhost', compression=True) >>> client_with_lz4 = Client('localhost', compression='lz4') >>> client_with_zstd = Client('localhost', compression='zstd') .. _compression-cityhash-notes: CityHash algorithm notes ~~~~~~~~~~~~~~~~~~~~~~~~ Unfortunately ClickHouse server comes with built-in old version of CityHash algorithm (1.0.2). That's why we can't use original `CityHash `_ package. An older version is published separately at `PyPI `_. Secure connection ----------------- .. code-block:: python >>> from clickhouse_driver import Client >>> >>> client = Client('localhost', secure=True) >>> # Using self-signed certificate. ... self_signed_client = Client( ... 'localhost', secure=True, ... ca_certs='/etc/clickhouse-server/server.crt' ... ) >>> # Disable verification. ... no_verifyed_client = Client( ... 'localhost', secure=True, verify=False ... ) >>> >>> # Example of secured client with Let's Encrypt certificate. ... import certifi >>> >>> client = Client( ... 'remote-host', secure=True, ca_certs=certifi.where() ... ) Specifying query id ------------------- You can manually set query identificator for each query. UUID for example: .. code-block:: python >>> from uuid import uuid4 >>> >>> query_id = str(uuid4()) >>> print(query_id) bbd7dea3-eb63-4a21-b727-f55b420a7223 >>> client.execute( ... 'SELECT * FROM system.processes', query_id=query_id ... ) [(1, 'default', 'bbd7dea3-eb63-4a21-b727-f55b420a7223', '127.0.0.1', 57664, 'default', 'bbd7dea3-eb63-4a21-b727-f55b420a7223', '127.0.0.1', 57664, 1, 'klebedev', 'klebedev-ThinkPad-T460', 'ClickHouse python-driver', 18, 10, 3, 54406, 0, '', '', 0.004916541, 0, 0, 0, 0, 0, 0, 0, 0, 'SELECT * FROM system.processes', (25,), ('Query', 'SelectQuery', 'NetworkReceiveElapsedMicroseconds', 'ContextLock', 'RWLockAcquiredReadLocks'), (1, 1, 54, 9, 1), ('use_uncompressed_cache', 'load_balancing', 'max_memory_usage'), ('0', 'random', '10000000000'))] You can cancel query with specific id by sending another query with the same query id if option `replace_running_query `_ is set to 1. Query results are fetched by the same instance of Client that emitted query. Retrieving results in columnar form ----------------------------------- Columnar form sometimes can be more useful. .. code-block:: python >>> client.execute('SELECT arrayJoin(range(3))', columnar=True) [(0, 1, 2)] Data types checking on INSERT ----------------------------- Data types check is disabled for performance on ``INSERT`` queries. You can turn it on by `types_check` option: .. code-block:: python >>> client.execute( ... 'INSERT INTO test (x) VALUES', [('abc', )], ... types_check=True ... ) 1 Query execution statistics -------------------------- Client stores statistics about last query execution. It can be obtained by accessing `last_query` attribute. Statistics is sent from ClickHouse server and calculated on client side. `last_query` contains info about: * profile: rows before limit .. code-block:: python >>> client.execute('SELECT arrayJoin(range(100)) LIMIT 3') [(0,), (1,), (2,)] >>> client.last_query.profile_info.rows_before_limit 100 * progress: - processed rows; - processed bytes; - total rows; - written rows (*new in version 0.1.3*); - written bytes (*new in version 0.1.3*); .. code-block:: python >>> client.execute('SELECT max(number) FROM numbers(10)') [(9,)] >>> client.last_query.progress.rows 10 >>> client.last_query.progress.bytes 80 >>> client.last_query.progress.total_rows 10 * elapsed time: .. code-block:: python >>> client.execute('SELECT sleep(1)') [(0,)] >>> client.last_query.elapsed 1.0060372352600098 Receiving server logs --------------------- Query logs can be received from server by using `send_logs_level` setting: .. code-block:: python >>> from logging.config import dictConfig >>> # Simple logging configuration. ... dictConfig({ ... 'version': 1, ... 'disable_existing_loggers': False, ... 'formatters': { ... 'standard': { ... 'format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s' ... }, ... }, ... 'handlers': { ... 'default': { ... 'level': 'INFO', ... 'formatter': 'standard', ... 'class': 'logging.StreamHandler', ... }, ... }, ... 'loggers': { ... '': { ... 'handlers': ['default'], ... 'level': 'INFO', ... 'propagate': True ... }, ... } ... }) >>> >>> settings = {'send_logs_level': 'debug'} >>> client.execute('SELECT 1', settings=settings) 2018-12-14 10:24:53,873 INFO clickhouse_driver.log: [ klebedev-ThinkPad-T460 ] [ 25 ] {b328ad33-60e8-4012-b4cc-97f44a7b28f2} executeQuery: (from 127.0.0.1:57762) SELECT 1 2018-12-14 10:24:53,874 INFO clickhouse_driver.log: [ klebedev-ThinkPad-T460 ] [ 25 ] {b328ad33-60e8-4012-b4cc-97f44a7b28f2} executeQuery: Query pipeline: Expression Expression One 2018-12-14 10:24:53,875 INFO clickhouse_driver.log: [ klebedev-ThinkPad-T460 ] [ 25 ] {b328ad33-60e8-4012-b4cc-97f44a7b28f2} executeQuery: Read 1 rows, 1.00 B in 0.004 sec., 262 rows/sec., 262.32 B/sec. 2018-12-14 10:24:53,875 INFO clickhouse_driver.log: [ klebedev-ThinkPad-T460 ] [ 25 ] {b328ad33-60e8-4012-b4cc-97f44a7b28f2} MemoryTracker: Peak memory usage (for query): 40.23 KiB. [(1,)] Multiple hosts -------------- *New in version 0.1.3.* Additional connection points can be defined by using `alt_hosts`. If main connection point is unavailable driver will use next one from `alt_hosts`. This option is good for ClickHouse cluster with multiple replicas. .. code-block:: python >>> from clickhouse_driver import Client >>> client = Client('host1', alt_hosts='host2:1234,host3,host4:5678') In example above on every *new* connection driver will use following sequence of hosts if previous host is unavailable: * host1:9000; * host2:1234; * host3:9000; * host4:5678. All queries within established connection will be sent to the same host. Python DB API 2.0 ----------------- *New in version 0.1.3.* This driver is also implements `DB API 2.0 specification `_. It can be useful for various integrations. Threads may share the module and connections. Parameters are expected in Python extended format codes, e.g. `...WHERE name=%(name)s`. .. code-block:: python >>> from clickhouse_driver import connect >>> conn = connect('clickhouse://localhost') >>> cursor = conn.cursor() >>> >>> cursor.execute('SHOW TABLES') >>> cursor.fetchall() [('test',)] >>> cursor.execute('DROP TABLE IF EXISTS test') >>> cursor.fetchall() [] >>> cursor.execute('CREATE TABLE test (x Int32) ENGINE = Memory') >>> cursor.fetchall() [] >>> cursor.executemany( ... 'INSERT INTO test (x) VALUES', ... [{'x': 100}] ... ) >>> cursor.rowcount 1 >>> cursor.executemany('INSERT INTO test (x) VALUES', [[200]]) >>> cursor.rowcount 1 >>> cursor.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 3} ... ) >>> cursor.rowcount 0 >>> cursor.execute('SELECT sum(x) FROM test') >>> cursor.fetchall() [(303,)] ClickHouse native protocol is synchronous: when you emit query in connection you must read whole server response before sending next query through this connection. To make DB API thread-safe each cursor should use it's own connection to the server. In Under the hood :ref:`dbapi-cursor` is wrapper around pure :ref:`api-client`. :ref:`dbapi-connection` class is just wrapper for handling multiple cursors (clients) and do not initiate actual connections to the ClickHouse server. There are some non-standard ClickHouse-related :ref:`Cursor methods ` for: external data, settings, etc. For automatic disposal Connection and Cursor instances can be used as context managers: .. code-block:: python >>> with connect('clickhouse://localhost') as conn: >>> with conn.cursor() as cursor: >>> cursor.execute('SHOW TABLES') >>> print(cursor.fetchall()) NumPy/Pandas support -------------------- *New in version 0.1.6.* Starting from version 0.1.6 package can SELECT and INSERT columns as NumPy arrays. Additional packages are required for :ref:`installation-numpy-support`. .. code-block:: python >>> client = Client('localhost', settings={'use_numpy': True}): >>> client.execute( ... 'SELECT * FROM system.numbers LIMIT 10000', ... columnar=True ... ) [array([ 0, 1, 2, ..., 9997, 9998, 9999], dtype=uint64)] Supported types: * Float32/64 * [U]Int8/16/32/64 * Date/DateTime('timezone')/DateTime64('timezone') * String/FixedString(N) * LowCardinality(T) * Nullable(T) Direct loading into NumPy arrays increases performance and lowers memory requirements on large amounts of rows. Direct loading into pandas DataFrame is also supported by using `query_dataframe`: .. code-block:: python >>> client = Client('localhost', settings={'use_numpy': True}) >>> client.query_dataframe(' ... 'SELECT number AS x, (number + 100) AS y ' ... 'FROM system.numbers LIMIT 10000' ... ) x y 0 0 100 1 1 101 2 2 102 3 3 103 4 4 104 ... ... ... 9995 9995 10095 9996 9996 10096 9997 9997 10097 9998 9998 10098 9999 9999 10099 [10000 rows x 2 columns] Writing pandas DataFrame is also supported with `insert_dataframe`: .. code-block:: python >>> client = Client('localhost', settings={'use_numpy': True}) >>> client.execute( ... 'CREATE TABLE test (x Int64, y Int64) Engine = Memory' ... ) >>> [] >>> df = client.query_dataframe( ... 'SELECT number AS x, (number + 100) AS y ' ... 'FROM system.numbers LIMIT 10000' ... ) >>> client.insert_dataframe('INSERT INTO test VALUES', df) >>> 10000 Starting from version 0.2.2 nullable columns are also supported. Keep in mind that nullable columns have ``object`` dtype. For convenience ``np.nan`` and ``None`` is supported as ``NULL`` values for inserting. But only ``None`` is returned after selecting for ``NULL`` values. .. code-block:: python >>> client = Client('localhost', settings={'use_numpy': True}) >>> client.execute( ... 'CREATE TABLE test (' ... 'a Nullable(Int64), ... 'b Nullable(Float64), ... 'c Nullable(String)' ... ') Engine = Memory' ... ) >>> [] >>> df = pd.DataFrame({ ... 'a': [1, None, None], ... 'b': [1.0, None, np.nan], ... 'c': ['a', None, np.nan], ... }, dtype=object) >>> client.insert_dataframe('INSERT INTO test VALUES', df) 3 >>> client.query_dataframe('SELECT * FROM test') a b c 0 1 1 a 1 None None None 2 None NaN None It's important to specify `dtype` during dataframe creation: .. code-block:: python >>> bad_df = pd.DataFrame({ ... 'a': [1, None, None], ... 'b': [1.0, None, np.nan], ... 'c': ['a', None, np.nan], ... }) >>> bad_df a b c 0 1.0 1.0 a 1 NaN NaN None 2 NaN NaN NaN >>> good_df = pd.DataFrame({ ... 'a': [1, None, None], ... 'b': [1.0, None, np.nan], ... 'c': ['a', None, np.nan], ... }, dtype=object) >>> good_df a b c 0 1 1 a 1 None None None 2 None NaN NaN As you can see float column ``b`` in ``bad_df`` has two ``NaN`` values. But ``NaN`` and ``None`` is not the same for float point numbers. ``NaN`` is ``float('nan')`` where ``None`` is representing ``NULL``. Automatic disposal ------------------ *New in version 0.2.2.* Each Client instance can be used as a context manager: .. code-block:: python >>> with Client('localhost') as client: >>> client.execute('SELECT 1') Upon exit, any established connection to the ClickHouse server will be closed automatically. python-clickhouse-driver-0.2.3/docs/index.rst000066400000000000000000000004321420676740400212570ustar00rootroot00000000000000Welcome to clickhouse-driver ============================ Release |release|. Welcome to clickhouse-driver's documentation. Get started with :ref:`installation` and then get an overview with the :ref:`quickstart` where common queries are described. .. include:: contents.rst.inc python-clickhouse-driver-0.2.3/docs/installation.rst000066400000000000000000000050271420676740400226560ustar00rootroot00000000000000.. _installation: Installation ============ Python Version -------------- Clickhouse-driver supports Python 3.4 and newer and PyPy. Build Dependencies ------------------ Starting from version *0.1.0* for building from source `gcc`, python and linux headers are required. Example for `python:alpine` docker image: .. code-block:: bash apk add gcc musl-dev By default there are wheels for Linux, Mac OS X and Windows. Packages for Linux and Mac OS X are available for python: 3.6 -- 3.10. Packages for Windows are available for python: 3.6 -- 3.10. Starting from version *0.2.3* there are wheels for musl-based Linux distributions. Dependencies ------------ These distributions will be installed automatically when installing clickhouse-driver. * `pytz`_ library for timezone calculations. * `enum34`_ backported Python 3.4 Enum. .. _pytz: http://pytz.sourceforge.net/ .. _enum34: https://pypi.org/project/enum34/ Optional dependencies ~~~~~~~~~~~~~~~~~~~~~ These distributions will not be installed automatically. Clickhouse-driver will detect and use them if you install them. * `clickhouse-cityhash`_ provides CityHash algorithm of specific version, see :ref:`compression-cityhash-notes`. * `lz4`_ enables `LZ4/LZ4HC compression `_ support. * `zstd`_ enables `ZSTD compression `_ support. .. _clickhouse-cityhash: https://pythonhosted.org/blinker/ .. _lz4: https://python-lz4.readthedocs.io/ .. _zstd: https://pypi.org/project/zstd/ .. _installation-pypi: Installation from PyPI ---------------------- The package can be installed using ``pip``: .. code-block:: bash pip install clickhouse-driver You can install extras packages if you need compression support. Example of LZ4 compression requirements installation: .. code-block:: bash pip install clickhouse-driver[lz4] You also can specify multiple extras by using comma. Install LZ4 and ZSTD requirements: .. code-block:: bash pip install clickhouse-driver[lz4,zstd] .. _installation-numpy-support: NumPy support ------------- You can install additional packages (NumPy and Pandas) if you need NumPy support: .. code-block:: bash pip install clickhouse-driver[numpy] NumPy supported versions are limited by ``numpy`` package python support. Installation from github ------------------------ Development version can be installed directly from github: .. code-block:: bash pip install git+https://github.com/mymarilyn/clickhouse-driver@master#egg=clickhouse-driver python-clickhouse-driver-0.2.3/docs/license.rst000066400000000000000000000002111420676740400215650ustar00rootroot00000000000000License ======= ClickHouse Python Driver is distributed under the `MIT license `_. python-clickhouse-driver-0.2.3/docs/misc.rst000066400000000000000000000074001420676740400211050ustar00rootroot00000000000000 Miscellaneous ============= Client configuring from URL --------------------------- *New in version 0.1.1.* Client can be configured from the given URL: .. code-block:: python >>> from clickhouse_driver import Client >>> client = Client.from_url( ... 'clickhouse://login:password@host:port/database' ... ) Port 9000 is default for schema ``clickhouse``, port 9440 is default for schema ``clickhouses``. Connection to default database: .. code-block:: python >>> client = Client.from_url('clickhouse://localhost') Querystring arguments will be passed along to the :meth:`~clickhouse_driver.connection.Connection` class’s initializer: .. code-block:: python >>> client = Client.from_url( ... 'clickhouse://localhost/database?send_logs_level=trace&' ... 'client_name=myclient&' ... 'compression=lz4' ... ) If parameter doesn't match Connection's init signature will be treated as settings parameter. .. _insert-from-csv-file: Inserting data from CSV file ---------------------------- Let's assume you have following data in CSV file. .. code-block:: shell $ cat /tmp/data.csv time,order,qty 2019-08-01 15:23:14,New order1,5 2019-08-05 09:14:45,New order2,3 2019-08-13 12:20:32,New order3,7 Data can be inserted into ClickHouse in the following way: .. code-block:: python >>> from csv import DictReader >>> from datetime import datetime >>> >>> from clickhouse_driver import Client >>> >>> >>> def iter_csv(filename): ... converters = { ... 'qty': int, ... 'time': lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S') ... } ... ... with open(filename, 'r') as f: ... reader = DictReader(f) ... for line in reader: ... yield {k: (converters[k](v) if k in converters else v) for k, v in line.items()} ... >>> client = Client('localhost') >>> >>> client.execute( ... 'CREATE TABLE IF NOT EXISTS data_csv ' ... '(' ... 'time DateTime, ' ... 'order String, ' ... 'qty Int32' ... ') Engine = Memory' ... ) >>> [] >>> client.execute('INSERT INTO data_csv VALUES', iter_csv('/tmp/data.csv')) 3 Table can be populated with json file in the similar way. Adding missed settings ---------------------- It's hard to keep package settings in consistent state with ClickHouse server's. Some settings can be missed if your server is old. But, if setting is *supported by your server* and missed in the package it can be added by simple monkey pathing. Just look into ClickHouse server source and pick corresponding setting type from package or write your own type. .. code-block:: python >>> from clickhouse_driver.settings.available import settings as available_settings, SettingBool >>> from clickhouse_driver import Client >>> >>> available_settings['allow_suspicious_low_cardinality_types'] = SettingBool >>> >>> client = Client('localhost', settings={'allow_suspicious_low_cardinality_types': True}) >>> client.execute('CREATE TABLE test (x LowCardinality(Int32)) Engine = Null') [] *New in version 0.1.5.* Modern ClickHouse servers (20.*+) use text serialization for settings instead of binary serialization. You don't have to add missed settings manually into available. Just specify new settings and it will work. .. code-block:: python >>> client = Client('localhost', settings={'brand_new_setting': 42}) >>> client.execute('SELECT 1') python-clickhouse-driver-0.2.3/docs/performance.rst000066400000000000000000000674461420676740400224730ustar00rootroot00000000000000 Performance =========== This section compares clickhouse-driver performance over Native interface with TSV and JSONEachRow formats available over HTTP interface. clickhouse-driver returns already parsed row items in Python data types. Driver performs all transformation for you. When you read data over HTTP you may need to cast strings into Python types. Test data --------- Sample data for testing is taken from `ClickHouse docs `_. Create database and table: .. code-block:: sql DROP DATABASE IF EXISTS perftest; CREATE DATABASE perftest; CREATE TABLE perftest.ontime ( Year UInt16, Quarter UInt8, Month UInt8, DayofMonth UInt8, DayOfWeek UInt8, FlightDate Date, UniqueCarrier FixedString(7), AirlineID Int32, Carrier FixedString(2), TailNum String, FlightNum String, OriginAirportID Int32, OriginAirportSeqID Int32, OriginCityMarketID Int32, Origin FixedString(5), OriginCityName String, OriginState FixedString(2), OriginStateFips String, OriginStateName String, OriginWac Int32, DestAirportID Int32, DestAirportSeqID Int32, DestCityMarketID Int32, Dest FixedString(5), DestCityName String, DestState FixedString(2), DestStateFips String, DestStateName String, DestWac Int32, CRSDepTime Int32, DepTime Int32, DepDelay Int32, DepDelayMinutes Int32, DepDel15 Int32, DepartureDelayGroups String, DepTimeBlk String, TaxiOut Int32, WheelsOff Int32, WheelsOn Int32, TaxiIn Int32, CRSArrTime Int32, ArrTime Int32, ArrDelay Int32, ArrDelayMinutes Int32, ArrDel15 Int32, ArrivalDelayGroups Int32, ArrTimeBlk String, Cancelled UInt8, CancellationCode FixedString(1), Diverted UInt8, CRSElapsedTime Int32, ActualElapsedTime Int32, AirTime Int32, Flights Int32, Distance Int32, DistanceGroup UInt8, CarrierDelay Int32, WeatherDelay Int32, NASDelay Int32, SecurityDelay Int32, LateAircraftDelay Int32, FirstDepTime String, TotalAddGTime String, LongestAddGTime String, DivAirportLandings String, DivReachedDest String, DivActualElapsedTime String, DivArrDelay String, DivDistance String, Div1Airport String, Div1AirportID Int32, Div1AirportSeqID Int32, Div1WheelsOn String, Div1TotalGTime String, Div1LongestGTime String, Div1WheelsOff String, Div1TailNum String, Div2Airport String, Div2AirportID Int32, Div2AirportSeqID Int32, Div2WheelsOn String, Div2TotalGTime String, Div2LongestGTime String, Div2WheelsOff String, Div2TailNum String, Div3Airport String, Div3AirportID Int32, Div3AirportSeqID Int32, Div3WheelsOn String, Div3TotalGTime String, Div3LongestGTime String, Div3WheelsOff String, Div3TailNum String, Div4Airport String, Div4AirportID Int32, Div4AirportSeqID Int32, Div4WheelsOn String, Div4TotalGTime String, Div4LongestGTime String, Div4WheelsOff String, Div4TailNum String, Div5Airport String, Div5AirportID Int32, Div5AirportSeqID Int32, Div5WheelsOn String, Div5TotalGTime String, Div5LongestGTime String, Div5WheelsOff String, Div5TailNum String ) ENGINE = MergeTree PARTITION BY Year ORDER BY (Carrier, FlightDate) SETTINGS index_granularity = 8192; Download some data for 2017 year: .. code-block:: bash for s in `seq 2017 2017` do for m in `seq 1 12` do wget https://transtats.bts.gov/PREZIP/On_Time_Reporting_Carrier_On_Time_Performance_1987_present_${s}_${m}.zip done done Insert data into ClickHouse: .. code-block:: bash for i in *.zip; do echo $i; unzip -cq $i '*.csv' | sed 's/\.00//g' | clickhouse-client --query="INSERT INTO perftest.ontime FORMAT CSVWithNames"; done Required packages ----------------- .. code-block:: bash pip install clickhouse-driver requests For fast json parsing we'll use ``ujson`` package: .. code-block:: bash pip install ujson Installed packages: :: $ pip freeze certifi==2020.4.5.1 chardet==3.0.4 clickhouse-driver==0.1.3 idna==2.9 pytz==2019.3 requests==2.23.0 tzlocal==2.0.0 ujson==2.0.3 urllib3==1.25.9 Versions -------- Machine: Linux ThinkPad-T460 4.4.0-177-generic #207-Ubuntu SMP Mon Mar 16 01:16:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux Python: CPython 3.6.5 (default, May 30 2019, 14:48:31) [GCC 5.4.0 20160609] Benchmarking ------------ Let's pick number of rows for testing with ``clickhouse-client``. .. code-block:: sql SELECT count() FROM ontime WHERE FlightDate < '2017-01-04' 45202 .. code-block:: sql SELECT count() FROM ontime WHERE FlightDate < '2017-01-10' 131848 .. code-block:: sql SELECT count() FROM ontime WHERE FlightDate < '2017-01-16' 217015 .. code-block:: sql SELECT count() FROM ontime WHERE FlightDate < '2017-02-01' 450017 .. code-block:: sql SELECT count() FROM ontime WHERE FlightDate < '2017-02-18' 697813 Scripts below can be benchmarked with following one-liner: .. code-block:: bash for d in 2017-01-04 2017-01-10 2017-01-16 2017-02-01 2017-02-18; do /usr/bin/time -f "%e s / %M kB" python script.py $d; done Time will measure: * elapsed real (wall clock) time used by the process, in seconds; * maximum resident set size of the process during its lifetime, in kilobytes. Plain text without parsing ^^^^^^^^^^^^^^^^^^^^^^^^^^ Let's take get plain text response from ClickHouse server as baseline. Fetching not parsed data with pure requests (1) .. code-block:: python import sys import requests query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT {}".format(sys.argv[1], sys.argv[2]) data = requests.get('http://localhost:8123/', params={'query': query}) Parsed rows ^^^^^^^^^^^ Line split into elements will be consider as "parsed" for TSV format (2) .. code-block:: python import sys import requests query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) data = [line.decode('utf-8').split('\t') for line in resp.iter_lines(chunk_size=10000)] Now we cast each element to it's data type (2.5) .. code-block:: python from datetime import date import sys import requests def get_python_type(ch_type): if ch_type.startswith('Int') or ch_type.startswith('UInt'): return int elif ch_type == 'String' or ch_type.startswith('FixedString'): return None elif ch_type == 'Date': return lambda value: date(*[int(x) for x in value.split('-')]) raise ValueError(f'Unsupported type: "{ch_type}"') resp = requests.get('http://localhost:8123', params={'query': 'describe table perftest.ontime FORMAT TSV'}) ch_types = [x.split('\t')[1] for x in resp.text.split('\n') if x] python_types = [get_python_type(x) for x in ch_types] query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) data = [] for line in resp.iter_lines(chunk_size=10000): data.append([cls(x) if cls else x for x, cls in zip(line.decode('utf-8').split('\t'), python_types)]) JSONEachRow format can be loaded with json loads (3) .. code-block:: python import sys import requests from ujson import loads query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT JSONEachRow".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) data = [list(loads(line).values()) for line in resp.iter_lines(chunk_size=10000)] Get fully parsed rows with ``clickhouse-driver`` in Native format (4) .. code-block:: python import sys from clickhouse_driver import Client query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}'".format(sys.argv[1]) client = Client.from_url('clickhouse://localhost') data = client.execute(query) Iteration over rows ^^^^^^^^^^^^^^^^^^^ Iteration over TSV (5) .. code-block:: python import sys import requests query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = line.decode('utf-8').split('\t') Now we cast each element to it's data type (5.5) .. code-block:: python from datetime import date import sys import requests def get_python_type(ch_type): if ch_type.startswith('Int') or ch_type.startswith('UInt'): return int elif ch_type == 'String' or ch_type.startswith('FixedString'): return None elif ch_type == 'Date': return lambda value: date(*[int(x) for x in value.split('-')]) raise ValueError(f'Unsupported type: "{ch_type}"') resp = requests.get('http://localhost:8123', params={'query': 'describe table perftest.ontime FORMAT TSV'}) ch_types = [x.split('\t')[1] for x in resp.text.split('\n') if x] python_types = [get_python_type(x) for x in ch_types] query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = [cls(x) if cls else x for x, cls in zip(line.decode('utf-8').split('\t'), python_types)] Iteration over JSONEachRow (6) .. code-block:: python import sys import requests from ujson import loads query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}' FORMAT JSONEachRow".format(sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = list(loads(line).values()) Iteration over rows with ``clickhouse-driver`` in Native format (7) .. code-block:: python import sys from clickhouse_driver import Client query = "SELECT * FROM perftest.ontime WHERE FlightDate < '{}'".format(sys.argv[1]) client = Client.from_url('clickhouse://localhost') for row in client.execute_iter(query): pass Iteration over string rows ^^^^^^^^^^^^^^^^^^^^^^^^^^ OK, but what if we need only string columns? Iteration over TSV (8) .. code-block:: python import sys import requests cols = [ 'UniqueCarrier', 'Carrier', 'TailNum', 'FlightNum', 'Origin', 'OriginCityName', 'OriginState', 'OriginStateFips', 'OriginStateName', 'Dest', 'DestCityName', 'DestState', 'DestStateFips', 'DestStateName', 'DepartureDelayGroups', 'DepTimeBlk', 'ArrTimeBlk', 'CancellationCode', 'FirstDepTime', 'TotalAddGTime', 'LongestAddGTime', 'DivAirportLandings', 'DivReachedDest', 'DivActualElapsedTime', 'DivArrDelay', 'DivDistance', 'Div1Airport', 'Div1WheelsOn', 'Div1TotalGTime', 'Div1LongestGTime', 'Div1WheelsOff', 'Div1TailNum', 'Div2Airport', 'Div2WheelsOn', 'Div2TotalGTime', 'Div2LongestGTime', 'Div2WheelsOff', 'Div2TailNum', 'Div3Airport', 'Div3WheelsOn', 'Div3TotalGTime', 'Div3LongestGTime', 'Div3WheelsOff', 'Div3TailNum', 'Div4Airport', 'Div4WheelsOn', 'Div4TotalGTime', 'Div4LongestGTime', 'Div4WheelsOff', 'Div4TailNum', 'Div5Airport', 'Div5WheelsOn', 'Div5TotalGTime', 'Div5LongestGTime', 'Div5WheelsOff', 'Div5TailNum' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(', '.join(cols), sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = line.decode('utf-8').split('\t') Iteration over JSONEachRow (9) .. code-block:: python import sys import requests from ujson import loads cols = [ 'UniqueCarrier', 'Carrier', 'TailNum', 'FlightNum', 'Origin', 'OriginCityName', 'OriginState', 'OriginStateFips', 'OriginStateName', 'Dest', 'DestCityName', 'DestState', 'DestStateFips', 'DestStateName', 'DepartureDelayGroups', 'DepTimeBlk', 'ArrTimeBlk', 'CancellationCode', 'FirstDepTime', 'TotalAddGTime', 'LongestAddGTime', 'DivAirportLandings', 'DivReachedDest', 'DivActualElapsedTime', 'DivArrDelay', 'DivDistance', 'Div1Airport', 'Div1WheelsOn', 'Div1TotalGTime', 'Div1LongestGTime', 'Div1WheelsOff', 'Div1TailNum', 'Div2Airport', 'Div2WheelsOn', 'Div2TotalGTime', 'Div2LongestGTime', 'Div2WheelsOff', 'Div2TailNum', 'Div3Airport', 'Div3WheelsOn', 'Div3TotalGTime', 'Div3LongestGTime', 'Div3WheelsOff', 'Div3TailNum', 'Div4Airport', 'Div4WheelsOn', 'Div4TotalGTime', 'Div4LongestGTime', 'Div4WheelsOff', 'Div4TailNum', 'Div5Airport', 'Div5WheelsOn', 'Div5TotalGTime', 'Div5LongestGTime', 'Div5WheelsOff', 'Div5TailNum' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}' FORMAT JSONEachRow".format(', '.join(cols), sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = list(loads(line).values()) Iteration over string rows with ``clickhouse-driver`` in Native format (10) .. code-block:: python import sys from clickhouse_driver import Client cols = [ 'UniqueCarrier', 'Carrier', 'TailNum', 'FlightNum', 'Origin', 'OriginCityName', 'OriginState', 'OriginStateFips', 'OriginStateName', 'Dest', 'DestCityName', 'DestState', 'DestStateFips', 'DestStateName', 'DepartureDelayGroups', 'DepTimeBlk', 'ArrTimeBlk', 'CancellationCode', 'FirstDepTime', 'TotalAddGTime', 'LongestAddGTime', 'DivAirportLandings', 'DivReachedDest', 'DivActualElapsedTime', 'DivArrDelay', 'DivDistance', 'Div1Airport', 'Div1WheelsOn', 'Div1TotalGTime', 'Div1LongestGTime', 'Div1WheelsOff', 'Div1TailNum', 'Div2Airport', 'Div2WheelsOn', 'Div2TotalGTime', 'Div2LongestGTime', 'Div2WheelsOff', 'Div2TailNum', 'Div3Airport', 'Div3WheelsOn', 'Div3TotalGTime', 'Div3LongestGTime', 'Div3WheelsOff', 'Div3TailNum', 'Div4Airport', 'Div4WheelsOn', 'Div4TotalGTime', 'Div4LongestGTime', 'Div4WheelsOff', 'Div4TailNum', 'Div5Airport', 'Div5WheelsOn', 'Div5TotalGTime', 'Div5LongestGTime', 'Div5WheelsOff', 'Div5TailNum' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}'".format(', '.join(cols), sys.argv[1]) client = Client.from_url('clickhouse://localhost') for row in client.execute_iter(query): pass Iteration over int rows ^^^^^^^^^^^^^^^^^^^^^^^ Iteration over TSV (11) .. code-block:: python import sys import requests cols = [ 'Year', 'Quarter', 'Month', 'DayofMonth', 'DayOfWeek', 'AirlineID', 'OriginAirportID', 'OriginAirportSeqID', 'OriginCityMarketID', 'OriginWac', 'DestAirportID', 'DestAirportSeqID', 'DestCityMarketID', 'DestWac', 'CRSDepTime', 'DepTime', 'DepDelay', 'DepDelayMinutes', 'DepDel15', 'TaxiOut', 'WheelsOff', 'WheelsOn', 'TaxiIn', 'CRSArrTime', 'ArrTime', 'ArrDelay', 'ArrDelayMinutes', 'ArrDel15', 'ArrivalDelayGroups', 'Cancelled', 'Diverted', 'CRSElapsedTime', 'ActualElapsedTime', 'AirTime', 'Flights', 'Distance', 'DistanceGroup', 'CarrierDelay', 'WeatherDelay', 'NASDelay', 'SecurityDelay', 'LateAircraftDelay', 'Div1AirportID', 'Div1AirportSeqID', 'Div2AirportID', 'Div2AirportSeqID', 'Div3AirportID', 'Div3AirportSeqID', 'Div4AirportID', 'Div4AirportSeqID', 'Div5AirportID', 'Div5AirportSeqID' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}' FORMAT TSV".format(', '.join(cols), sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = [int(x) for x in line.split(b'\t')] Iteration over JSONEachRow (12) .. code-block:: python import sys import requests from ujson import loads cols = [ 'Year', 'Quarter', 'Month', 'DayofMonth', 'DayOfWeek', 'AirlineID', 'OriginAirportID', 'OriginAirportSeqID', 'OriginCityMarketID', 'OriginWac', 'DestAirportID', 'DestAirportSeqID', 'DestCityMarketID', 'DestWac', 'CRSDepTime', 'DepTime', 'DepDelay', 'DepDelayMinutes', 'DepDel15', 'TaxiOut', 'WheelsOff', 'WheelsOn', 'TaxiIn', 'CRSArrTime', 'ArrTime', 'ArrDelay', 'ArrDelayMinutes', 'ArrDel15', 'ArrivalDelayGroups', 'Cancelled', 'Diverted', 'CRSElapsedTime', 'ActualElapsedTime', 'AirTime', 'Flights', 'Distance', 'DistanceGroup', 'CarrierDelay', 'WeatherDelay', 'NASDelay', 'SecurityDelay', 'LateAircraftDelay', 'Div1AirportID', 'Div1AirportSeqID', 'Div2AirportID', 'Div2AirportSeqID', 'Div3AirportID', 'Div3AirportSeqID', 'Div4AirportID', 'Div4AirportSeqID', 'Div5AirportID', 'Div5AirportSeqID' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}' FORMAT JSONEachRow".format(', '.join(cols), sys.argv[1]) resp = requests.get('http://localhost:8123/', stream=True, params={'query': query}) for line in resp.iter_lines(chunk_size=10000): line = list(loads(line).values()) Iteration over int rows with ``clickhouse-driver`` in Native format (13) .. code-block:: python import sys from clickhouse_driver import Client cols = [ 'Year', 'Quarter', 'Month', 'DayofMonth', 'DayOfWeek', 'AirlineID', 'OriginAirportID', 'OriginAirportSeqID', 'OriginCityMarketID', 'OriginWac', 'DestAirportID', 'DestAirportSeqID', 'DestCityMarketID', 'DestWac', 'CRSDepTime', 'DepTime', 'DepDelay', 'DepDelayMinutes', 'DepDel15', 'TaxiOut', 'WheelsOff', 'WheelsOn', 'TaxiIn', 'CRSArrTime', 'ArrTime', 'ArrDelay', 'ArrDelayMinutes', 'ArrDel15', 'ArrivalDelayGroups', 'Cancelled', 'Diverted', 'CRSElapsedTime', 'ActualElapsedTime', 'AirTime', 'Flights', 'Distance', 'DistanceGroup', 'CarrierDelay', 'WeatherDelay', 'NASDelay', 'SecurityDelay', 'LateAircraftDelay', 'Div1AirportID', 'Div1AirportSeqID', 'Div2AirportID', 'Div2AirportSeqID', 'Div3AirportID', 'Div3AirportSeqID', 'Div4AirportID', 'Div4AirportSeqID', 'Div5AirportID', 'Div5AirportSeqID' ] query = "SELECT {} FROM perftest.ontime WHERE FlightDate < '{}'".format(', '.join(cols), sys.argv[1]) client = Client.from_url('clickhouse://localhost') for row in client.execute_iter(query): pass Results ------- This table contains memory and timing benchmark results of snippets above. JSON in table is shorthand for JSONEachRow. .. rst-class:: table-small-text table-center-header table-right-text-align-results +----------------------------------+-----------+-----------+-----------+-----------+-----------+ | | Rows | | +-----------+-----------+-----------+-----------+-----------+ | | 50k | 131k | 217k | 450k | 697k | +==================================+===========+===========+===========+===========+===========+ |**Plain text without parsing: timing** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |Naive requests.get TSV (1) | 0.40 s | 0.67 s | 0.95 s | 1.67 s | 2.52 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |Naive requests.get JSON (1) | 0.61 s | 1.23 s | 2.09 s | 3.52 s | 5.20 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Plain text without parsing: memory** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |Naive requests.get TSV (1) | 49 MB | 107 MB | 165 MB | 322 MB | 488 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |Naive requests.get JSON (1) | 206 MB | 564 MB | 916 MB | 1.83 GB | 2.83 GB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Parsed rows: timing** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (2) | 0.81 s | 1.81 s | 3.09 s | 7.22 s | 11.87 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV with cast (2.5) | 1.78 s | 4.58 s | 7.42 s | 16.12 s | 25.52 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (3) | 2.14 s | 5.65 s | 9.20 s | 20.43 s | 31.72 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (4) | 0.73 s | 1.40 s | 2.08 s | 4.03 s | 6.20 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Parsed rows: memory** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (2) | 171 MB | 462 MB | 753 MB | 1.51 GB | 2.33 GB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV with cast (2.5) | 135 MB | 356 MB | 576 MB | 1.15 GB | 1.78 GB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (3) | 139 MB | 366 MB | 591 MB | 1.18 GB | 1.82 GB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (4) | 135 MB | 337 MB | 535 MB | 1.05 GB | 1.62 GB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over rows: timing** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (5) | 0.49 s | 0.99 s | 1.34 s | 2.58 s | 4.00 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV with cast (5.5) | 1.38 s | 3.38 s | 5.40 s | 10.89 s | 16.59 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (6) | 1.89 s | 4.73 s | 7.63 s | 15.63 s | 24.60 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (7) | 0.62 s | 1.28 s | 1.93 s | 3.68 s | 5.54 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over rows: memory** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (5) | 19 MB | 19 MB | 19 MB | 19 MB | 19 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV with cast (5.5) | 19 MB | 19 MB | 19 MB | 19 MB | 19 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (6) | 20 MB | 20 MB | 20 MB | 20 MB | 20 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (7) | 56 MB | 70 MB | 71 MB | 71 MB | 71 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over string rows: timing** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (8) | 0.40 s | 0.67 s | 0.80 s | 1.55 s | 2.18 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (9) | 1.14 s | 2.64 s | 4.22 s | 8.48 s | 12.96 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (10) | 0.46 s | 0.91 s | 1.35 s | 2.49 s | 3.67 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over string rows: memory** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (8) | 19 MB | 19 MB | 19 MB | 19 MB | 19 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (9) | 20 MB | 20 MB | 20 MB | 20 MB | 20 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (10) | 46 MB | 56 MB | 57 MB | 57 MB | 57 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over int rows: timing** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (11) | 0.84 s | 2.06 s | 3.22 s | 6.27 s | 10.06 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (12) | 0.95 s | 2.15 s | 3.55 s | 6.93 s | 10.82 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (13) | 0.43 s | 0.61 s | 0.86 s | 1.53 s | 2.27 s | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |**Iteration over int rows: memory** | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get TSV (11) | 19 MB | 19 MB | 19 MB | 19 MB | 19 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |requests.get JSON (12) | 20 MB | 20 MB | 20 MB | 20 MB | 20 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ |clickhouse-driver Native (13) | 41 MB | 48 MB | 48 MB | 48 MB | 49 MB | +----------------------------------+-----------+-----------+-----------+-----------+-----------+ Conclusion ---------- If you need to get significant number of rows from ClickHouse server **as text** then TSV format is your choice. See **Iteration over string rows** results. But if you need to manipulate over python data types then you should take a look on drivers with Native format. For most data types driver uses binary :func:`~struct.pack` / :func:`~struct.unpack` for serialization / deserialization. Which is obviously faster than ``cls() for x in lst``. See (2.5) and (5.5). It doesn't matter which interface to use if you manipulate small amount of rows. python-clickhouse-driver-0.2.3/docs/quickstart.rst000066400000000000000000000152541420676740400223520ustar00rootroot00000000000000.. _quickstart: Quickstart ========== This page gives a good introduction to clickhouse-driver. It assumes you already have clickhouse-driver installed. If you do not, head over to the :ref:`installation` section. A minimal working example looks like this: .. code-block:: python >>> from clickhouse_driver import Client >>> >>> client = Client(host='localhost') >>> >>> client.execute('SHOW DATABASES') [('default',)] This code will show all tables from ``'default'`` database. There are two conceptual types of queries: - Read only queries: SELECT, SHOW, etc. - Read and write queries: INSERT. Every query should be executed by calling one of the client's execute methods: `execute`, `execute_with_progress`, `execute_iter method`. - SELECT queries can use `execute`, `execute_with_progress`, `execute_iter` methods. - INSERT queries can use only `execute` method. Selecting data -------------- Simple select query looks like: .. code-block:: python >>> client.execute('SELECT * FROM system.numbers LIMIT 5') [(0,), (1,), (2,), (3,), (4,)] Of course queries can and should be parameterized to avoid SQL injections: .. code-block:: python >>> from datetime import date >>> client.execute( ... 'SELECT %(date)s, %(a)s + %(b)s', ... {'date': date.today(), 'a': 1, 'b': 2} ... ) [('2018-10-21', 3)] Percent symbols in inlined constants should be doubled if you mix constants with ``%`` symbol and ``%(myvar)s`` parameters. .. code-block:: python >>> client.execute( ... "SELECT 'test' like '%%es%%', %(myvar)s", ... {'myvar': 1} ... ) NOTE: formatting queries using Python's f-strings or concatenation can lead to SQL injections. Use ``%(myvar)s`` parameters instead. Customisation ``SELECT`` output with ``FORMAT`` clause is not supported. .. _execute-with-progress: Selecting data with progress statistics --------------------------------------- You can get query progress statistics by using `execute_with_progress`. It can be useful for cancelling long queries. .. code-block:: python >>> from datetime import datetime >>> >>> progress = client.execute_with_progress( ... 'LONG AND COMPLICATED QUERY' ... ) >>> >>> timeout = 20 >>> started_at = datetime.now() >>> >>> for num_rows, total_rows in progress: ... if total_rows: ... done = float(num_rows) / total_rows ... else: ... done = total_rows ... ... now = datetime.now() ... elapsed = (now - started_at).total_seconds() ... # Cancel query if it takes more than 20 seconds ... # to process 50% of rows. ... if elapsed > timeout and done < 0.5: ... client.cancel() ... break ... else: ... rv = progress.get_result() ... print(rv) ... .. _execute-iter: Streaming results ----------------- When you are dealing with large datasets block by block results streaming may be useful: .. code-block:: python >>> settings = {'max_block_size': 100000} >>> rows_gen = client.execute_iter( ... 'QUERY WITH MANY ROWS', settings=settings ... ) >>> >>> for row in rows_gen: ... print(row) ... Inserting data -------------- Insert queries in `Native protocol `_ are a little bit tricky because of ClickHouse's columnar nature. And because we're using Python. INSERT query consists of two parts: query statement and query values. Query values are split into chunks called blocks. Each block is sent in binary columnar form. As data in each block is sent in binary we should not serialize into string by using substitution ``%(a)s`` and then deserialize it back into Python types. This INSERT would be extremely slow if executed with thousands rows of data: .. code-block:: python >>> client.execute( ... 'INSERT INTO test (x) VALUES (%(a)s), (%(b)s), ...', ... {'a': 1, 'b': 2, ...} ... ) To insert data efficiently, provide data separately, and end your statement with a ``VALUES`` clause: .. code-block:: python >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [{'x': 1}, {'x': 2}, {'x': 3}, {'x': 100}] ... ) 4 >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [[200]] ... ) 1 >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... ((x, ) for x in range(5)) ... ) 5 You can use any iterable yielding lists, tuples or dicts. If data is not passed, connection will be terminated after a timeout. .. code-block:: python >>> client.execute('INSERT INTO test (x) VALUES') # will hang The following WILL NOT work: .. code-block:: python >>> client.execute( ... 'INSERT INTO test (x) VALUES (%(a)s), (%(b)s)', ... {'a': 1, 'b': 2} ... ) Of course for ``INSERT ... SELECT`` queries data is not needed: .. code-block:: python >>> client.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 5} ... ) [] ClickHouse will execute this query like a usual ``SELECT`` query. Inserting data in different formats with ``FORMAT`` clause is not supported. See :ref:`insert-from-csv-file` if you need to data in custom format. DDL --- DDL queries can be executed in the same way SELECT queries are executed: .. code-block:: python >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute('CREATE TABLE test (x Int32) ENGINE = Memory') [] Async and multithreading ------------------------ Every ClickHouse query is assigned an identifier to enable request execution tracking. However, ClickHouse native protocol is synchronous: all incoming queries are executed consecutively. Clickhouse-driver does not yet implement a connection pool. To utilize ClickHouse's asynchronous capability you should either use multiple Client instances or implement a queue. The same thing is applied to multithreading. Queries from different threads can't use one Client instance with single connection. You should use different clients for different threads. However, if you are using DB API for communication with the server each cursor create its own Client instance. This makes communication thread-safe. python-clickhouse-driver-0.2.3/docs/types.rst000066400000000000000000000237061420676740400213250ustar00rootroot00000000000000 Supported types =============== Each ClickHouse type is deserialized to a corresponding Python type when SELECT queries are prepared. When serializing INSERT queries, clickhouse-driver accepts a broader range of Python types. The following ClickHouse types are supported by clickhouse-driver: [U]Int8/16/32/64/128/256 ------------------------ INSERT types: :class:`int`, :class:`long`. SELECT type: :class:`int`. Float32/64 ---------- INSERT types: :class:`float`, :class:`int`, :class:`long`. SELECT type: :class:`float`. Date/Date32 ----------- *Date32 support is new in version 0.2.2.* INSERT types: :class:`~datetime.date`, :class:`~datetime.datetime`. SELECT type: :class:`~datetime.date`. DateTime('timezone')/DateTime64('timezone') ------------------------------------------- *Timezone support is new in version 0.0.11.* *DateTime64 support is new in version 0.1.3.* INSERT types: :class:`~datetime.datetime`, :class:`int`, :class:`long`. Integers are interpreted as seconds without timezone (UNIX timestamps). Integers can be used when insertion of datetime column is a bottleneck. SELECT type: :class:`~datetime.datetime`. Setting `use_client_time_zone `_ is taken into consideration. You can cast DateTime column to integers if you are facing performance issues when selecting large amount of rows. Due to Python's current limitations minimal DateTime64 resolution is one microsecond. String/FixedString(N) --------------------- INSERT types: :class:`str`/:func:`basestring `, :class:`bytes`. See note below. SELECT type: :class:`str`/:func:`basestring `, :class:`bytes`. See note below. String column is encoded/decoded with encoding specified by ``strings_encoding`` setting. Default encoding is UTF-8. You can specify custom encoding: .. code-block:: python >>> settings = {'strings_encoding': 'cp1251'} >>> rows = client.execute( ... 'SELECT * FROM table_with_strings', ... settings=settings ... ) Encoding is applied to all string fields in query. String columns can be returned without any decoding. In this case return values are `bytes`: .. code-block:: python >>> settings = {'strings_as_bytes': True} >>> rows = client.execute( ... 'SELECT * FROM table_with_strings', ... settings=settings ... ) If a column has FixedString type, upon returning from SELECT it may contain trailing zeroes in accordance with ClickHouse's storage format. Trailing zeroes are stripped by driver for convenience. During SELECT, if a string cannot be decoded with specified encoding, it will return as :class:`bytes`. During INSERT, if ``strings_as_bytes`` setting is not specified and string cannot be encoded with encoding, a ``UnicodeEncodeError`` will be raised. Enum8/16 -------- INSERT types: :class:`~enum.Enum`, :class:`int`, :class:`long`, :class:`str`/:func:`basestring `. SELECT type: :class:`str`/:func:`basestring `. .. code-block:: python >>> from enum import IntEnum >>> >>> class MyEnum(IntEnum): ... foo = 1 ... bar = 2 ... >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute(''' ... CREATE TABLE test ... ( ... x Enum8('foo' = 1, 'bar' = 2) ... ) ENGINE = Memory ... ''') [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [{'x': MyEnum.foo}, {'x': 'bar'}, {'x': 1}] ... ) 3 >>> client.execute('SELECT * FROM test') [('foo',), ('bar',), ('foo',)] Currently clickhouse-driver can't handle empty enum value due to Python's `Enum` mechanics. Enum member name must be not empty. See `issue`_ and `workaround`_. .. _issue: https://github.com/mymarilyn/clickhouse-driver/issues/48 .. _workaround: https://github.com/mymarilyn/clickhouse-driver/issues/48#issuecomment-412480613 Array(T) -------- INSERT types: :class:`list`, :class:`tuple`. SELECT type: :class:`list`. *Versions before 0.1.4:* SELECT type: :class:`tuple`. .. code-block:: python >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute( ... 'CREATE TABLE test (x Array(Int32)) ' ... 'ENGINE = Memory' ... ) [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [{'x': [10, 20, 30]}, {'x': [11, 21, 31]}] ... ) 2 >>> client.execute('SELECT * FROM test') [((10, 20, 30),), ((11, 21, 31),)] Nullable(T) ----------- INSERT types: :data:`~types.NoneType`, ``T``. SELECT type: :data:`~types.NoneType`, ``T``. Bool ---- INSERT types: :class:`bool`, SELECT type: :class:`bool`. UUID ---- INSERT types: :class:`str`/:func:`basestring `, :class:`~uuid.UUID`. SELECT type: :class:`~uuid.UUID`. Decimal ------- *New in version 0.0.16.* INSERT types: :class:`~decimal.Decimal`, :class:`float`, :class:`int`, :class:`long`. SELECT type: :class:`~decimal.Decimal`. Supported subtypes: * Decimal(P, S). * Decimal32(S). * Decimal64(S). * Decimal128(S). * Decimal256(S). *New in version 0.2.1.* IPv4/IPv6 --------- *New in version 0.0.19.* INSERT types: :class:`~ipaddress.IPv4Address`/:class:`~ipaddress.IPv6Address`, :class:`int`, :class:`long`, :class:`str`/:func:`basestring `. SELECT type: :class:`~ipaddress.IPv4Address`/:class:`~ipaddress.IPv6Address`. .. code-block:: python >>> from ipaddress import IPv4Address, IPv6Address >>> >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute( ... 'CREATE TABLE test (x IPv4) ' ... 'ENGINE = Memory' ... ) [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', [ ... {'x': '192.168.253.42'}, ... {'x': 167772161}, ... {'x': IPv4Address('192.168.253.42')} ... ]) 3 >>> client.execute('SELECT * FROM test') [(IPv4Address('192.168.253.42'),), (IPv4Address('10.0.0.1'),), (IPv4Address('192.168.253.42'),)] >>> >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute( ... 'CREATE TABLE test (x IPv6) ' ... 'ENGINE = Memory' ... ) [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', [ ... {'x': '79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'}, ... {'x': IPv6Address('12ff:0000:0000:0000:0000:0000:0000:0001')}, ... {'x': b"y\xf4\xe6\x98E\xde\xa5\x9b'e(\xe3\x8d:5\xae"} ... ]) 3 >>> client.execute('SELECT * FROM test') [(IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), (IPv6Address('12ff::1'),), (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),)] >>> LowCardinality(T) ----------------- *New in version 0.0.20.* INSERT types: ``T``. SELECT type: ``T``. SimpleAggregateFunction(F, T) ----------------------------- *New in version 0.0.21.* INSERT types: ``T``. SELECT type: ``T``. AggregateFunctions for `AggregatingMergeTree` Engine are not supported. Tuple(T1, T2, ...) ------------------ *New in version 0.1.4.* INSERT types: :class:`list`, :class:`tuple`. SELECT type: :class:`tuple`. Nested(flatten_nested=1, default) ------ Nested type is represented by sequence of arrays when flatten_nested=1. In example below actual columns for are ``col.name`` and ``col.version``. .. code-block:: sql :) CREATE TABLE test_nested (col Nested(name String, version UInt16)) Engine = Memory; CREATE TABLE test_nested ( `col` Nested( name String, version UInt16) ) ENGINE = Memory Ok. 0 rows in set. Elapsed: 0.005 sec. :) DESCRIBE TABLE test_nested FORMAT TSV; DESCRIBE TABLE test_nested FORMAT TSV col.name Array(String) col.version Array(UInt16) 2 rows in set. Elapsed: 0.004 sec. Inserting data into nested column in ``clickhouse-client``: .. code-block:: sql :) INSERT INTO test_nested VALUES (['a', 'b', 'c'], [100, 200, 300]); INSERT INTO test_nested VALUES Ok. 1 rows in set. Elapsed: 0.003 sec. Inserting data into nested column with ``clickhouse-driver``: .. code-block:: python client.execute('INSERT INTO test_nested VALUES', [ (['a', 'b', 'c'], [100, 200, 300]), ]) Nested(flatten_nested=0) ------ Nested type is represented by array of named tuples when flatten_nested=0. .. code-block:: sql :) SET flatten_nested = 0; SET flatten_nested = 0 Ok. 0 rows in set. Elapsed: 0.006 sec. :) CREATE TABLE test_nested (col Nested(name String, version UInt16)) Engine = Memory; CREATE TABLE test_nested ( `col` Nested(name String, version UInt16) ) ENGINE = Memory Ok. 0 rows in set. Elapsed: 0.005 sec. :) DESCRIBE TABLE test_nested FORMAT TSV; DESCRIBE TABLE test_nested FORMAT TSV col Nested(name String, version UInt16) 1 rows in set. Elapsed: 0.004 sec. Inserting data into nested column in ``clickhouse-client``: .. code-block:: sql :) INSERT INTO test_nested VALUES ([('a', 100), ('b', 200), ('c', 300)]); INSERT INTO test_nested VALUES Ok. 1 rows in set. Elapsed: 0.003 sec. Inserting data into nested column with ``clickhouse-driver``: .. code-block:: python client.execute( 'INSERT INTO test_nested VALUES', [([('a', 100), ('b', 200), ('c', 300)]),] ) # or client.execute( 'INSERT INTO test_nested VALUES', [{'col': [{'name': 'a', 'version': 100}, {'name': 'b', 'version': 200}, {'name': 'c', 'version': 300}]}] ) Map(key, value) ------------------ *New in version 0.2.1.* INSERT types: :class:`dict`. SELECT type: :class:`dict`. python-clickhouse-driver-0.2.3/docs/unsupportedserverversions.rst000066400000000000000000000003361420676740400255630ustar00rootroot00000000000000 Unsupported server versions =========================== Following versions are not supported by this package: - 20.1.*. Due to keeping alias type name to metadata. However you can use these versions for your own risk. python-clickhouse-driver-0.2.3/setup.cfg000066400000000000000000000003121420676740400203040ustar00rootroot00000000000000[db] host=localhost port=9000 database=test user=default password= compression=lz4,lz4hc,zstd client=clickhouse-client [log] level=ERROR [bdist_wheel] universal = 0 [metadata] license_file = LICENSE python-clickhouse-driver-0.2.3/setup.py000066400000000000000000000073711420676740400202110ustar00rootroot00000000000000import os import re from codecs import open from setuptools import setup, find_packages from distutils.extension import Extension try: from Cython.Build import cythonize except ImportError: USE_CYTHON = False else: USE_CYTHON = True CYTHON_TRACE = bool(os.getenv('CYTHON_TRACE', False)) here = os.path.abspath(os.path.dirname(__file__)) def read_version(): regexp = re.compile(r'^VERSION\W*=\W*\(([^\(\)]*)\)') init_py = os.path.join(here, 'clickhouse_driver', '__init__.py') with open(init_py, encoding='utf-8') as f: for line in f: match = regexp.match(line) if match is not None: return match.group(1).replace(', ', '.') else: raise RuntimeError( 'Cannot find version in clickhouse_driver/__init__.py' ) with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = f.read() # Prepare extensions. ext = '.pyx' if USE_CYTHON else '.c' extensions = [ Extension( 'clickhouse_driver.bufferedreader', ['clickhouse_driver/bufferedreader' + ext] ), Extension( 'clickhouse_driver.bufferedwriter', ['clickhouse_driver/bufferedwriter' + ext] ), Extension( 'clickhouse_driver.columns.largeint', ['clickhouse_driver/columns/largeint' + ext] ), Extension( 'clickhouse_driver.varint', ['clickhouse_driver/varint' + ext] ) ] if USE_CYTHON: compiler_directives = {'language_level': '3'} if CYTHON_TRACE: compiler_directives['linetrace'] = True extensions = cythonize(extensions, compiler_directives=compiler_directives) setup( name='clickhouse-driver', version=read_version(), description='Python driver with native interface for ClickHouse', long_description=long_description, url='https://github.com/mymarilyn/clickhouse-driver', author='Konstantin Lebedev', author_email='kostyan.lebedev@gmail.com', license='MIT', classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Console', 'Intended Audience :: Developers', 'Intended Audience :: Information Technology', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: SQL', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Database', 'Topic :: Software Development', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Application Frameworks', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Scientific/Engineering :: Information Analysis' ], keywords='ClickHouse db database cloud analytics', project_urls={ 'Documentation': 'https://clickhouse-driver.readthedocs.io', }, packages=find_packages('.', exclude=['tests*']), python_requires='>=3.4.*, <4', install_requires=[ 'pytz', 'tzlocal', 'tzlocal<2.1; python_version=="3.5"' ], ext_modules=extensions, extras_require={ 'lz4': [ 'lz4<=3.0.1; implementation_name=="pypy"', 'lz4; implementation_name!="pypy"', 'clickhouse-cityhash>=1.0.2.1' ], 'zstd': ['zstd', 'clickhouse-cityhash>=1.0.2.1'], 'numpy': ['numpy>=1.12.0', 'pandas>=0.24.0'] }, test_suite='pytest' ) python-clickhouse-driver-0.2.3/tests/000077500000000000000000000000001420676740400176315ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/__init__.py000066400000000000000000000000001420676740400217300ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/columns/000077500000000000000000000000001420676740400213115ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/columns/__init__.py000066400000000000000000000000001420676740400234100ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/columns/test_array.py000066400000000000000000000205151420676740400240430ustar00rootroot00000000000000from uuid import UUID from tests.testcase import BaseTestCase from clickhouse_driver import errors from tests.util import require_server_version class ArrayTestCase(BaseTestCase): def test_empty(self): columns = 'a Array(Int32)' data = [([], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '[]\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_simple(self): columns = 'a Array(Int32)' data = [([100, 500], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '[100,500]\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_write_column_as_nested_array(self): columns = 'a Array(Int32)' data = [([100, 500], ), ([100, 500], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '[100,500]\n[100,500]\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nested_with_enum(self): columns = "a Array(Array(Enum8('hello' = -1, 'world' = 2)))" data = [([['hello', 'world'], ['hello']], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "[['hello','world'],['hello']]\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nested_of_nested(self): columns = 'a Array(Array(Array(Int32))), b Array(Array(Array(Int32)))' data = [([ [[255, 170], [127, 127, 127, 127, 127], [170, 170, 170], [170]], [[255, 255, 255], [255]], [[255], [255], [255]] ], [ [[255, 170], [127, 127, 127, 127, 127], [170, 170, 170], [170]], [[255, 255, 255], [255]], [[255], [255], [255]] ])] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '[[[255,170],[127,127,127,127,127],[170,170,170],[170]],' '[[255,255,255],[255]],[[255],[255],[255]]]\t' '[[[255,170],[127,127,127,127,127],[170,170,170],[170]],' '[[255,255,255],[255]],[[255],[255],[255]]]\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_multidimensional(self): columns = "a Array(Array(Array(Nullable(String))))" data = [([[['str1_1', 'str1_2', None], [None]], [['str1_3', 'str1_4', None], [None]]], ), ([[['str2_1', 'str2_2', None], [None]]], ), ([[['str3_1', 'str3_2', None], [None]]],)] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '[[[\'str1_1\',\'str1_2\',NULL],[NULL]],' '[[\'str1_3\',\'str1_4\',NULL],[NULL]]]\n' '[[[\'str2_1\',\'str2_2\',NULL],[NULL]]]\n' '[[[\'str3_1\',\'str3_2\',NULL],[NULL]]]\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_empty_nested(self): columns = "a Array(Array(Array(Int32))), b Array(Array(Array(Int32)))" data = [ ([], [[]],), ] with self.create_table(columns): self.client.execute("INSERT INTO test (a, b) VALUES", data) query = "SELECT * FROM test" inserted = self.emit_cli(query) self.assertEqual( inserted, "[]\t[[]]\n", ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_type_mismatch_error(self): columns = 'a Array(Int32)' data = [('test', )] with self.create_table(columns): with self.assertRaises(errors.TypeMismatchError): self.client.execute('INSERT INTO test (a) VALUES', data) data = [(['test'], )] with self.create_table(columns): with self.assertRaises(errors.TypeMismatchError): self.client.execute('INSERT INTO test (a) VALUES', data) def test_string_array(self): columns = 'a Array(String)' data = [(['aaa', 'bbb'], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "['aaa','bbb']\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_string_nullable_array(self): columns = 'a Array(Nullable(String))' data = [(['aaa', None, 'bbb'], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "['aaa',NULL,'bbb']\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_uuid_array(self): columns = 'a Array(UUID)' data = [([ UUID('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'), UUID('2efcead4-ff55-4db5-bdb4-6b36a308d8e0') ], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "['c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'," "'2efcead4-ff55-4db5-bdb4-6b36a308d8e0']\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_uuid_nullable_array(self): columns = 'a Array(Nullable(UUID))' data = [([ UUID('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'), None, UUID('2efcead4-ff55-4db5-bdb4-6b36a308d8e0') ], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "['c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'," "NULL," "'2efcead4-ff55-4db5-bdb4-6b36a308d8e0']\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) @require_server_version(19, 16, 13) def test_tuple_array(self): columns = 'a Array(Tuple(Int32))' data = [([], )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "[]\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_bool.py000066400000000000000000000040351420676740400236570ustar00rootroot00000000000000from tests.testcase import BaseTestCase from clickhouse_driver import errors class BoolTestCase(BaseTestCase): required_server_version = (21, 12) def test_simple(self): columns = ("a Bool") data = [(1,), (0,), (True,), (False,), (None,), ("False",), ("",)] with self.create_table(columns): self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'true\n' 'false\n' 'true\n' 'false\n' 'false\n' 'true\n' 'false\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ (True, ), (False, ), (True, ), (False, ), (False, ), (True, ), (False, ), ] ) def test_errors(self): columns = "a Bool" with self.create_table(columns): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', [(1, )], types_check=True ) def test_nullable(self): columns = "a Nullable(Bool)" data = [(None, ), (True, ), (False, )] with self.create_table(columns): self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( '\\N\ntrue\nfalse\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ (None, ), (True, ), (False, ), ] ) python-clickhouse-driver-0.2.3/tests/columns/test_common.py000066400000000000000000000033501420676740400242130ustar00rootroot00000000000000from tests.testcase import BaseTestCase class CommonTestCase(BaseTestCase): client_kwargs = {'settings': {'insert_block_size': 1}} def setUp(self): super(CommonTestCase, self).setUp() self.send_data_count = 0 old_send_data = self.client.connection.send_data def send_data(*args, **kwargs): self.send_data_count += 1 return old_send_data(*args, **kwargs) self.client.connection.send_data = send_data def test_insert_block_size(self): with self.create_table('a UInt8'): data = [(x, ) for x in range(4)] self.client.execute( 'INSERT INTO test (a) VALUES', data ) # Two empty blocks: for end of sending external tables # and data. self.assertEqual(self.send_data_count, 4 + 2) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '0\n1\n2\n3\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_columnar_insert_block_size(self): with self.create_table('a UInt8'): data = [(0, 1, 2, 3)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) # Two empty blocks: for end of sending external tables # and data. self.assertEqual(self.send_data_count, 4 + 2) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '0\n1\n2\n3\n') inserted = self.client.execute(query) expected = [(0, ), (1, ), (2, ), (3, )] self.assertEqual(inserted, expected) python-clickhouse-driver-0.2.3/tests/columns/test_date.py000066400000000000000000000070151420676740400236420ustar00rootroot00000000000000import os from datetime import date, datetime from unittest.mock import patch from freezegun import freeze_time from tests.testcase import BaseTestCase class DateTestCase(BaseTestCase): @freeze_time('2017-03-05 03:00:00') def test_do_not_use_timezone(self): with self.create_table('a Date'): data = [(date(1970, 1, 2), )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1970-01-02\n') with patch.dict(os.environ, {'TZ': 'US/Hawaii'}): inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_insert_datetime_to_date(self): with self.create_table('a Date'): testTime = datetime(2015, 6, 6, 12, 30, 54) self.client.execute( 'INSERT INTO test (a) VALUES', [(testTime, )] ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2015-06-06\n') def test_wrong_date_insert(self): with self.create_table('a Date'): data = [ (date(5555, 1, 1), ), (date(1, 1, 1), ), (date(2149, 6, 7), ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) expected = ( 3*'1970-01-01\n' if self.server_version > (20, 7, 2) else 3*'0000-00-00\n' ) self.assertEqual(inserted, expected) def test_boundaries(self): extended_date = self.server_version > (21, 4) with self.create_table('a Date'): data = [ (date(1970, 1, 1), ), ((date(2149, 6, 6) if extended_date else date(2106, 2, 7)), ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) if extended_date: expected = '1970-01-01\n2149-06-06\n' else: if self.server_version > (20, 7, 2): expected = '1970-01-01\n2106-02-07\n' else: expected = '0000-00-00\n2106-02-07\n' self.assertEqual(inserted, expected) inserted = self.client.execute(query) self.assertEqual(inserted, data) class Date32TestCase(BaseTestCase): required_server_version = (21, 9) def test_wrong_date_insert(self): with self.create_table('a Date32'): data = [ (date(5555, 1, 1), ), (date(1, 1, 1), ), (date(2284, 1, 1), ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1970-01-01\n1970-01-01\n1970-01-01\n') def test_boundaries(self): with self.create_table('a Date32'): data = [(date(1925, 1, 1), ), (date(2283, 11, 11), )] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1925-01-01\n2283-11-11\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_datetime.py000066400000000000000000000446531420676740400245320ustar00rootroot00000000000000from datetime import date, datetime from unittest.mock import patch from pytz import timezone, utc, UnknownTimeZoneError import tzlocal from tests.testcase import BaseTestCase from tests.util import require_server_version, patch_env_tz class DateTimeTestCase(BaseTestCase): def test_simple(self): with self.create_table('a Date, b DateTime'): data = [(date(2012, 10, 25), datetime(2012, 10, 25, 14, 7, 19))] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25\t2012-10-25 14:07:19\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable_date(self): with self.create_table('a Nullable(Date)'): data = [ (None, ), (date(2012, 10, 25), ), (None, ), (date(2017, 6, 23), ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\n2012-10-25\n\\N\n2017-06-23\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable_datetime(self): with self.create_table('a Nullable(DateTime)'): data = [ (None, ), (datetime(2012, 10, 25, 14, 7, 19), ), (None, ), (datetime(2017, 6, 23, 19, 10, 15), ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\n2012-10-25 14:07:19\n\\N\n2017-06-23 19:10:15\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_handle_errors_from_tzlocal(self): with patch('tzlocal.get_localzone') as mocked: mocked.side_effect = UnknownTimeZoneError() self.client.execute('SELECT now()') if hasattr(tzlocal, 'get_localzone_name'): with patch('tzlocal.get_localzone_name') as mocked: mocked.side_effect = None self.client.execute('SELECT now()') @require_server_version(20, 1, 2) def test_datetime64_frac_trunc(self): with self.create_table('a DateTime64'): data = [(datetime(2012, 10, 25, 14, 7, 19, 125600), )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25 14:07:19.125\n') inserted = self.client.execute(query) self.assertEqual( inserted, [(datetime(2012, 10, 25, 14, 7, 19, 125000), )] ) def test_insert_integers(self): with self.create_table('a DateTime'): self.client.execute( 'INSERT INTO test (a) VALUES', [(1530211034, )] ) query = 'SELECT toUInt32(a), a FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1530211034\t2018-06-28 21:37:14\n') @require_server_version(20, 1, 2) def test_insert_integers_datetime64(self): with self.create_table('a DateTime64'): self.client.execute( 'INSERT INTO test (a) VALUES', [(1530211034123, )] ) query = 'SELECT toUInt32(a), a FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1530211034\t2018-06-28 21:37:14.123\n') def test_insert_integer_bounds(self): with self.create_table('a DateTime'): self.client.execute( 'INSERT INTO test (a) VALUES', [(0, ), (1, ), (1500000000, ), (2**32-1, )] ) query = 'SELECT toUInt32(a) FROM test ORDER BY a' inserted = self.emit_cli(query) self.assertEqual(inserted, '0\n1\n1500000000\n4294967295\n') @require_server_version(21, 4) def test_insert_datetime64_extended_range(self): with self.create_table('a DateTime64(0)'): self.client.execute( 'INSERT INTO test (a) VALUES', [(-1420077600, ), (-1420077599, ), (0, ), (1, ), (9877248000, )] ) query = 'SELECT toInt64(a), a FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '-1420077600\t1925-01-01 00:00:00\n' '-1420077599\t1925-01-01 00:00:01\n' '0\t1970-01-01 03:00:00\n' '1\t1970-01-01 03:00:01\n' '9877248000\t2282-12-31 03:00:00\n' ) query = 'SELECT a FROM test ORDER BY a' inserted = self.client.execute(query) self.assertEqual( inserted, [ (datetime(1925, 1, 1, 0, 0, 0), ), (datetime(1925, 1, 1, 0, 0, 1), ), (datetime(1970, 1, 1, 3, 0, 0), ), (datetime(1970, 1, 1, 3, 0, 1), ), (datetime(2282, 12, 31, 3, 0, 0), ) ] ) @require_server_version(21, 4) def test_insert_datetime64_extended_range_pure_ints_out_of_range(self): with self.create_table('a DateTime64(0)'): self.client.execute( 'INSERT INTO test (a) VALUES', [(0, ), (1, ), (-2**63, ), (2**63-1, )] ) query = 'SELECT toInt64(a) FROM test ORDER BY a' inserted = self.emit_cli(query) self.assertEqual( inserted, '-9223372036854775808\n0\n1\n9223372036854775807\n' ) class DateTimeTimezonesTestCase(BaseTestCase): dt_type = 'DateTime' # Asia/Kamchatka = UTC+12 # Asia/Novosibirsk = UTC+7 # Europe/Moscow = UTC+3 # 1500010800 second since epoch in Europe/Moscow. # 1500000000 second since epoch in UTC. dt = datetime(2017, 7, 14, 5, 40) dt_tz = timezone('Asia/Kamchatka').localize(dt) col_tz_name = 'Asia/Novosibirsk' col_tz = timezone(col_tz_name) # INSERTs and SELECTs must be the same as clickhouse-client's # if column has no timezone. def table_columns(self, with_tz=False): if not with_tz: return 'a {}'.format(self.dt_type) return "a {}('{}')".format(self.dt_type, self.col_tz_name) def test_use_server_timezone(self): # Insert datetime with timezone UTC # into column with no timezone # using server's timezone (Europe/Moscow) # Determine server timezone and calculate expected timestamp. server_tz_name = self.client.execute('SELECT timezone()')[0][0] offset = timezone(server_tz_name).utcoffset(self.dt).total_seconds() timestamp = 1500010800 - int(offset) with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt, )] ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')" ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '{ts}\n{ts}\n'.format(ts=timestamp)) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, [(self.dt, ), (self.dt, )]) def test_use_client_timezone(self): # Insert datetime with timezone UTC # into column with no timezone # using client's timezone Asia/Novosibirsk settings = {'use_client_time_zone': True} with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt, )], settings=settings ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, settings=settings) self.assertEqual(inserted, [(self.dt, ), (self.dt, )]) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_use_server_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with no timezone # using server's timezone (Europe/Moscow) server_tz_name = self.client.execute('SELECT timezone()')[0][0] offset = timezone(server_tz_name).utcoffset(self.dt) with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt_tz, )] ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) dt = (self.dt_tz.astimezone(utc) + offset).replace(tzinfo=None) self.assertEqual(inserted, '{dt}\n{dt}\n'.format(dt=dt)) inserted = self.client.execute(query) self.assertEqual(inserted, [(dt, ), (dt, )]) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_use_client_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with no timezone # using client's timezone Asia/Novosibirsk settings = {'use_client_time_zone': True} with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt_tz, )], settings=settings ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query, settings=settings) dt = datetime(2017, 7, 14, 0, 40) self.assertEqual(inserted, [(dt, ), (dt, )]) @require_server_version(1, 1, 54337) def test_column_use_server_timezone(self): # Insert datetime with no timezone # into column with timezone Asia/Novosibirsk # using server's timezone (Europe/Moscow) with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt, )] ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')" ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, [ (self.col_tz.localize(self.dt), ), (self.col_tz.localize(self.dt), ) ]) @require_server_version(1, 1, 54337) def test_column_use_client_timezone(self): # Insert datetime with no timezone # into column with timezone Asia/Novosibirsk # using client's timezone Europe/Moscow settings = {'use_client_time_zone': True} with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt, )], settings=settings ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, settings=settings) self.assertEqual(inserted, [ (self.col_tz.localize(self.dt), ), (self.col_tz.localize(self.dt), ) ]) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_column_use_server_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with timezone Asia/Novosibirsk # using server's timezone (Europe/Moscow) with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt_tz, )] ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query) dt = datetime(2017, 7, 14, 0, 40) self.assertEqual(inserted, [ (self.col_tz.localize(dt), ), (self.col_tz.localize(dt), ) ]) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_column_use_client_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with timezone Asia/Novosibirsk # using client's timezone (Europe/Moscow) settings = {'use_client_time_zone': True} with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [(self.dt_tz, )], settings=settings ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query, settings=settings) dt = datetime(2017, 7, 14, 0, 40) self.assertEqual(inserted, [ (self.col_tz.localize(dt), ), (self.col_tz.localize(dt), ) ]) class DateTime64TimezonesTestCase(DateTimeTimezonesTestCase): dt_type = 'DateTime64' required_server_version = (20, 1, 2) def table_columns(self, with_tz=False): if not with_tz: return 'a {}(0)'.format(self.dt_type) return "a {}(0, '{}')".format(self.dt_type, self.col_tz_name) python-clickhouse-driver-0.2.3/tests/columns/test_decimal.py000066400000000000000000000236351420676740400243310ustar00rootroot00000000000000from decimal import Decimal from clickhouse_driver import errors from tests.testcase import BaseTestCase from tests.util import require_server_version class DecimalTestCase(BaseTestCase): required_server_version = (18, 12, 13) stable_support_version = (18, 14, 9) trailing_zeros_version = (21, 9) def client_kwargs(self, version): if version < self.stable_support_version: return {'settings': {'allow_experimental_decimal_type': True}} def cli_client_kwargs(self): if self.stable_support_version > self.server_version: return {'allow_experimental_decimal_type': 1} def test_simple(self): with self.create_table('a Decimal(9, 5)'): data = [(Decimal('300.42'), ), (300.42, ), (-300, )] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) if self.server_version < self.trailing_zeros_version: expected = '300.42000\n300.42000\n-300.00000\n' else: expected = '300.42\n300.42\n-300\n' self.assertEqual(inserted, expected) inserted = self.client.execute(query) self.assertEqual(inserted, [ (Decimal('300.42'), ), (Decimal('300.42'), ), (Decimal('-300'), ) ]) @require_server_version(18, 12, 17) def test_different_precisions(self): columns = 'a Decimal32(2), b Decimal64(2), c Decimal128(2)' with self.create_table(columns): data = [( Decimal('300.42'), # 300.42 + (1 << 34) Decimal('17179869484.42'), # 300.42 + (1 << 100) Decimal('1267650600228229401496703205676.42') )] self.client.execute( 'INSERT INTO test (a, b, c) VALUES', data ) # Casting to string saves precision. query = ( 'SELECT ' 'CAST(a AS String), CAST(b AS String), CAST(c AS String)' 'FROM test' ) inserted = self.emit_cli(query) self.assertEqual( inserted, '300.42\t' '17179869484.42\t' '1267650600228229401496703205676.42\n' ) inserted = self.client.execute('SELECT * FROM test') self.assertEqual(inserted, data) @require_server_version(18, 12, 17) def test_different_precisions_negative(self): columns = 'a Decimal32(2), b Decimal64(2), c Decimal128(2)' with self.create_table(columns): data = [( Decimal('-300.42'), # 300.42 + (1 << 34) Decimal('-17179869484.42'), # 300.42 + (1 << 100) Decimal('-1267650600228229401496703205676.42') )] self.client.execute( 'INSERT INTO test (a, b, c) VALUES', data ) # Casting to string saves precision. query = ( 'SELECT ' 'CAST(a AS String), CAST(b AS String), CAST(c AS String)' 'FROM test' ) inserted = self.emit_cli(query) self.assertEqual( inserted, '-300.42\t' '-17179869484.42\t' '-1267650600228229401496703205676.42\n' ) inserted = self.client.execute('SELECT * FROM test') self.assertEqual(inserted, data) @require_server_version(18, 12, 17) def test_max_precisions(self): columns = 'a Decimal32(0), b Decimal64(0), c Decimal128(0)' with self.create_table(columns): data = [( Decimal(10**9 - 1), Decimal(10**18 - 1), Decimal(10**38 - 1) ), ( Decimal(-10**9 + 1), Decimal(-10**18 + 1), Decimal(-10**38 + 1) )] self.client.execute( 'INSERT INTO test (a, b, c) VALUES', data ) # Casting to string saves precision. query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '999999999\t' '999999999999999999\t' '99999999999999999999999999999999999999\n' '-999999999\t' '-999999999999999999\t' '-99999999999999999999999999999999999999\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable(self): with self.create_table('a Nullable(Decimal32(3))'): data = [(300.42, ), (None, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) if self.server_version < self.trailing_zeros_version: expected = '300.420\n\\N\n' else: expected = '300.42\n\\N\n' self.assertEqual(inserted, expected) inserted = self.client.execute(query) self.assertEqual(inserted, [(Decimal('300.42'), ), (None, ), ]) def test_no_scale(self): with self.create_table('a Decimal32(0)'): data = [(2147483647, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2147483647\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(Decimal('2147483647'), )]) def test_type_mismatch(self): data = [(2147483649, )] with self.create_table('a Decimal32(0)'): with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('2147483649 for column "a"', str(e.exception)) with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data ) self.assertIn('Column a', str(e.exception)) def test_type_mismatch_scale(self): data = [(1.234,)] with self.create_table('a Decimal32(2)'): with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('1.234 for column "a"', str(e.exception)) # Without types_check decimal will be cropped. self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1.23\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(Decimal('1.23'), )]) def test_preserve_precision(self): data = [(1.66, ), (1.15, )] with self.create_table('a Decimal(18, 2)'): self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1.66\n1.15\n') inserted = self.client.execute(query) self.assertEqual(inserted, [ (Decimal('1.66'), ), (Decimal('1.15'), ) ]) def test_precision_one_sign_after_point(self): data = [(1.6, ), (1.0, ), (12312.0, ), (999999.6, )] with self.create_table('a Decimal(8, 1)'): self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) if self.server_version < self.trailing_zeros_version: expected = '1.6\n1.0\n12312.0\n999999.6\n' else: expected = '1.6\n1\n12312\n999999.6\n' self.assertEqual(inserted, expected) inserted = self.client.execute(query) self.assertEqual(inserted, [ (Decimal('1.6'),), (Decimal('1.0'),), (Decimal('12312.0'),), (Decimal('999999.6'),) ]) class Decimal256TestCase(BaseTestCase): required_server_version = (18, 12, 13) def cli_client_kwargs(self): return {'allow_experimental_bigint_types': 1} @require_server_version(20, 9, 2) def test_decimal256(self): data = [ (1.66, ), (1.15, ), # 300.42 + (1 << 200) (Decimal('1606938044258990275541962092341162602522202993782792835301676.42'), ), # noqa: E501 (Decimal('-1606938044258990275541962092341162602522202993782792835301676.42'), ) # noqa: E501 ] with self.create_table('a Decimal256(2)'): self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '1.66\n' '1.15\n' '1606938044258990275541962092341162602522202993782792835301676.42\n' # noqa: E501 '-1606938044258990275541962092341162602522202993782792835301676.42\n' # noqa: E501 ) inserted = self.client.execute(query) self.assertEqual(inserted, [ (Decimal('1.66'), ), (Decimal('1.15'), ), (Decimal('1606938044258990275541962092341162602522202993782792835301676.42'), ), # noqa: E501 (Decimal('-1606938044258990275541962092341162602522202993782792835301676.42'), ) # noqa: E501 ]) python-clickhouse-driver-0.2.3/tests/columns/test_enum.py000066400000000000000000000106051420676740400236700ustar00rootroot00000000000000from enum import IntEnum from tests.testcase import BaseTestCase from clickhouse_driver import errors class A(IntEnum): hello = -1 world = 2 class B(IntEnum): foo = -300 bar = 300 class EnumTestCase(BaseTestCase): def test_simple(self): columns = ( "a Enum8('hello' = -1, 'world' = 2), " "b Enum16('foo' = -300, 'bar' = 300)" ) data = [(A.hello, B.bar), (A.world, B.foo), (-1, 300), (2, -300)] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'hello\tbar\n' 'world\tfoo\n' 'hello\tbar\n' 'world\tfoo\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ ('hello', 'bar'), ('world', 'foo'), ('hello', 'bar'), ('world', 'foo') ] ) def test_enum_by_string(self): columns = "a Enum8('hello' = 1, 'world' = 2)" data = [('hello', ), ('world', )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'hello\n' 'world\n' ) ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_errors(self): columns = "a Enum8('test' = 1, 'me' = 2)" data = [(A.world, )] with self.create_table(columns): with self.assertRaises(errors.LogicalError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) columns = "a Enum8('test' = 1, 'me' = 2)" data = [(3, )] with self.create_table(columns): with self.assertRaises(errors.LogicalError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_quote_in_name(self): columns = "a Enum8(' \\' t = ' = -1, 'test' = 2)" data = [(-1, ), (" ' t = ", )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( " \\' t = \n" " \\' t = \n" ) ) inserted = self.client.execute(query) self.assertEqual(inserted, [(" ' t = ", ), (" ' t = ", )]) def test_comma_and_space_in_name(self): columns = "a Enum8('one' = 1, 'two_with_comma, ' = 2, 'three' = 3)" data = [(2, ), ('two_with_comma, ', )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'two_with_comma, \n' 'two_with_comma, \n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [('two_with_comma, ',), ('two_with_comma, ',)] ) def test_nullable(self): columns = "a Nullable(Enum8('hello' = -1, 'world' = 2))" data = [(None, ), (A.hello, ), (None, ), (A.world, )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( '\\N\nhello\n\\N\nworld\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ (None, ), ('hello', ), (None, ), ('world', ), ] ) python-clickhouse-driver-0.2.3/tests/columns/test_fixedstring.py000066400000000000000000000172361420676740400252610ustar00rootroot00000000000000# coding=utf-8 from __future__ import unicode_literals from tests.testcase import BaseTestCase from clickhouse_driver import errors class FixedStringTestCase(BaseTestCase): def test_simple(self): data = [('a', ), ('bb', ), ('ccc', ), ('dddd', ), ('я', )] with self.create_table('a FixedString(4)'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'a\\0\\0\\0\n' 'bb\\0\\0\n' 'ccc\\0\n' 'dddd\n' 'я\\0\\0\n' ) ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_non_utf(self): data = [('яндекс'.encode('koi8-r'), )] with self.create_table('a FixedString(6)'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='koi8-r') self.assertEqual(inserted, 'яндекс\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_oversized(self): columns = 'a FixedString(4)' data = [('aaaaa', )] with self.create_table(columns): with self.assertRaises(errors.TooLargeStringSize): self.client.execute( 'INSERT INTO test (a) VALUES', data ) data = [('тест', )] with self.create_table(columns): with self.assertRaises(errors.TooLargeStringSize): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_nullable(self): with self.create_table('a Nullable(FixedString(10))'): data = [(None, ), ('test', ), (None, ), ('nullable', )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_null_byte_in_the_middle(self): data = [('test\0test', )] with self.create_table('a FixedString(9)'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_empty(self): data = [('',)] with self.create_table('a FixedString(5)'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_custom_encoding(self): settings = {'strings_encoding': 'cp1251'} data = [(('яндекс'), ), (('test'), )] with self.create_table('a FixedString(10)'): self.client.execute( 'INSERT INTO test (a) VALUES', data, settings=settings ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='cp1251') self.assertEqual( inserted, 'яндекс\\0\\0\\0\\0\n' 'test\\0\\0\\0\\0\\0\\0\n' ) inserted = self.client.execute(query, settings=settings) self.assertEqual(inserted, data) self.assertIsInstance(inserted[0][0], str) self.assertIsInstance(inserted[1][0], str) def test_not_supported_types(self): datas = [ [(bytearray(b'asd'), )], [(123, )] ] with self.create_table('a String'): for data in datas: with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('for column "a"', str(e.exception)) with self.assertRaises(AttributeError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) class ByteFixedStringTestCase(BaseTestCase): client_kwargs = {'settings': {'strings_as_bytes': True}} def test_oversized(self): columns = 'a FixedString(4)' data = [(bytes('aaaaa'.encode('utf-8')), )] with self.create_table(columns): with self.assertRaises(errors.TooLargeStringSize): self.client.execute( 'INSERT INTO test (a) VALUES', data ) data = [(bytes('тест'.encode('utf-8')), )] with self.create_table(columns): with self.assertRaises(errors.TooLargeStringSize): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_not_decoded(self): data = [ (bytes('яндекс'.encode('cp1251')), ), (bytes('test'.encode('cp1251')), ), ] with self.create_table('a FixedString(8)'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='cp1251') self.assertEqual( inserted, 'яндекс\\0\\0\ntest\\0\\0\\0\\0\n' ) inserted = self.client.execute(query) # Assert items with trailing zeros self.assertEqual( inserted, [ ('яндекс'.encode('cp1251') + b'\x00' * 2, ), ('test'.encode('cp1251') + b'\x00' * 4, ) ] ) self.assertIsInstance(inserted[0][0], bytes) self.assertIsInstance(inserted[1][0], bytes) def test_nullable(self): with self.create_table('a Nullable(FixedString(10))'): data = [ (None, ), (b'test\x00\x00\x00\x00\x00\x00', ), (None, ), (b'nullable\x00\x00', ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_not_supported_types(self): datas = [ [('asd', )], [(bytearray(b'asd'), )], [(123, )] ] with self.create_table('a String'): for data in datas: with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('for column "a"', str(e.exception)) with self.assertRaises(ValueError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data ) self.assertIn('bytes object expected', str(e.exception)) python-clickhouse-driver-0.2.3/tests/columns/test_float.py000066400000000000000000000052371420676740400240360ustar00rootroot00000000000000import math from tests.testcase import BaseTestCase from clickhouse_driver import errors class FloatTestCase(BaseTestCase): def test_chop_to_type(self): with self.create_table('a Float32, b Float64'): data = [ (3.4028235e38, 3.4028235e38), (3.4028235e39, 3.4028235e39), (-3.4028235e39, 3.4028235e39), (1, 2) ] with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) self.assertIn('Column a', str(e.exception)) def test_simple(self): with self.create_table('a Float32, b Float64'): data = [ (3.4028235e38, 3.4028235e38), (3.4028235e39, 3.4028235e39), (-3.4028235e39, 3.4028235e39), (1, 2) ] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( '3.4028235e38\t3.4028235e38\n' 'inf\t3.4028235e39\n' '-inf\t3.4028235e39\n' '1\t2\n' ) ) inserted = self.client.execute(query) self.assertEqual(inserted, [ (3.4028234663852886e+38, 3.4028235e38), (float('inf'), 3.4028235e39), (-float('inf'), 3.4028235e39), (1, 2) ]) def test_nullable(self): with self.create_table('a Nullable(Float32)'): data = [(None, ), (0.5, ), (None, ), (1.5, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\n0.5\n\\N\n1.5\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nan(self): with self.create_table('a Float32'): data = [(float('nan'), ), (0.5, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'nan\n0.5\n') inserted = self.client.execute(query) self.assertEqual(len(inserted), 2) self.assertTrue(math.isnan(inserted[0][0])) self.assertEqual(inserted[1][0], 0.5) python-clickhouse-driver-0.2.3/tests/columns/test_int.py000066400000000000000000000206571420676740400235260ustar00rootroot00000000000000from tests.testcase import BaseTestCase from clickhouse_driver import errors from tests.util import require_server_version class IntTestCase(BaseTestCase): def test_chop_to_type(self): with self.create_table('a UInt8'): data = [(300, )] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '44\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(44, )]) with self.create_table('a Int8'): data = [(-300,)] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '-44\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(-44, )]) def test_raise_struct_error(self): with self.create_table('a UInt8'): with self.assertRaises(errors.TypeMismatchError) as e: data = [(300, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) exc = str(e.exception) self.assertIn('Column a', exc) self.assertIn('types_check=True', exc) def test_uint_type_mismatch(self): data = [(-1, )] with self.create_table('a UInt8'): with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('-1 for column "a"', str(e.exception)) with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data ) self.assertIn('Column a', str(e.exception)) def test_all_sizes(self): columns = ( 'a Int8, b Int16, c Int32, d Int64, ' 'e UInt8, f UInt16, g UInt32, h UInt64' ) data = [ (-10, -300, -123581321, -123581321345589144, 10, 300, 123581321, 123581321345589144) ] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a, b, c, d, e, f, g, h) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( '-10\t-300\t-123581321\t-123581321345589144\t' '10\t300\t123581321\t123581321345589144\n' ) ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_corner_cases(self): columns = ( 'a Int8, b Int16, c Int32, d Int64, ' 'e UInt8, f UInt16, g UInt32, h UInt64' ) data = [ (-128, -32768, -2147483648, -9223372036854775808, 255, 65535, 4294967295, 18446744073709551615), (127, 32767, 2147483647, 9223372036854775807, 0, 0, 0, 0), ] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a, b, c, d, e, f, g, h) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( '-128\t-32768\t-2147483648\t-9223372036854775808\t' '255\t65535\t4294967295\t18446744073709551615\n' '127\t32767\t2147483647\t9223372036854775807\t0\t0\t0\t0\n' ) ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable(self): with self.create_table('a Nullable(Int32)'): data = [(2, ), (None, ), (4, ), (None, ), (8, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2\n\\N\n4\n\\N\n8\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) class BigIntTestCase(BaseTestCase): required_server_version = (20, 8, 2) def cli_client_kwargs(self): return {'allow_experimental_bigint_types': 1} def test_int128(self): with self.create_table('a Int128'): data = [ (-170141183460469231731687303715884105728, ), (-111111111111111111111111111111111111111, ), (123, ), (111111111111111111111111111111111111111, ), (170141183460469231731687303715884105727, ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '-170141183460469231731687303715884105728\n' '-111111111111111111111111111111111111111\n' '123\n' '111111111111111111111111111111111111111\n' '170141183460469231731687303715884105727\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) @require_server_version(21, 6) def test_uint128(self): with self.create_table('a UInt128'): data = [ (0, ), (123, ), (340282366920938463463374607431768211455, ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '0\n' '123\n' '340282366920938463463374607431768211455\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_int256(self): with self.create_table('a Int256'): data = [ (-57896044618658097711785492504343953926634992332820282019728792003956564819968, ), # noqa: E501 (-11111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501 (123, ), (11111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501 (57896044618658097711785492504343953926634992332820282019728792003956564819967, ) # noqa: E501 ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '-57896044618658097711785492504343953926634992332820282019728792003956564819968\n' # noqa: E501 '-11111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501 '123\n' '11111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501 '57896044618658097711785492504343953926634992332820282019728792003956564819967\n' # noqa: E501 ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_uint256(self): with self.create_table('a UInt256'): data = [ (0, ), (123, ), (111111111111111111111111111111111111111111111111111111111111111111111111111111, ), # noqa: E501 (115792089237316195423570985008687907853269984665640564039457584007913129639935, ) # noqa: E501 ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '0\n' '123\n' '111111111111111111111111111111111111111111111111111111111111111111111111111111\n' # noqa: E501 '115792089237316195423570985008687907853269984665640564039457584007913129639935\n' # noqa: E501 ) inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_interval.py000066400000000000000000000013371420676740400245520ustar00rootroot00000000000000from tests.testcase import BaseTestCase class IntervalTestCase(BaseTestCase): required_server_version = (1, 1, 54310) def test_all(self): interval = [ ('YEAR', 1), ('MONTH', 2), ('WEEK', 3), ('DAY', 4), ('HOUR', 5), ('MINUTE', 6), ('SECOND', 7) ] columns = ', '.join(['INTERVAL {} {}'.format(v, k) for k, v in interval]) query = 'SELECT {}'.format(columns) cli_result = self.emit_cli(query) self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n') client_result = self.client.execute(query) self.assertEqual(client_result, [(1, 2, 3, 4, 5, 6, 7)]) python-clickhouse-driver-0.2.3/tests/columns/test_ip.py000066400000000000000000000165061420676740400233420ustar00rootroot00000000000000from __future__ import unicode_literals from clickhouse_driver import errors from ipaddress import IPv6Address, IPv4Address from tests.testcase import BaseTestCase class IPv4TestCase(BaseTestCase): required_server_version = (19, 3, 3) def test_simple(self): with self.create_table('a IPv4'): data = [ (IPv4Address("10.0.0.1"),), (IPv4Address("192.168.253.42"),) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '10.0.0.1\n' '192.168.253.42\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv4Address("10.0.0.1"),), (IPv4Address("192.168.253.42"),) ]) def test_from_int(self): with self.create_table('a IPv4'): data = [ (167772161,), ] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '10.0.0.1\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv4Address("10.0.0.1"),), ]) def test_from_str(self): with self.create_table('a IPv4'): data = [ ("10.0.0.1",), ] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '10.0.0.1\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv4Address("10.0.0.1"),), ]) def test_type_mismatch(self): data = [(1025.2147,)] with self.create_table('a IPv4'): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) def test_bad_ipv4(self): data = [('985.512.12.0',)] with self.create_table('a IPv4'): with self.assertRaises(errors.CannotParseDomainError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_bad_ipv4_with_type_check(self): data = [('985.512.12.0',)] with self.create_table('a IPv4'): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) def test_nullable(self): with self.create_table('a Nullable(IPv4)'): data = [(IPv4Address('10.10.10.10'),), (None,)] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '10.10.10.10\n\\N\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) class IPv6TestCase(BaseTestCase): required_server_version = (19, 3, 3) def test_simple(self): with self.create_table('a IPv6'): data = [ (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), (IPv6Address('a22:cc64:cf47:1653:4976:3c0c:ff8d:417c'),), (IPv6Address('12ff:0000:0000:0000:0000:0000:0000:0001'),) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '79f4:e698:45de:a59b:2765:28e3:8d3a:35ae\n' 'a22:cc64:cf47:1653:4976:3c0c:ff8d:417c\n' '12ff::1\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), (IPv6Address('a22:cc64:cf47:1653:4976:3c0c:ff8d:417c'),), (IPv6Address('12ff::1'),) ]) def test_from_str(self): with self.create_table('a IPv6'): data = [ ('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae',), ] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '79f4:e698:45de:a59b:2765:28e3:8d3a:35ae\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), ]) def test_from_bytes(self): with self.create_table('a IPv6'): data = [ (b"y\xf4\xe6\x98E\xde\xa5\x9b'e(\xe3\x8d:5\xae",), ] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( '79f4:e698:45de:a59b:2765:28e3:8d3a:35ae\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), ]) def test_type_mismatch(self): data = [(1025.2147,)] with self.create_table('a IPv6'): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) def test_bad_ipv6(self): data = [("ghjk:e698:45de:a59b:2765:28e3:8d3a:zzzz",)] with self.create_table('a IPv6'): with self.assertRaises(errors.CannotParseDomainError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_bad_ipv6_with_type_check(self): data = [("ghjk:e698:45de:a59b:2765:28e3:8d3a:zzzz",)] with self.create_table('a IPv6'): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) def test_nullable(self): with self.create_table('a Nullable(IPv6)'): data = [ (IPv6Address('79f4:e698:45de:a59b:2765:28e3:8d3a:35ae'),), (None,)] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '79f4:e698:45de:a59b:2765:28e3:8d3a:35ae\n\\N\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_low_cardinality.py000066400000000000000000000133311420676740400261070ustar00rootroot00000000000000from datetime import date, timedelta from decimal import Decimal from tests.testcase import BaseTestCase class LowCardinalityTestCase(BaseTestCase): required_server_version = (19, 3, 3) stable_support_version = (19, 9, 2) def cli_client_kwargs(self): if self.server_version >= self.stable_support_version: return {'allow_suspicious_low_cardinality_types': 1} def test_uint8(self): with self.create_table('a LowCardinality(UInt8)'): data = [(x, ) for x in range(255)] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x[0]) for x in data) + '\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_int8(self): with self.create_table('a LowCardinality(Int8)'): data = [(x - 127, ) for x in range(255)] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x[0]) for x in data) + '\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable_int8(self): with self.create_table('a LowCardinality(Nullable(Int8))'): data = [(None, ), (-1, ), (0, ), (1, ), (None, )] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\n-1\n0\n1\n\\N\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_date(self): with self.create_table('a LowCardinality(Date)'): start = date(1970, 1, 1) data = [(start + timedelta(x), ) for x in range(300)] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_float(self): with self.create_table('a LowCardinality(Float)'): data = [(float(x),) for x in range(300)] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_decimal(self): with self.create_table('a LowCardinality(Float)'): data = [(Decimal(x),) for x in range(300)] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_array(self): with self.create_table('a Array(LowCardinality(Int16))'): data = [([100, 500], )] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '[100,500]\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_empty_array(self): with self.create_table('a Array(LowCardinality(Int16))'): data = [([], )] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '[]\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_string(self): with self.create_table('a LowCardinality(String)'): data = [ ('test', ), ('low', ), ('cardinality', ), ('test', ), ('test', ), ('', ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\nlow\ncardinality\ntest\ntest\n\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_fixed_string(self): with self.create_table('a LowCardinality(FixedString(12))'): data = [ ('test', ), ('low', ), ('cardinality', ), ('test', ), ('test', ), ('', ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' 'low\\0\\0\\0\\0\\0\\0\\0\\0\\0\n' 'cardinality\\0\n' 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable_string(self): with self.create_table('a LowCardinality(Nullable(String))'): data = [ ('test', ), ('', ), (None, ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\n\n\\N\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_map.py000066400000000000000000000070131420676740400235000ustar00rootroot00000000000000from tests.testcase import BaseTestCase class MapTestCase(BaseTestCase): required_server_version = (21, 1, 2) # TODO: detect stable version stable_support_version = (22, 14, 9) def client_kwargs(self, version): if version < self.stable_support_version: return {'settings': {'allow_experimental_map_type': True}} def cli_client_kwargs(self): if self.stable_support_version > self.server_version: return {'allow_experimental_map_type': 1} def _sorted_dicts(self, text): items = [ ('{' + ','.join(sorted(x.strip('{}\n').split(','))) + '}') for x in text.strip('\n').split('\n') ] return '\n'.join(items) + '\n' def test_simple(self): with self.create_table('a Map(String, UInt64)'): data = [ ({},), ({'key1': 1}, ), ({'key1': 2, 'key2': 20}, ), ({'key1': 3, 'key2': 30, 'key3': 50}, ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( self._sorted_dicts(inserted), "{}\n" "{'key1':1}\n" "{'key1':2,'key2':20}\n" "{'key1':3,'key2':30,'key3':50}\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) # def test_nullable(self): # with self.create_table('a Map(Nullable(String), Nullable(UInt64))'): # data = [ # ({},), # ({None: None},), # ({'key1': 1}, ) # ] # self.client.execute('INSERT INTO test (a) VALUES', data) # query = 'SELECT * FROM test' # inserted = self.emit_cli(query) # self.assertEqual( # inserted, # "{}\n" # "{NULL:NULL}\n" # "{'key1':1}\n" # ) # inserted = self.client.execute(query) # self.assertEqual(inserted, data) # # def test_low_cardinality(self): # columns = 'a Map(LowCardinality(String), LowCardinality(UInt64))' # with self.create_table(columns): # data = [ # ({'key1': 1}, ), # ({'key1': 1}, ), # ({'key1': 1}, ) # ] # self.client.execute('INSERT INTO test (a) VALUES', data) # query = 'SELECT * FROM test' # inserted = self.emit_cli(query) # self.assertEqual( # inserted, # "{'key1':1}\n" # "{'key1':1}\n" # "{'key1':1}\n" # ) # inserted = self.client.execute(query) # self.assertEqual(inserted, data) def test_array(self): columns = 'a Map(String, Array(UInt64))' with self.create_table(columns): data = [ ({'key1': []}, ), ({'key2': [1, 2, 3]}, ), ({'key3': [1, 1, 1, 1]}, ) ] self.client.execute('INSERT INTO test (a) VALUES', data) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "{'key1':[]}\n" "{'key2':[1,2,3]}\n" "{'key3':[1,1,1,1]}\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/columns/test_nested.py000066400000000000000000000067261420676740400242170ustar00rootroot00000000000000from tests.testcase import BaseTestCase from tests.util import require_server_version from clickhouse_driver.columns import nestedcolumn class NestedTestCase(BaseTestCase): def entuple(self, lst): return tuple( self.entuple(x) if isinstance(x, list) else x for x in lst ) @require_server_version(21, 3, 13) def test_simple(self): columns = 'n Nested(i Int32, s String)' # INSERT INTO test_nested VALUES ([(0, 'a'), (1, 'b')]); data = [([(0, 'a'), (1, 'b')],)] with self.create_table(columns, flatten_nested=0): self.client.execute( 'INSERT INTO test (n) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, "[(0,'a'),(1,'b')]\n") inserted = self.client.execute(query) self.assertEqual(inserted, data) projected_i = self.client.execute('SELECT n.i FROM test') self.assertEqual( projected_i, [([0, 1],)] ) projected_s = self.client.execute('SELECT n.s FROM test') self.assertEqual( projected_s, [(['a', 'b'],)] ) @require_server_version(21, 3, 13) def test_multiple_rows(self): columns = 'n Nested(i Int32, s String)' data = [([(0, 'a'), (1, 'b')],), ([(3, 'd'), (4, 'e')],)] with self.create_table(columns, flatten_nested=0): self.client.execute( 'INSERT INTO test (n) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "[(0,'a'),(1,'b')]\n[(3,'d'),(4,'e')]\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) @require_server_version(21, 3, 13) def test_dict(self): columns = 'n Nested(i Int32, s String)' data = [ {'n': [{'i': 0, 's': 'a'}, {'i': 1, 's': 'b'}]}, {'n': [{'i': 3, 's': 'd'}, {'i': 4, 's': 'e'}]}, ] with self.create_table(columns, flatten_nested=0): self.client.execute( 'INSERT INTO test (n) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "[(0,'a'),(1,'b')]\n[(3,'d'),(4,'e')]\n" ) inserted = self.client.execute(query) self.assertEqual( inserted, [([(0, 'a'), (1, 'b')],), ([(3, 'd'), (4, 'e')],)] ) def test_get_nested_columns(self): self.assertEqual( nestedcolumn.get_nested_columns( 'Nested(a Tuple(Array(Int8)),\n b Nullable(String))', ), ['Tuple(Array(Int8))', 'Nullable(String)'] ) def test_get_columns_with_types(self): self.assertEqual( nestedcolumn.get_columns_with_types( 'Nested(a Tuple(Array(Int8)),\n b Nullable(String))', ), [('a', 'Tuple(Array(Int8))'), ('b', 'Nullable(String)')] ) def test_get_inner_spec(self): inner = 'a Tuple(Array(Int8), Array(Int64)), b Nullable(String)' self.assertEqual( nestedcolumn.get_inner_spec('Nested({}) dummy '.format(inner)), inner ) python-clickhouse-driver-0.2.3/tests/columns/test_null.py000066400000000000000000000003051420676740400236720ustar00rootroot00000000000000from tests.testcase import BaseTestCase class NullTestCase(BaseTestCase): def test_select_null(self): rv = self.client.execute('SELECT NULL') self.assertEqual(rv, [(None, )]) python-clickhouse-driver-0.2.3/tests/columns/test_nullable.py000066400000000000000000000025611420676740400245240ustar00rootroot00000000000000from tests.testcase import BaseTestCase from clickhouse_driver import errors ErrorCodes = errors.ErrorCodes class NullableTestCase(BaseTestCase): def test_simple(self): columns = 'a Nullable(Int32)' data = [(3, ), (None, ), (2, )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '3\n\\N\n2\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable_inside_nullable(self): columns = 'a Nullable(Nullable(Int32))' with self.assertRaises(errors.ServerException) as e: self.client.execute( 'CREATE TABLE test ({}) ''ENGINE = Memory'.format(columns) ) self.assertEqual(e.exception.code, ErrorCodes.ILLEGAL_TYPE_OF_ARGUMENT) def test_nullable_array(self): columns = 'a Nullable(Array(Nullable(Array(Nullable(Int32)))))' with self.assertRaises(errors.ServerException) as e: self.client.execute( 'CREATE TABLE test ({}) ''ENGINE = Memory'.format(columns) ) self.assertEqual(e.exception.code, ErrorCodes.ILLEGAL_TYPE_OF_ARGUMENT) python-clickhouse-driver-0.2.3/tests/columns/test_simpleaggregatefunction.py000066400000000000000000000061751420676740400276410ustar00rootroot00000000000000from enum import IntEnum from tests.testcase import BaseTestCase class SimpleAggregateFunctionTestCase(BaseTestCase): required_server_version = (19, 8, 3) def test_simple(self): columns = 'a SimpleAggregateFunction(any, Int32)' data = [(3, ), (2, )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '3\n2\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable(self): columns = 'a SimpleAggregateFunction(any, Nullable(Int32))' data = [(3, ), (None, ), (2, )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '3\n\\N\n2\n' ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_simple_agg_function(self): class A(IntEnum): hello = -1 world = 2 columns = "a SimpleAggregateFunction(anyLast, " \ "Enum8('hello' = -1, 'world' = 2))" data = [(A.hello,), (A.world,), (-1,), (2,)] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'hello\n' 'world\n' 'hello\n' 'world\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ ('hello',), ('world',), ('hello',), ('world',) ] ) def test_simple_agg_function_nullable(self): class A(IntEnum): hello = -1 world = 2 columns = "a SimpleAggregateFunction(anyLast, " \ "Nullable(Enum8('hello' = -1, 'world' = 2)))" data = [(A.hello,), (A.world,), (None,), (-1,), (2,)] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, ( 'hello\n' 'world\n' '\\N\n' 'hello\n' 'world\n' ) ) inserted = self.client.execute(query) self.assertEqual( inserted, [ ('hello',), ('world',), (None, ), ('hello',), ('world',) ] ) python-clickhouse-driver-0.2.3/tests/columns/test_string.py000066400000000000000000000142331420676740400242330ustar00rootroot00000000000000# coding=utf-8 from __future__ import unicode_literals from tests.testcase import BaseTestCase from clickhouse_driver import errors class StringTestCase(BaseTestCase): def test_unicode(self): data = [('яндекс', )] with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'яндекс\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_non_utf(self): data = [('яндекс'.encode('koi8-r'), )] with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='koi8-r') self.assertEqual(inserted, 'яндекс\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_null_byte_in_the_middle(self): data = [('a\x00b', )] with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'a\\0b\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable(self): with self.create_table('a Nullable(String)'): data = [(None, ), ('test', ), (None, ), ('nullable', )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_buffer_reader(self): data = [('a' * 300, )] * 300 with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_compressed_client(self): with self.created_client(compression=True) as client: data = [('a' * 300, )] with self.create_table('a String'): client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = client.execute(query) self.assertEqual(inserted, data) def test_custom_encoding(self): settings = {'strings_encoding': 'cp1251'} data = [(('яндекс'), ), (('test'), )] with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data, settings=settings ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='cp1251') self.assertEqual(inserted, 'яндекс\ntest\n') inserted = self.client.execute(query, settings=settings) self.assertEqual(inserted, data) self.assertIsInstance(inserted[0][0], str) self.assertIsInstance(inserted[1][0], str) def test_not_supported_types(self): datas = [ [(bytearray(b'asd'), )], [(123, )] ] with self.create_table('a String'): for data in datas: with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('for column "a"', str(e.exception)) with self.assertRaises(AttributeError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) class ByteStringTestCase(BaseTestCase): client_kwargs = {'settings': {'strings_as_bytes': True}} def test_not_decoded(self): data = [ (bytes('яндекс'.encode('cp1251')), ), (bytes('test'.encode('cp1251')), ), ] with self.create_table('a String'): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query, encoding='cp1251') self.assertEqual(inserted, 'яндекс\ntest\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) self.assertIsInstance(inserted[0][0], bytes) self.assertIsInstance(inserted[1][0], bytes) def test_nullable(self): with self.create_table('a Nullable(String)'): data = [(None, ), (b'test', ), (None, ), (b'nullable', )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_not_supported_types(self): datas = [ [('asd', )], [(bytearray(b'asd'), )], [(123, )] ] with self.create_table('a String'): for data in datas: with self.assertRaises(errors.TypeMismatchError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('for column "a"', str(e.exception)) with self.assertRaises(ValueError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data ) self.assertIn('bytes object expected', str(e.exception)) python-clickhouse-driver-0.2.3/tests/columns/test_tuple.py000066400000000000000000000126211420676740400240550ustar00rootroot00000000000000from datetime import date from clickhouse_driver import errors from tests.testcase import BaseTestCase from tests.util import require_server_version class TupleTestCase(BaseTestCase): def entuple(self, lst): return tuple( self.entuple(x) if isinstance(x, list) else x for x in lst ) def test_simple(self): columns = 'a Tuple(Int32, String)' data = [((1, 'a'), ), ((2, 'b'), )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, "(1,'a')\n(2,'b')\n") inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_tuple_single_element(self): columns = 'a Tuple(Int32)' data = [((1, ), ), ((2, ), )] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, "(1)\n(2)\n") inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nullable(self): with self.create_table('a Tuple(Nullable(Int32), Nullable(String))'): data = [ ((1, 'a'), ), ((2, None), ), ((None, None), ), ((None, 'd'), ), ((5, 'e'), ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "(1,'a')\n" "(2,NULL)\n(NULL,NULL)\n(NULL,'d')\n" "(5,'e')\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_nested_tuple_with_common_types(self): columns = 'a Tuple(String, Tuple(Int32, String), String)' with self.create_table(columns): data = [ (('one', (1, 'a'), 'two'), ), (('three', (2, 'b'), 'four'), ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "('one',(1,'a'),'two')\n" "('three',(2,'b'),'four')\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_tuple_of_tuples(self): columns = ( "a Tuple(" "Tuple(Int32, String)," "Tuple(Enum8('hello' = 1, 'world' = 2), Date)" ")" ) with self.create_table(columns): data = [ (((1, 'a'), (1, date(2020, 3, 11))), ), (((2, 'b'), (2, date(2020, 3, 12))), ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "((1,'a'),('hello','2020-03-11'))\n" "((2,'b'),('world','2020-03-12'))\n" ) inserted = self.client.execute(query) self.assertEqual( inserted, [ (((1, 'a'), ('hello', date(2020, 3, 11))), ), (((2, 'b'), ('world', date(2020, 3, 12))), ) ] ) def test_tuple_of_arrays(self): with self.create_table('a Tuple(Array(Int32))'): data = [(([1, 2, 3], ), ), (([4, 5, 6], ), )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "([1,2,3])\n([4,5,6])\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) # Bug in Array of Tuple handing before 19.16.13: # DESCRIBE TABLE test # # | a.1 | Array(UInt8) | # | a.2 | Array(UInt8) | # | a.3 | Array(UInt8) | # https://github.com/ClickHouse/ClickHouse/pull/8866 @require_server_version(19, 16, 13) def test_array_of_tuples(self): with self.create_table('a Array(Tuple(UInt8, UInt8, UInt8))'): data = [ ([(1, 2, 3), (4, 5, 6)], ), ([(7, 8, 9)],), ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, "[(1,2,3),(4,5,6)]\n" "[(7,8,9)]\n" ) inserted = self.client.execute(query) self.assertEqual(inserted, data) def test_type_mismatch_error(self): columns = 'a Tuple(Int32)' data = [('test', )] with self.create_table(columns): with self.assertRaises(errors.TypeMismatchError): self.client.execute('INSERT INTO test (a) VALUES', data) python-clickhouse-driver-0.2.3/tests/columns/test_unknown.py000066400000000000000000000006031420676740400244200ustar00rootroot00000000000000 from unittest import TestCase from clickhouse_driver import errors from clickhouse_driver.columns.service import get_column_by_spec class UnknownColumnTestCase(TestCase): def test_get_unknown_column(self): with self.assertRaises(errors.UnknownTypeError) as e: get_column_by_spec('Unicorn', {'context': {}}) self.assertIn('Unicorn', str(e.exception)) python-clickhouse-driver-0.2.3/tests/columns/test_uuid.py000066400000000000000000000043461420676740400236770ustar00rootroot00000000000000from uuid import UUID from tests.testcase import BaseTestCase from clickhouse_driver import errors class UUIDTestCase(BaseTestCase): def test_simple(self): with self.create_table('a UUID'): data = [ (UUID('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'), ), ('2efcead4-ff55-4db5-bdb4-6b36a308d8e0', ) ] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, ( 'c0fcbba9-0752-44ed-a5d6-4dfb4342b89d\n' '2efcead4-ff55-4db5-bdb4-6b36a308d8e0\n' )) inserted = self.client.execute(query) self.assertEqual(inserted, [ (UUID('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'), ), (UUID('2efcead4-ff55-4db5-bdb4-6b36a308d8e0'), ) ]) def test_type_mismatch(self): data = [(62457709573696417404743346296141175008, )] with self.create_table('a UUID'): with self.assertRaises(errors.TypeMismatchError): self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) with self.assertRaises(AttributeError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_bad_uuid(self): data = [('a', )] with self.create_table('a UUID'): with self.assertRaises(errors.CannotParseUuidError): self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_nullable(self): with self.create_table('a Nullable(UUID)'): data = [(UUID('2efcead4-ff55-4db5-bdb4-6b36a308d8e0'), ), (None, )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2efcead4-ff55-4db5-bdb4-6b36a308d8e0\n\\N\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/conftest.py000066400000000000000000000002701420676740400220270ustar00rootroot00000000000000import pytest @pytest.fixture(autouse=True) def assert_empty_output(capfd): yield captured = capfd.readouterr() assert captured.out == '' assert captured.err == '' python-clickhouse-driver-0.2.3/tests/docker-compose.yml000066400000000000000000000006211420676740400232650ustar00rootroot00000000000000version: '3' services: clickhouse-server: image: "yandex/clickhouse-server:$VERSION" container_name: test-clickhouse-server environment: - TZ=Europe/Moscow ports: - "127.0.0.1:9000:9000" clickhouse-client: image: "yandex/clickhouse-client:$VERSION" container_name: test-clickhouse-client entrypoint: /bin/sh command: [-c, 'while :; do sleep 1; done'] python-clickhouse-driver-0.2.3/tests/log.py000066400000000000000000000012401420676740400207610ustar00rootroot00000000000000from logging.config import dictConfig def configure(level): dictConfig({ 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'standard': { 'format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s' }, }, 'handlers': { 'default': { 'level': level, 'formatter': 'standard', 'class': 'logging.StreamHandler', }, }, 'loggers': { '': { 'handlers': ['default'], 'level': level, 'propagate': True }, } }) python-clickhouse-driver-0.2.3/tests/numpy/000077500000000000000000000000001420676740400210015ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/numpy/__init__.py000066400000000000000000000000001420676740400231000ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/numpy/columns/000077500000000000000000000000001420676740400224615ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/numpy/columns/__init__.py000066400000000000000000000000001420676740400245600ustar00rootroot00000000000000python-clickhouse-driver-0.2.3/tests/numpy/columns/test_datetime.py000066400000000000000000000476541420676740400257060ustar00rootroot00000000000000from datetime import datetime, date from unittest.mock import patch try: import numpy as np except ImportError: np = None try: import pandas as pd except ImportError: pd = None from pytz import timezone, utc, UnknownTimeZoneError import tzlocal from tests.numpy.testcase import NumpyBaseTestCase from tests.util import require_server_version, patch_env_tz class BaseDateTimeTestCase(NumpyBaseTestCase): def make_numpy_d64ns(self, items): return np.array(items, dtype='datetime64[ns]') class DateTimeTestCase(BaseDateTimeTestCase): def test_datetime_type(self): query = 'SELECT now()' rv = self.client.execute(query, columnar=True) self.assertIsInstance(rv[0][0], np.datetime64) @require_server_version(20, 1, 2) def test_datetime64_type(self): query = 'SELECT now64()' rv = self.client.execute(query, columnar=True) self.assertIsInstance(rv[0][0], np.datetime64) def test_simple(self): with self.create_table('a Date, b DateTime'): data = [ np.array(['2012-10-25'], dtype='datetime64[D]'), np.array(['2012-10-25T14:07:19'], dtype='datetime64[ns]') ] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25\t2012-10-25 14:07:19\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], np.array(['2012-10-25'], dtype='datetime64[D]') ) self.assertArraysEqual( inserted[1], self.make_numpy_d64ns(['2012-10-25T14:07:19']) ) def test_nullable_date(self): with self.create_table('a Nullable(Date)'): data = [ np.array([None, date(2012, 10, 25), None, date(2017, 6, 23)], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\n2012-10-25\n\\N\n2017-06-23\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], data[0]) self.assertEqual(inserted[0].dtype, object) def test_nullable_datetime(self): with self.create_table('a Nullable(DateTime)'): data = [ np.array([ None, datetime(2012, 10, 25, 14, 7, 19), None, datetime(2017, 6, 23, 19, 10, 15) ], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\n2012-10-25 14:07:19\n\\N\n2017-06-23 19:10:15\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], data[0]) self.assertEqual(inserted[0].dtype, object) def test_handle_errors_from_tzlocal(self): with patch('tzlocal.get_localzone') as mocked: mocked.side_effect = UnknownTimeZoneError() self.client.execute('SELECT now()') if hasattr(tzlocal, 'get_localzone_name'): with patch('tzlocal.get_localzone_name') as mocked: mocked.side_effect = None self.client.execute('SELECT now()') @require_server_version(20, 1, 2) def test_datetime64_frac_trunc(self): with self.create_table('a DateTime64'): data = [self.make_numpy_d64ns(['2012-10-25T14:07:19.125600'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25 14:07:19.125\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns(['2012-10-25T14:07:19.125']) ) @require_server_version(20, 1, 2) def test_datetime64_explicit_frac(self): with self.create_table('a DateTime64(1)'): data = [self.make_numpy_d64ns(['2012-10-25T14:07:19.125600'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25 14:07:19.1\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns(['2012-10-25T14:07:19.1']) ) def test_insert_integers_datetime(self): with self.create_table('a DateTime'): self.client.execute( 'INSERT INTO test (a) VALUES', [np.array([1530211034], dtype=np.uint32)], columnar=True ) query = 'SELECT toUInt32(a), a FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1530211034\t2018-06-28 21:37:14\n') @require_server_version(20, 1, 2) def test_insert_integers_datetime64(self): with self.create_table('a DateTime64'): self.client.execute( 'INSERT INTO test (a) VALUES', [np.array([1530211034123], dtype=np.uint64)], columnar=True ) query = 'SELECT toUInt32(a), a FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1530211034\t2018-06-28 21:37:14.123\n') def test_insert_integer_bounds(self): with self.create_table('a DateTime'): self.client.execute( 'INSERT INTO test (a) VALUES', [np.array([0, 1, 1500000000, 2**32-1], dtype=np.uint32)], columnar=True ) query = 'SELECT toUInt32(a) FROM test ORDER BY a' inserted = self.emit_cli(query) self.assertEqual(inserted, '0\n1\n1500000000\n4294967295\n') class DateTimeTimezonesTestCase(BaseDateTimeTestCase): dt_type = 'DateTime' def make_tz_numpy_array(self, dt, tz_name): dtype = 'datetime64[ns]' return pd.to_datetime(np.array([dt] * 2, dtype=dtype)) \ .tz_localize(tz_name).to_numpy(dtype) # Asia/Kamchatka = UTC+12 # Asia/Novosibirsk = UTC+7 # Europe/Moscow = UTC+3 # 1500010800 second since epoch in Europe/Moscow. # 1500000000 second since epoch in UTC. dt = datetime(2017, 7, 14, 5, 40) dt_str = dt.isoformat() # properties for lazy evaluation for dealing with AttributeError when no # numpy/pandas installed @property def dt_arr(self): return np.array([self.dt_str], dtype='datetime64[s]') @property def dt_tz(self): return pd.to_datetime(self.dt_arr).tz_localize('Asia/Kamchatka') col_tz_name = 'Asia/Novosibirsk' col_tz = timezone(col_tz_name) # INSERTs and SELECTs must be the same as clickhouse-client's # if column has no timezone. def table_columns(self, with_tz=False): if not with_tz: return 'a {}'.format(self.dt_type) return "a {}('{}')".format(self.dt_type, self.col_tz_name) def test_use_server_timezone(self): # Insert datetime with timezone UTC # into column with no timezone # using server's timezone (Europe/Moscow) # Determine server timezone and calculate expected timestamp. server_tz_name = self.client.execute('SELECT timezone()')[0][0] offset = timezone(server_tz_name).utcoffset(self.dt).total_seconds() timestamp = 1500010800 - int(offset) with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_arr], columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')" ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '{ts}\n{ts}\n'.format(ts=timestamp)) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns([self.dt_str] * 2) ) def test_use_client_timezone(self): # Insert datetime with timezone UTC # into column with no timezone # using client's timezone Asia/Novosibirsk settings = {'use_client_time_zone': True} with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_arr], settings=settings, columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, columnar=True, settings=settings) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns([self.dt_str] * 2) ) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_use_server_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with no timezone # using server's timezone (Europe/Moscow) server_tz_name = self.client.execute('SELECT timezone()')[0][0] offset = timezone(server_tz_name).utcoffset(self.dt) with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_tz], columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) dt = (self.dt_tz.to_pydatetime()[0].astimezone(utc) + offset) \ .replace(tzinfo=None) self.assertEqual(inserted, '{dt}\n{dt}\n'.format(dt=dt)) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns([dt.isoformat()] * 2) ) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_use_client_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with no timezone # using client's timezone Asia/Novosibirsk settings = {'use_client_time_zone': True} with patch_env_tz('Asia/Novosibirsk'): with self.create_table(self.table_columns()): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_tz], settings=settings, columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query, columnar=True, settings=settings) dt = datetime(2017, 7, 14, 0, 40) self.assertArraysEqual( inserted[0], self.make_numpy_d64ns([dt.isoformat()] * 2) ) @require_server_version(1, 1, 54337) def test_column_use_server_timezone(self): # Insert datetime with no timezone # into column with timezone Asia/Novosibirsk # using server's timezone (Europe/Moscow) with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_arr], columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')" ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], self.make_tz_numpy_array(self.dt, self.col_tz_name) ) @require_server_version(1, 1, 54337) def test_column_use_client_timezone(self): # Insert datetime with no timezone # into column with timezone Asia/Novosibirsk # using client's timezone Europe/Moscow settings = {'use_client_time_zone': True} with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_arr], settings=settings, columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES ('2017-07-14 05:40:00')", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499985600 = 1500000000 - 4 * 3600 self.assertEqual(inserted, '1499985600\n1499985600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) self.assertEqual( inserted, '2017-07-14 05:40:00\n2017-07-14 05:40:00\n' ) inserted = self.client.execute(query, columnar=True, settings=settings) self.assertArraysEqual( inserted[0], self.make_tz_numpy_array(self.dt, self.col_tz_name) ) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_column_use_server_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with timezone Asia/Novosibirsk # using server's timezone (Europe/Moscow) with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_tz], columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query, columnar=True) dt = datetime(2017, 7, 14, 0, 40) self.assertArraysEqual( inserted[0], self.make_tz_numpy_array(dt, self.col_tz_name) ) @require_server_version(1, 1, 54337) def test_datetime_with_timezone_column_use_client_timezone(self): # Insert datetime with timezone Asia/Kamchatka # into column with timezone Asia/Novosibirsk # using client's timezone (Europe/Moscow) settings = {'use_client_time_zone': True} with patch_env_tz('Europe/Moscow'): with self.create_table(self.table_columns(with_tz=True)): self.client.execute( 'INSERT INTO test (a) VALUES', [self.dt_tz], settings=settings, columnar=True ) self.emit_cli( "INSERT INTO test (a) VALUES " "(toDateTime('2017-07-14 05:40:00', 'Asia/Kamchatka'))", use_client_time_zone=1 ) query = 'SELECT toInt32(a) FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 1499967600 = 1500000000 - 12 * 3600 self.assertEqual(inserted, '1499967600\n1499967600\n') query = 'SELECT * FROM test' inserted = self.emit_cli(query, use_client_time_zone=1) # 2017-07-14 00:40:00 = 2017-07-14 05:40:00 - 05:00:00 # (Kamchatka - Novosibirsk) self.assertEqual( inserted, '2017-07-14 00:40:00\n2017-07-14 00:40:00\n' ) inserted = self.client.execute(query, columnar=True, settings=settings) dt = datetime(2017, 7, 14, 0, 40) self.assertArraysEqual( inserted[0], self.make_tz_numpy_array(dt, self.col_tz_name) ) class DateTime64TimezonesTestCase(DateTimeTimezonesTestCase): dt_type = 'DateTime64' required_server_version = (20, 1, 2) def table_columns(self, with_tz=False): if not with_tz: return 'a {}(0)'.format(self.dt_type) return "a {}(0, '{}')".format(self.dt_type, self.col_tz_name) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_float.py000066400000000000000000000056331420676740400252060ustar00rootroot00000000000000from parameterized import parameterized try: import numpy as np except ImportError: np = None from tests.numpy.testcase import NumpyBaseTestCase class FloatTestCase(NumpyBaseTestCase): n = 10 def check_result(self, rv, col_type): self.assertArraysEqual(rv[0], np.array(range(self.n))) self.assertEqual(rv[0].dtype, col_type) def get_query(self, ch_type): with self.create_table('a {}'.format(ch_type)): data = [np.array(range(self.n))] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x) for x in data[0]) + '\n' ) return self.client.execute(query, columnar=True) def test_float32(self): rv = self.get_query('Float32') self.check_result(rv, np.float32) def test_float64(self): rv = self.get_query('Float64') self.check_result(rv, np.float64) def test_fractional_round_trip(self): with self.create_table('a Float32'): data = [np.array([0.5, 1.5], dtype=np.float32)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '0.5\n1.5\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], data[0]) @parameterized.expand(['Float32', 'Float64']) def test_nullable(self, float_type): with self.create_table('a Nullable({})'.format(float_type)): data = [np.array([np.nan, 0.5, None, 1.5], dtype=object)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'nan\n0.5\n\\N\n1.5\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0].astype(str), data[0].astype(str) ) self.assertEqual(inserted[0].dtype, object) def test_nan(self): with self.create_table('a Float32'): data = [np.array([float('nan'), 0.5], dtype=np.float32)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'nan\n0.5\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0].astype(str), data[0].astype(str) ) self.assertEqual(inserted[0].dtype, np.float32) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_int.py000066400000000000000000000055421420676740400246720ustar00rootroot00000000000000try: import numpy as np except ImportError: np = None from tests.numpy.testcase import NumpyBaseTestCase class IntTestCase(NumpyBaseTestCase): n = 10 def check_result(self, rv, col_type): self.assertArraysEqual(rv[0], np.array(range(self.n))) self.assertEqual(rv[0].dtype, col_type) def get_query(self, ch_type): with self.create_table('a {}'.format(ch_type)): data = [np.array(range(self.n))] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x) for x in data[0]) + '\n' ) return self.client.execute(query, columnar=True) def test_int8(self): rv = self.get_query('Int8') self.check_result(rv, np.int8) def test_int16(self): rv = self.get_query('Int16') self.check_result(rv, np.int16) def test_int32(self): rv = self.get_query('Int32') self.check_result(rv, np.int32) def test_int64(self): rv = self.get_query('Int64') self.check_result(rv, np.int64) def test_uint8(self): rv = self.get_query('UInt8') self.check_result(rv, np.uint8) def test_uint16(self): rv = self.get_query('UInt16') self.check_result(rv, np.uint16) def test_uint32(self): rv = self.get_query('UInt32') self.check_result(rv, np.uint32) def test_uint64(self): rv = self.get_query('UInt64') self.check_result(rv, np.uint64) def test_insert_nan_into_non_nullable(self): with self.create_table('a Int32'): data = [ np.array([123, np.nan], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '123\n0\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], np.array([123, 0])) self.assertEqual(inserted[0].dtype, np.int32) def test_nullable(self): with self.create_table('a Nullable(Int32)'): data = [np.array([2, None, 4, None, 8])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2\n\\N\n4\n\\N\n8\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], data[0]) self.assertEqual(inserted[0].dtype, object) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_low_cardinality.py000066400000000000000000000166531420676740400272710ustar00rootroot00000000000000try: import numpy as np except ImportError: np = None try: import pandas as pd except ImportError: pd = None from tests.numpy.testcase import NumpyBaseTestCase # from decimal import Decimal class LowCardinalityTestCase(NumpyBaseTestCase): required_server_version = (19, 3, 3) stable_support_version = (19, 9, 2) def cli_client_kwargs(self): if self.server_version >= self.stable_support_version: return {'allow_suspicious_low_cardinality_types': 1} def check_result(self, inserted, data): self.assertArraysEqual(inserted[0], data[0]) self.assertIsInstance(inserted[0], pd.Categorical) def test_uint8(self): with self.create_table('a LowCardinality(UInt8)'): data = [np.array(range(255))] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x) for x in data[0]) + '\n' ) inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) def test_int8(self): with self.create_table('a LowCardinality(Int8)'): data = [np.array([x - 127 for x in range(255)])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\n'.join(str(x) for x in data[0]) + '\n' ) inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) def test_nullable_int8(self): with self.create_table('a LowCardinality(Nullable(Int8))'): data = [np.array([None, -1, 0, 1, None], dtype=object)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\n-1\n0\n1\n\\N\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0].astype(str), pd.Categorical(data[0]).astype(str) ) self.assertIsInstance(inserted[0], pd.Categorical) def test_date(self): with self.create_table('a LowCardinality(Date)'): data = [np.array(list(range(300)), dtype='datetime64[D]')] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) def test_float(self): with self.create_table('a LowCardinality(Float)'): data = [np.array([float(x) for x in range(300)])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) # def test_decimal(self): # with self.create_table('a LowCardinality(Float)'): # data = [(Decimal(x),) for x in range(300)] # self.client.execute('INSERT INTO test (a) VALUES', data[0]) # # query = 'SELECT * FROM test' # inserted = self.client.execute(query) # self.assertEqual(inserted, data[0]) # # def test_array(self): # with self.create_table('a Array(LowCardinality(Int16))'): # data = [([100, 500], )] # self.client.execute('INSERT INTO test (a) VALUES', data[0]) # # query = 'SELECT * FROM test' # inserted = self.emit_cli(query) # self.assertEqual(inserted, '[100,500]\n') # # inserted = self.client.execute(query) # self.assertEqual(inserted, data[0]) # # def test_empty_array(self): # with self.create_table('a Array(LowCardinality(Int16))'): # data = [([], )] # self.client.execute('INSERT INTO test (a) VALUES', data[0]) # # query = 'SELECT * FROM test' # inserted = self.emit_cli(query) # self.assertEqual(inserted, '[]\n') # # inserted = self.client.execute(query) # self.assertEqual(inserted, data[0]) # def test_string(self): with self.create_table('a LowCardinality(String)'): data = [ np.array(['test', 'low', 'cardinality', 'test', 'test', '']) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\nlow\ncardinality\ntest\ntest\n\n' ) inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) def test_insert_nan_string_into_non_nullable(self): with self.create_table('a LowCardinality(String)'): data = [ np.array(['test', None], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\n\n' ) inserted = self.client.execute(query, columnar=True) self.check_result(inserted, [np.array(['test', ''])]) def test_fixed_string(self): with self.create_table('a LowCardinality(FixedString(12))'): data = [ np.array(['test', 'low', 'cardinality', 'test', 'test', '']) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' 'low\\0\\0\\0\\0\\0\\0\\0\\0\\0\n' 'cardinality\\0\n' 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' 'test\\0\\0\\0\\0\\0\\0\\0\\0\n' '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n' ) inserted = self.client.execute(query, columnar=True) self.check_result(inserted, data) def test_nullable_string(self): with self.create_table('a LowCardinality(Nullable(String))'): data = [ np.array(['test', '', None], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, 'test\n\n\\N\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0].astype(str), pd.Categorical(data[0]).astype(str) ) self.assertIsInstance(inserted[0], pd.Categorical) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_nullable.py000066400000000000000000000035121420676740400256710ustar00rootroot00000000000000try: import numpy as np except ImportError: np = None try: import pandas as pd except ImportError: pd = None from tests.numpy.testcase import NumpyBaseTestCase from clickhouse_driver import errors ErrorCodes = errors.ErrorCodes class NullableTestCase(NumpyBaseTestCase): def test_simple(self): columns = 'a Nullable(Int32)' data = [np.array([3, None, 2], dtype=object)] with self.create_table(columns): self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '3\n\\N\n2\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual(inserted[0], data[0]) self.assertEqual(inserted[0].dtype, object) def test_simple_dataframe(self): columns = ( 'a Int64, ' 'b Nullable(Float64), ' 'c Nullable(String), ' 'd Nullable(Int64)' ) df = pd.DataFrame({ 'a': [1, 2, 3], 'b': [1.0, None, np.nan], 'c': ['a', None, np.nan], 'd': [1, None, None], }, dtype=object) expected = pd.DataFrame({ 'a': np.array([1, 2, 3], dtype=np.int64), 'b': np.array([1.0, None, np.nan], dtype=object), 'c': np.array(['a', None, None], dtype=object), 'd': np.array([1, None, None], dtype=object), }) with self.create_table(columns): rv = self.client.insert_dataframe('INSERT INTO test VALUES', df) self.assertEqual(rv, 3) df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a') self.assertTrue(expected.equals(df2)) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_other.py000066400000000000000000000020731420676740400252150ustar00rootroot00000000000000from parameterized import parameterized from clickhouse_driver import errors from clickhouse_driver.columns.service import get_column_by_spec from clickhouse_driver.context import Context from tests.numpy.testcase import NumpyBaseTestCase class OtherColumnsTestCase(NumpyBaseTestCase): def get_column(self, spec): ctx = Context() ctx.client_settings = {'strings_as_bytes': False, 'use_numpy': True} return get_column_by_spec(spec, {'context': ctx}) @parameterized.expand([ ("Enum8('hello' = 1, 'world' = 2)", ), ('Decimal(8, 4)', ), ('Array(String)', ), ('Tuple(String)', ), ('SimpleAggregateFunction(any, Int32)', ), ('Map(String, String)', ), ('Array(LowCardinality(String))', ) ]) def test_generic_type(self, spec): col = self.get_column(spec) self.assertIsNotNone(col) def test_get_unknown_column(self): with self.assertRaises(errors.UnknownTypeError) as e: self.get_column('Unicorn') self.assertIn('Unicorn', str(e.exception)) python-clickhouse-driver-0.2.3/tests/numpy/columns/test_string.py000066400000000000000000000134171420676740400254060ustar00rootroot00000000000000try: import numpy as np except ImportError: np = None from tests.numpy.testcase import NumpyBaseTestCase class StringTestCase(NumpyBaseTestCase): def test_string(self): with self.create_table('a String'): data = [np.array(['a', 'b', 'c'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'a\nb\nc\n') rv = self.client.execute(query, columnar=True) self.assertArraysEqual(rv[0], data) self.assertNotEqual(rv[0].dtype, object) self.assertIsInstance(rv[0][1], (np.str_, )) def test_nullable(self): with self.create_table('a Nullable(String)'): data = [np.array([np.nan, 'test', None, 'nullable'], dtype=object)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], [np.array([None, 'test', None, 'nullable'])] ) self.assertEqual(inserted[0].dtype, object) class ByteStringTestCase(NumpyBaseTestCase): client_kwargs = {'settings': {'strings_as_bytes': True, 'use_numpy': True}} def test_string(self): with self.create_table('a String'): data = [np.array([b'a', b'b', b'c'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'a\nb\nc\n') rv = self.client.execute(query, columnar=True) self.assertArraysEqual(rv[0], data) self.assertNotEqual(rv[0].dtype, object) self.assertIsInstance(rv[0][0], (np.bytes_, )) def test_nullable(self): with self.create_table('a Nullable(String)'): data = [ np.array([np.nan, b'test', None, b'nullable'], dtype=object) ] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '\\N\ntest\n\\N\nnullable\n') inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], [np.array([None, b'test', None, b'nullable'])] ) self.assertEqual(inserted[0].dtype, object) class FixedStringTestCase(NumpyBaseTestCase): def test_string(self): with self.create_table('a FixedString(3)'): data = [np.array(['a', 'b', 'c'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'a\\0\\0\nb\\0\\0\nc\\0\\0\n') rv = self.client.execute(query, columnar=True) self.assertArraysEqual(rv[0], data) self.assertNotEqual(rv[0].dtype, object) self.assertIsInstance(rv[0][0], (np.str_, )) def test_nullable(self): with self.create_table('a Nullable(FixedString(10))'): data = [np.array([np.nan, 'test', None, 'nullable'], dtype=object)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], [np.array([None, 'test', None, 'nullable'])] ) self.assertEqual(inserted[0].dtype, object) class ByteFixedStringTestCase(NumpyBaseTestCase): client_kwargs = {'settings': {'strings_as_bytes': True, 'use_numpy': True}} def test_string(self): with self.create_table('a FixedString(3)'): data = [np.array([b'a', b'b', b'c'])] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, 'a\\0\\0\nb\\0\\0\nc\\0\\0\n') rv = self.client.execute(query, columnar=True) self.assertArraysEqual(rv[0], data) self.assertNotEqual(rv[0].dtype, object) self.assertIsInstance(rv[0][0], (np.bytes_, )) def test_nullable(self): with self.create_table('a Nullable(FixedString(10))'): data = [np.array([ np.nan, b'test\x00\x00\x00\x00\x00\x00', None, b'nullable\x00\x00' ], dtype=object)] self.client.execute( 'INSERT INTO test (a) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual( inserted, '\\N\ntest\\0\\0\\0\\0\\0\\0\n\\N\nnullable\\0\\0\n' ) inserted = self.client.execute(query, columnar=True) self.assertArraysEqual( inserted[0], [np.array([None, b'test', None, b'nullable'])] ) self.assertEqual(inserted[0].dtype, object) python-clickhouse-driver-0.2.3/tests/numpy/test_external_tables.py000066400000000000000000000026561420676740400255770ustar00rootroot00000000000000try: import numpy as np import pandas as pd except ImportError: np = None pd = None from tests.numpy.testcase import NumpyBaseTestCase class ExternalTablesTestCase(NumpyBaseTestCase): def test_select(self): tables = [{ 'name': 'test', 'structure': [('x', 'Int32'), ('y', 'String')], 'data': pd.DataFrame({ 'x': [100, 500], 'y': ['abc', 'def'] }) }] rv = self.client.execute( 'SELECT * FROM test', external_tables=tables, columnar=True ) self.assertArraysListEqual( rv, [np.array([100, 500]), np.array(['abc', 'def'])] ) def test_send_empty_table(self): tables = [{ 'name': 'test', 'structure': [('x', 'Int32')], 'data': pd.DataFrame({'x': []}) }] rv = self.client.execute( 'SELECT * FROM test', external_tables=tables, columnar=True ) self.assertArraysListEqual(rv, []) def test_send_empty_table_structure(self): tables = [{ 'name': 'test', 'structure': [], 'data': pd.DataFrame() }] with self.assertRaises(ValueError) as e: self.client.execute( 'SELECT * FROM test', external_tables=tables, columnar=True ) self.assertIn('Empty table "test" structure', str(e.exception)) python-clickhouse-driver-0.2.3/tests/numpy/test_generic.py000066400000000000000000000124341420676740400240320ustar00rootroot00000000000000import types try: import numpy as np import pandas as pd except ImportError: np = None pd = None from tests.testcase import BaseTestCase from tests.numpy.testcase import NumpyBaseTestCase class GenericTestCase(NumpyBaseTestCase): n = 10 def test_columnar(self): rv = self.client.execute( 'SELECT number FROM numbers({})'.format(self.n), columnar=True ) self.assertEqual(len(rv), 1) self.assertIsInstance(rv[0], (np.ndarray, )) def test_rowwise(self): rv = self.client.execute( 'SELECT number FROM numbers({})'.format(self.n) ) self.assertEqual(len(rv), self.n) self.assertIsInstance(rv[0], (np.ndarray, )) def test_insert_not_supported(self): data = [np.array(range(self.n))] with self.create_table('a Int32'): with self.assertRaises(ValueError) as e: self.client.execute( 'INSERT INTO test (a) VALUES', data ) self.assertEqual( 'NumPy inserts is only allowed with columnar=True', str(e.exception) ) def test_with_column_types(self): rv = self.client.execute( 'SELECT CAST(2 AS Int32) AS x', with_column_types=True ) self.assertEqual(rv, ([(2, )], [('x', 'Int32')])) class NumpyProgressTestCase(NumpyBaseTestCase): def test_select_with_progress(self): progress = self.client.execute_with_progress('SELECT 2') self.assertEqual( list(progress), [(1, 0), (1, 0)] if self.server_version > (20,) else [(1, 0)] ) self.assertEqual(progress.get_result(), [(2,)]) self.assertTrue(self.client.connection.connected) def test_select_with_progress_no_progress_obtaining(self): progress = self.client.execute_with_progress('SELECT 2') self.assertEqual(progress.get_result(), [(2,)]) class NumpyIteratorTestCase(NumpyBaseTestCase): def test_select_with_iter(self): result = self.client.execute_iter( 'SELECT number FROM system.numbers LIMIT 10' ) self.assertIsInstance(result, types.GeneratorType) self.assertEqual(list(result), list(zip(range(10)))) self.assertEqual(list(result), []) def test_select_with_iter_with_column_types(self): result = self.client.execute_iter( 'SELECT CAST(number AS UInt32) as number ' 'FROM system.numbers LIMIT 10', with_column_types=True ) self.assertIsInstance(result, types.GeneratorType) self.assertEqual( list(result), [[('number', 'UInt32')]] + list(zip(range(10))) ) self.assertEqual(list(result), []) class DataFrameTestCase(NumpyBaseTestCase): def test_query_simple(self): df = self.client.query_dataframe( 'SELECT CAST(number AS Int64) AS x FROM system.numbers LIMIT 100' ) self.assertTrue(df.equals(pd.DataFrame({'x': range(100)}))) def test_query_replace_whitespace_in_column_names(self): df = self.client.query_dataframe( 'SELECT number AS "test me" FROM system.numbers LIMIT 100' ) self.assertIn('test_me', df) def test_insert_simple(self): n = 10 df = pd.DataFrame({ 'a': range(n), 'b': [float(x) for x in range(n)] }) with self.create_table('a Int64, b Float64'): rv = self.client.insert_dataframe('INSERT INTO test VALUES', df) self.assertEqual(rv, n) df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a') self.assertTrue(df.equals(df2)) def test_insert_chunking(self): with self.create_table('a Int64'): rv = self.client.execute( 'INSERT INTO test VALUES', [np.array(range(3))], columnar=True, settings={'insert_block_size': 1} ) self.assertEqual(rv, 3) def test_insert_not_ordered_columns(self): n = 10 df = pd.DataFrame({ 'b': range(n), 'a': [str(x) for x in range(n)] })[['b', 'a']] with self.create_table('a String, b Float64'): rv = self.client.insert_dataframe( 'INSERT INTO test (a, b) VALUES', df ) self.assertEqual(rv, n) class NoNumPyTestCase(BaseTestCase): def setUp(self): super(NoNumPyTestCase, self).setUp() try: import numpy # noqa: F401 import pandas # noqa: F401 except Exception: pass else: self.skipTest('NumPy extras are installed') def test_runtime_error_without_numpy(self): with self.assertRaises(RuntimeError) as e: with self.created_client(settings={'use_numpy': True}) as client: client.execute('SELECT 1') self.assertEqual( 'Extras for NumPy must be installed', str(e.exception) ) def test_query_dataframe(self): with self.assertRaises(RuntimeError) as e: with self.created_client(settings={'use_numpy': True}) as client: client.query_dataframe('SELECT 1 AS x') self.assertEqual( 'Extras for NumPy must be installed', str(e.exception) ) python-clickhouse-driver-0.2.3/tests/numpy/testcase.py000066400000000000000000000011511420676740400231640ustar00rootroot00000000000000try: import numpy as np except ImportError: np = None from tests.numpy.util import check_numpy from tests.testcase import BaseTestCase class NumpyBaseTestCase(BaseTestCase): client_kwargs = {'settings': {'use_numpy': True}} @check_numpy def setUp(self): super(NumpyBaseTestCase, self).setUp() def assertArraysEqual(self, first, second): return self.assertTrue((first == second).all()) def assertArraysListEqual(self, first, second): self.assertEqual(len(first), len(second)) for x, y in zip(first, second): self.assertTrue((x == y).all()) python-clickhouse-driver-0.2.3/tests/numpy/util.py000066400000000000000000000005141420676740400223300ustar00rootroot00000000000000from functools import wraps from unittest import SkipTest def check_numpy(f): @wraps(f) def wrapper(*args, **kwargs): try: return f(*args, **kwargs) except RuntimeError as e: if 'NumPy' in str(e): raise SkipTest('Numpy package is not installed') return wrapper python-clickhouse-driver-0.2.3/tests/test_blocks.py000066400000000000000000000206051420676740400225220ustar00rootroot00000000000000import types from unittest.mock import patch from clickhouse_driver.errors import ServerException from tests.testcase import BaseTestCase, file_config from tests.util import capture_logging class BlocksTestCase(BaseTestCase): def test_return_totals_extremes(self): rv = self.client.execute( 'SELECT a, sum(b + a) FROM (' 'SELECT arrayJoin(range(3)) - 1 AS a,' 'arrayJoin(range(4)) AS b' ') AS t ' 'GROUP BY a WITH TOTALS ' 'ORDER BY a', settings={'extremes': 1} ) self.assertEqual(rv, [ (-1, 2), (0, 6), (1, 10), # TOTALS (0, 18), # EXTREMES (-1, 2), (1, 10) ]) def test_columnar_result(self): rv = self.client.execute( 'SELECT a, sum(b + a) FROM (' 'SELECT arrayJoin(range(3)) - 1 AS a,' 'arrayJoin(range(4)) AS b' ') AS t ' 'GROUP BY a ' 'ORDER BY a', columnar=True ) self.assertEqual(rv, [ (-1, 0, 1), (2, 6, 10) ]) def test_columnar_block_extend(self): with self.create_table('a Int32'): self.client.execute('INSERT INTO test (a) VALUES', [(1, )]) self.client.execute('INSERT INTO test (a) VALUES', [(2, )]) query = 'SELECT * FROM test ORDER BY a' inserted = self.client.execute(query, columnar=True) self.assertEqual(inserted, [(1, 2)]) def test_select_with_column_types(self): rv = self.client.execute( 'SELECT CAST(1 AS Int32) AS x', with_column_types=True ) self.assertEqual(rv, ([(1,)], [('x', 'Int32')])) def test_select_with_columnar_with_column_types(self): progress = self.client.execute_with_progress( 'SELECT arrayJoin(A) -1 as j,' 'arrayJoin(A)+1 as k FROM(' 'SELECT range(3) as A)', columnar=True, with_column_types=True) rv = ([(-1, 0, 1), (1, 2, 3)], [('j', 'Int16'), ('k', 'UInt16')]) self.assertEqual(progress.get_result(), rv) def test_close_connection_on_keyboard_interrupt(self): connection = self.client.connection with self.assertRaises(KeyboardInterrupt): with patch.object(connection, 'send_query') as mocked_send_query: mocked_send_query.side_effect = KeyboardInterrupt self.client.execute('SELECT 1') self.assertFalse(self.client.connection.connected) class ProgressTestCase(BaseTestCase): def test_select_with_progress(self): progress = self.client.execute_with_progress('SELECT 2') self.assertEqual( list(progress), [(1, 0), (1, 0)] if self.server_version > (20,) else [(1, 0)] ) self.assertEqual(progress.get_result(), [(2,)]) self.assertTrue(self.client.connection.connected) def test_progress_totals(self): progress = self.client.execute_with_progress('SELECT 2') self.assertEqual(progress.progress_totals.rows, 0) self.assertEqual(progress.progress_totals.bytes, 0) self.assertEqual(progress.progress_totals.total_rows, 0) self.assertEqual(progress.get_result(), [(2,)]) self.assertEqual(progress.progress_totals.rows, 1) self.assertEqual(progress.progress_totals.bytes, 1) self.assertEqual(progress.progress_totals.total_rows, 0) def test_select_with_progress_error(self): with self.assertRaises(ServerException): progress = self.client.execute_with_progress('SELECT error') list(progress) self.assertFalse(self.client.connection.connected) def test_select_with_progress_no_progress_unwind(self): progress = self.client.execute_with_progress('SELECT 2') self.assertEqual(progress.get_result(), [(2,)]) self.assertTrue(self.client.connection.connected) def test_select_with_progress_cancel(self): self.client.execute_with_progress('SELECT 2') rv = self.client.cancel() self.assertEqual(rv, [(2,)]) self.assertTrue(self.client.connection.connected) def test_select_with_progress_cancel_with_column_types(self): self.client.execute_with_progress('SELECT CAST(2 AS Int32) as x') rv = self.client.cancel(with_column_types=True) self.assertEqual(rv, ([(2,)], [('x', 'Int32')])) self.assertTrue(self.client.connection.connected) def test_select_with_progress_with_params(self): progress = self.client.execute_with_progress( 'SELECT %(x)s', params={'x': 2} ) self.assertEqual(progress.get_result(), [(2,)]) self.assertTrue(self.client.connection.connected) def test_close_connection_on_keyboard_interrupt(self): connection = self.client.connection with self.assertRaises(KeyboardInterrupt): with patch.object(connection, 'send_query') as mocked_send_query: mocked_send_query.side_effect = KeyboardInterrupt self.client.execute_with_progress('SELECT 1') self.assertFalse(self.client.connection.connected) class IteratorTestCase(BaseTestCase): def test_select_with_iter(self): result = self.client.execute_iter( 'SELECT number FROM system.numbers LIMIT 10' ) self.assertIsInstance(result, types.GeneratorType) self.assertEqual(list(result), list(zip(range(10)))) self.assertEqual(list(result), []) def test_select_with_iter_with_column_types(self): result = self.client.execute_iter( 'SELECT CAST(number AS UInt32) as number ' 'FROM system.numbers LIMIT 10', with_column_types=True ) self.assertIsInstance(result, types.GeneratorType) self.assertEqual( list(result), [[('number', 'UInt32')]] + list(zip(range(10))) ) self.assertEqual(list(result), []) def test_select_with_iter_error(self): with self.assertRaises(ServerException): result = self.client.execute_iter('SELECT error') self.assertIsInstance(result, types.GeneratorType) list(result) self.assertFalse(self.client.connection.connected) def test_close_connection_on_keyboard_interrupt(self): connection = self.client.connection with self.assertRaises(KeyboardInterrupt): with patch.object(connection, 'send_query') as mocked_send_query: mocked_send_query.side_effect = KeyboardInterrupt self.client.execute_iter('SELECT 1') self.assertFalse(self.client.connection.connected) class LogTestCase(BaseTestCase): required_server_version = (18, 12, 13) def test_logs(self): with capture_logging('clickhouse_driver.log', 'INFO') as buffer: settings = {'send_logs_level': 'debug'} query = 'SELECT 1' self.client.execute(query, settings=settings) self.assertIn(query, buffer.getvalue()) def test_logs_insert(self): with capture_logging('clickhouse_driver.log', 'INFO') as buffer: with self.create_table('a Int32'): settings = {'send_logs_level': 'debug'} query = 'INSERT INTO test (a) VALUES' self.client.execute(query, [(1, )], settings=settings) logs = buffer.getvalue() self.assertIn(query, logs) if self.server_version > (19, ): self.assertIn('MemoryTracker', logs) # Test all packets of INSERT query are consumed. rv = self.client.execute('SELECT 1', settings=settings) self.assertEqual(rv, [(1, )]) def test_logs_with_compression(self): compression = 'lz4' supported_compressions = ( file_config.get('db', 'compression').split(',') ) if compression not in supported_compressions: self.skipTest( 'Compression {} is not supported'.format(compression) ) with self.created_client(compression='lz4') as client: with capture_logging('clickhouse_driver.log', 'INFO') as buffer: settings = {'send_logs_level': 'debug'} query = 'SELECT 1' client.execute(query, settings=settings) self.assertIn(query, buffer.getvalue()) python-clickhouse-driver-0.2.3/tests/test_buffered_reader.py000066400000000000000000000013641420676740400243520ustar00rootroot00000000000000import socket from unittest import TestCase, mock from clickhouse_driver.bufferedreader import BufferedSocketReader class BufferedReaderTestCase(TestCase): def test_overflow_signed_int_string_size(self): data = b'\xFF\xFE\xFC\xFE\xFE\xFE\xFE\xFE\x29\x80\x40\x00\x00\x01' def recv_into(buf): size = len(data) buf[0:size] = data return size with mock.patch('socket.socket') as mock_socket: mock_socket.return_value.recv_into.side_effect = recv_into reader = BufferedSocketReader(socket.socket(), 1024) # Trying to allocate huge amount of memory. with self.assertRaises(MemoryError): reader.read_strings(5, encoding='utf-8') python-clickhouse-driver-0.2.3/tests/test_client.py000066400000000000000000000233151420676740400225240ustar00rootroot00000000000000import ssl from clickhouse_driver import Client from clickhouse_driver.compression.lz4 import Compressor as LZ4Compressor from clickhouse_driver.compression.lz4hc import Compressor as LZHC4Compressor from clickhouse_driver.compression.zstd import Compressor as ZSTDCompressor from clickhouse_driver.protocol import Compression from tests.numpy.util import check_numpy from tests.testcase import TestCase class ClientFromUrlTestCase(TestCase): def assertHostsEqual(self, client, another, msg=None): self.assertEqual(list(client.connection.hosts), another, msg=msg) def test_simple(self): c = Client.from_url('clickhouse://host') self.assertHostsEqual(c, [('host', 9000)]) self.assertEqual(c.connection.database, 'default') c = Client.from_url('clickhouse://host/db') self.assertHostsEqual(c, [('host', 9000)]) self.assertEqual(c.connection.database, 'db') def test_credentials(self): c = Client.from_url('clickhouse://host/db') self.assertEqual(c.connection.user, 'default') self.assertEqual(c.connection.password, '') c = Client.from_url('clickhouse://admin:secure@host/db') self.assertEqual(c.connection.user, 'admin') self.assertEqual(c.connection.password, 'secure') c = Client.from_url('clickhouse://user:@host/db') self.assertEqual(c.connection.user, 'user') self.assertEqual(c.connection.password, '') def test_credentials_unquoting(self): c = Client.from_url('clickhouse://ad%3Amin:se%2Fcure@host/db') self.assertEqual(c.connection.user, 'ad:min') self.assertEqual(c.connection.password, 'se/cure') def test_schema(self): c = Client.from_url('clickhouse://host') self.assertFalse(c.connection.secure_socket) c = Client.from_url('clickhouses://host') self.assertTrue(c.connection.secure_socket) c = Client.from_url('test://host') self.assertFalse(c.connection.secure_socket) def test_port(self): c = Client.from_url('clickhouse://host') self.assertHostsEqual(c, [('host', 9000)]) c = Client.from_url('clickhouses://host') self.assertHostsEqual(c, [('host', 9440)]) c = Client.from_url('clickhouses://host:1234') self.assertHostsEqual(c, [('host', 1234)]) def test_secure(self): c = Client.from_url('clickhouse://host?secure=n') self.assertHostsEqual(c, [('host', 9000)]) self.assertFalse(c.connection.secure_socket) c = Client.from_url('clickhouse://host?secure=y') self.assertHostsEqual(c, [('host', 9440)]) self.assertTrue(c.connection.secure_socket) c = Client.from_url('clickhouse://host:1234?secure=y') self.assertHostsEqual(c, [('host', 1234)]) self.assertTrue(c.connection.secure_socket) with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?secure=nonono') def test_compression(self): c = Client.from_url('clickhouse://host?compression=n') self.assertEqual(c.connection.compression, Compression.DISABLED) self.assertIsNone(c.connection.compressor_cls) c = Client.from_url('clickhouse://host?compression=y') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZ4Compressor) c = Client.from_url('clickhouse://host?compression=lz4') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZ4Compressor) c = Client.from_url('clickhouse://host?compression=lz4hc') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZHC4Compressor) c = Client.from_url('clickhouse://host?compression=zstd') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, ZSTDCompressor) with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?compression=custom') def test_client_name(self): c = Client.from_url('clickhouse://host?client_name=native') self.assertEqual(c.connection.client_name, 'ClickHouse native') def test_timeouts(self): with self.assertRaises(ValueError): Client.from_url('clickhouse://host?connect_timeout=test') c = Client.from_url('clickhouse://host?connect_timeout=1.2') self.assertEqual(c.connection.connect_timeout, 1.2) c = Client.from_url('clickhouse://host?send_receive_timeout=1.2') self.assertEqual(c.connection.send_receive_timeout, 1.2) c = Client.from_url('clickhouse://host?sync_request_timeout=1.2') self.assertEqual(c.connection.sync_request_timeout, 1.2) def test_compress_block_size(self): with self.assertRaises(ValueError): Client.from_url('clickhouse://host?compress_block_size=test') c = Client.from_url('clickhouse://host?compress_block_size=100500') # compression is not set self.assertIsNone(c.connection.compress_block_size) c = Client.from_url( 'clickhouse://host?' 'compress_block_size=100500&' 'compression=1' ) self.assertEqual(c.connection.compress_block_size, 100500) def test_settings(self): c = Client.from_url( 'clickhouse://host?' 'send_logs_level=trace&' 'max_block_size=123' ) self.assertEqual(c.settings, { 'send_logs_level': 'trace', 'max_block_size': '123' }) def test_ssl(self): c = Client.from_url( 'clickhouses://host?' 'verify=false&' 'ssl_version=PROTOCOL_SSLv23&' 'ca_certs=/tmp/certs&' 'ciphers=HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5' ) self.assertEqual(c.connection.ssl_options, { 'ssl_version': ssl.PROTOCOL_SSLv23, 'ca_certs': '/tmp/certs', 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5' }) def test_ssl_key_cert(self): base_url = ( 'clickhouses://host?' 'verify=true&' 'ssl_version=PROTOCOL_SSLv23&' 'ca_certs=/tmp/certs&' 'ciphers=HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5&' ) base_expected = { 'ssl_version': ssl.PROTOCOL_SSLv23, 'ca_certs': '/tmp/certs', 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5' } c = Client.from_url( base_url + 'keyfile=/tmp/client.key&' 'certfile=/tmp/client.cert' ) expected = base_expected.copy() expected.update({ 'keyfile': '/tmp/client.key', 'certfile': '/tmp/client.cert' }) self.assertEqual(c.connection.ssl_options, expected) c = Client.from_url( base_url + 'certfile=/tmp/client.cert' ) expected = base_expected.copy() expected.update({ 'certfile': '/tmp/client.cert' }) self.assertEqual(c.connection.ssl_options, expected) def test_alt_hosts(self): c = Client.from_url('clickhouse://host?alt_hosts=host2:1234') self.assertHostsEqual(c, [('host', 9000), ('host2', 1234)]) c = Client.from_url('clickhouse://host?alt_hosts=host2') self.assertHostsEqual(c, [('host', 9000), ('host2', 9000)]) def test_parameters_cast(self): c = Client.from_url('clickhouse://host?insert_block_size=123') self.assertEqual( c.connection.context.client_settings['insert_block_size'], 123 ) def test_settings_is_important(self): c = Client.from_url('clickhouse://host?settings_is_important=1') self.assertEqual(c.connection.settings_is_important, True) with self.assertRaises(ValueError): c = Client.from_url('clickhouse://host?settings_is_important=2') self.assertEqual(c.connection.settings_is_important, True) c = Client.from_url('clickhouse://host?settings_is_important=0') self.assertEqual(c.connection.settings_is_important, False) @check_numpy def test_use_numpy(self): c = Client.from_url('clickhouse://host?use_numpy=true') self.assertTrue(c.connection.context.client_settings['use_numpy']) def test_opentelemetry(self): c = Client.from_url( 'clickhouse://host?opentelemetry_traceparent=' '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00' ) self.assertEqual( c.connection.context.client_settings['opentelemetry_traceparent'], '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00' ) self.assertEqual( c.connection.context.client_settings['opentelemetry_tracestate'], '' ) c = Client.from_url( 'clickhouse://host?opentelemetry_traceparent=' '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00&' 'opentelemetry_tracestate=state' ) self.assertEqual( c.connection.context.client_settings['opentelemetry_traceparent'], '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00' ) self.assertEqual( c.connection.context.client_settings['opentelemetry_tracestate'], 'state' ) def test_quota_key(self): c = Client.from_url('clickhouse://host?quota_key=myquota') self.assertEqual( c.connection.context.client_settings['quota_key'], 'myquota' ) c = Client.from_url('clickhouse://host') self.assertEqual( c.connection.context.client_settings['quota_key'], '' ) python-clickhouse-driver-0.2.3/tests/test_compression.py000066400000000000000000000061111420676740400236020ustar00rootroot00000000000000from datetime import date, datetime from unittest import TestCase from clickhouse_driver import errors from clickhouse_driver.client import Client from clickhouse_driver.compression import get_compressor_cls from clickhouse_driver.compression.lz4 import Compressor from .testcase import BaseTestCase, file_config class BaseCompressionTestCase(BaseTestCase): compression = False supported_compressions = file_config.get('db', 'compression').split(',') def _create_client(self): settings = None if self.compression: # Set server compression method explicitly # By default server sends blocks compressed by LZ4. method = self.compression if self.server_version > (19, ): method = method.upper() settings = {'network_compression_method': method} return Client( self.host, self.port, self.database, self.user, self.password, compression=self.compression, settings=settings ) def setUp(self): super(BaseCompressionTestCase, self).setUp() supported = ( self.compression is False or self.compression in self.supported_compressions ) if not supported: self.skipTest( 'Compression {} is not supported'.format(self.compression) ) def run_simple(self): with self.create_table('a Date, b DateTime'): data = [(date(2012, 10, 25), datetime(2012, 10, 25, 14, 7, 19))] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '2012-10-25\t2012-10-25 14:07:19\n') inserted = self.client.execute(query) self.assertEqual(inserted, data) def test(self): if self.compression is False: return self.run_simple() class LZ4ReadWriteTestCase(BaseCompressionTestCase): compression = 'lz4' class LZ4HCReadWriteTestCase(BaseCompressionTestCase): compression = 'lz4hc' class ZSTDReadWriteTestCase(BaseCompressionTestCase): compression = 'zstd' class MiscCompressionTestCase(TestCase): def test_default_compression(self): client = Client('localhost', compression=True) self.assertEqual(client.connection.compressor_cls, Compressor) def test_unknown_compressor(self): with self.assertRaises(errors.UnknownCompressionMethod) as e: get_compressor_cls('hello') self.assertEqual( e.exception.code, errors.ErrorCodes.UNKNOWN_COMPRESSION_METHOD ) class ReadByBlocksTestCase(BaseCompressionTestCase): compression = 'lz4' def test(self): with self.create_table('a Int32'): data = [(x % 200, ) for x in range(1000000)] self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.client.execute(query) self.assertEqual(inserted, data) python-clickhouse-driver-0.2.3/tests/test_connect.py000066400000000000000000000256031420676740400227010ustar00rootroot00000000000000# coding: utf-8 import socket from io import BytesIO from unittest.mock import patch from clickhouse_driver import errors from clickhouse_driver.client import Client from clickhouse_driver.protocol import ClientPacketTypes, ServerPacketTypes from clickhouse_driver.bufferedreader import BufferedReader from clickhouse_driver.writer import write_binary_str from tests.testcase import BaseTestCase from unittest import TestCase class PacketsTestCase(BaseTestCase): def test_packets_to_str(self): self.assertEqual(ClientPacketTypes.to_str(2), 'Data') self.assertEqual(ClientPacketTypes.to_str(6), 'Unknown packet') self.assertEqual(ClientPacketTypes.to_str(42), 'Unknown packet') self.assertEqual(ServerPacketTypes.to_str(4), 'Pong') self.assertEqual(ServerPacketTypes.to_str(12), 'Unknown packet') self.assertEqual(ServerPacketTypes.to_str(42), 'Unknown packet') class ConnectTestCase(BaseTestCase): def unexpected_packet_message(self, expected, got): return ( 'Code: 102. Unexpected packet from server {}:{} ' '(expected {}, got {})' ).format(self.host, self.port, expected, got) def test_exception_on_hello_packet(self): with self.created_client(user='wrong_user') as client: with self.assertRaises(errors.ServerException) as e: client.execute('SHOW TABLES') # Simple exception formatting checks exc = e.exception self.assertIn('Code:', str(exc)) self.assertIn('Stack trace:', str(exc)) def test_network_error(self): client = Client('bad-address') with patch('socket.getaddrinfo') as mocked_getaddrinfo: mocked_getaddrinfo.side_effect = socket.error( -2, 'Name or service not known' ) with self.assertRaises(errors.NetworkError): client.execute('SHOW TABLES') def test_timeout_error(self): with patch('socket.socket') as ms: ms.return_value.connect.side_effect = socket.timeout with self.assertRaises(errors.SocketTimeoutError) as e: self.client.execute('SHOW TABLES') self.assertEqual( str(e.exception), 'Code: 209. ({}:{})'.format(self.host, self.port) ) ms.return_value.connect.side_effect = socket.timeout(42, 'Test') with self.assertRaises(errors.SocketTimeoutError) as e: self.client.execute('SHOW TABLES') self.assertEqual( str(e.exception), 'Code: 209. Test ({}:{})'.format(self.host, self.port) ) def test_transport_not_connection_on_disconnect(self): # Create connection. self.client.execute('SELECT 1') connection = self.client.connection with patch.object(connection, 'ping') as mocked_ping: mocked_ping.return_value = False with patch.object(connection, 'socket') as mocked_socket: mocked_socket.shutdown.side_effect = socket.error( 107, 'Transport endpoint is not connected' ) # New socket should be created. rv = self.client.execute('SELECT 1') self.assertEqual(rv, [(1, )]) # Close newly created socket. connection.socket.close() def test_socket_error_on_ping(self): self.client.execute('SELECT 1') with patch.object(self.client.connection, 'fout') as mocked_fout: mocked_fout.flush.side_effect = socket.error(32, 'Broken pipe') rv = self.client.execute('SELECT 1') self.assertEqual(rv, [(1, )]) def test_ping_got_unexpected_package(self): self.client.execute('SELECT 1') with patch.object(self.client.connection, 'fin') as mocked_fin: # Emulate Exception packet on ping. mocked_fin.read_one.return_value = 2 error = errors.UnexpectedPacketFromServerError with self.assertRaises(error) as e: self.client.execute('SELECT 1') self.assertEqual( str(e.exception), self.unexpected_packet_message('Pong', 'Exception') ) def test_eof_on_receive_packet(self): self.client.execute('SELECT 1') with patch.object(self.client.connection, 'fin') as mocked_fin: # Emulate Exception packet on ping. mocked_fin.read_one.side_effect = [4, EOFError] with self.assertRaises(EOFError): self.client.execute('SELECT 1') def test_eof_error_on_ping(self): self.client.execute('SELECT 1') self.raised = False read_one = self.client.connection.fin.read_one def side_effect(*args, **kwargs): if not self.raised: self.raised = True raise EOFError('Unexpected EOF while reading bytes') else: return read_one(*args, **kwargs) with patch.object(self.client.connection, 'fin') as mocked_fin: mocked_fin.read_one.side_effect = side_effect rv = self.client.execute('SELECT 1') self.assertEqual(rv, [(1, )]) def test_alt_hosts(self): client = Client( 'wrong_host', 1234, self.database, self.user, self.password, alt_hosts='{}:{}'.format(self.host, self.port) ) self.n_calls = 0 getaddrinfo = socket.getaddrinfo def side_getaddrinfo(host, *args, **kwargs): if host == 'wrong_host': self.n_calls += 1 raise socket.error(-2, 'Name or service not known') return getaddrinfo(host, *args, **kwargs) with patch('socket.getaddrinfo') as mocked_getaddrinfo: mocked_getaddrinfo.side_effect = side_getaddrinfo rv = client.execute('SELECT 1') self.assertEqual(rv, [(1,)]) client.disconnect() rv = client.execute('SELECT 1') self.assertEqual(rv, [(1,)]) # Last host must be remembered and getaddrinfo must call exactly # once with host == 'wrong_host'. self.assertEqual(self.n_calls, 1) client.disconnect() def test_remember_current_database(self): with self.created_client() as client: client.execute(' USE system ; ') client.disconnect() rv = client.execute('SELECT currentDatabase()') self.assertEqual(rv, [('system', )]) def test_context_manager(self): with self.created_client() as c: c.execute('SELECT 1') self.assertTrue(c.connection.connected) self.assertFalse(c.connection.connected) def test_unknown_packet(self): self.client.execute('SELECT 1') with patch('clickhouse_driver.connection.read_varint') as read_mock, \ patch.object(self.client.connection, 'force_connect'): read_mock.return_value = 42 with self.assertRaises(errors.UnknownPacketFromServerError) as e: self.client.execute('SELECT 1') self.assertEqual( str(e.exception), 'Code: 100. Unknown packet 42 from server {}:{}'.format( self.host, self.port ) ) def test_unknown_packet_on_connect(self): with patch('clickhouse_driver.connection.read_varint') as read_mock: read_mock.return_value = 42 error = errors.UnexpectedPacketFromServerError with self.assertRaises(error) as e: self.client.execute('SELECT 1') msg = self.unexpected_packet_message( 'Hello or Exception', 'Unknown packet' ) self.assertEqual(str(e.exception), msg) def test_partially_consumed_query(self): self.client.execute_iter('SELECT 1') error = errors.PartiallyConsumedQueryError with self.assertRaises(error) as e: self.client.execute_iter('SELECT 1') self.assertEqual( str(e.exception), 'Simultaneous queries on single connection detected' ) rv = self.client.execute('SELECT 1') self.assertEqual(rv, [(1, )]) def test_read_all_packets_on_execute_iter(self): list(self.client.execute_iter('SELECT 1')) list(self.client.execute_iter('SELECT 1')) class FakeBufferedReader(BufferedReader): def __init__(self, inputs, bufsize=128): super(FakeBufferedReader, self).__init__(bufsize) self._inputs = inputs self._counter = 0 def read_into_buffer(self): try: value = self._inputs[self._counter] except IndexError: value = b'' else: self._counter += 1 self.current_buffer_size = len(value) self.buffer[:len(value)] = value if self.current_buffer_size == 0: raise EOFError('Unexpected EOF while reading bytes') class TestBufferedReader(TestCase): def test_corner_case_read(self): rdr = FakeBufferedReader([ b'\x00' * 10, b'\xff' * 10, ]) self.assertEqual(rdr.read(5), b'\x00' * 5) self.assertEqual(rdr.read(10), b'\x00' * 5 + b'\xff' * 5) self.assertEqual(rdr.read(5), b'\xff' * 5) self.assertRaises(EOFError, rdr.read, 10) def test_corner_case_read_to_end_of_buffer(self): rdr = FakeBufferedReader([ b'\x00' * 10, b'\xff' * 10, ]) self.assertEqual(rdr.read(5), b'\x00' * 5) self.assertEqual(rdr.read(5), b'\x00' * 5) self.assertEqual(rdr.read(5), b'\xff' * 5) self.assertEqual(rdr.read(5), b'\xff' * 5) self.assertRaises(EOFError, rdr.read, 10) def test_corner_case_exact_buffer(self): rdr = FakeBufferedReader([ b'\x00' * 10, b'\xff' * 10, ], bufsize=10) self.assertEqual(rdr.read(5), b'\x00' * 5) self.assertEqual(rdr.read(10), b'\x00' * 5 + b'\xff' * 5) self.assertEqual(rdr.read(5), b'\xff' * 5) def test_read_strings(self): strings = [ u'Yoyodat' * 10, u'Peter Maffay' * 10, ] buf = BytesIO() for name in strings: write_binary_str(name, buf) buf = buf.getvalue() ref_values = tuple(x.encode('utf-8') for x in strings) for split in range(1, len(buf) - 1): for split_2 in range(split + 1, len(buf) - 2): self.assertEqual( buf[:split] + buf[split:split_2] + buf[split_2:], buf ) bufs = [ buf[:split], buf[split:split_2], buf[split_2:], ] rdr = FakeBufferedReader(bufs, bufsize=4096) read_values = rdr.read_strings(2) self.assertEqual(repr(ref_values), repr(read_values)) python-clickhouse-driver-0.2.3/tests/test_dbapi.py000066400000000000000000000341561420676740400223320ustar00rootroot00000000000000import types from contextlib import contextmanager import socket from unittest.mock import patch from clickhouse_driver import connect from clickhouse_driver.dbapi import ( ProgrammingError, InterfaceError, OperationalError ) from tests.testcase import BaseTestCase class DBAPITestCaseBase(BaseTestCase): def create_connection(self, **kwargs): kwargs.setdefault('user', self.user) kwargs.setdefault('password', self.password) kwargs.setdefault('host', self.host) kwargs.setdefault('port', self.port) kwargs.setdefault('database', self.database) return connect(**kwargs) @contextmanager def created_connection(self, **kwargs): connection = self.create_connection(**kwargs) try: yield connection finally: connection.close() @contextmanager def created_cursor(self, **kwargs): with self.created_connection(**kwargs) as connection: cursor = connection.cursor() try: yield cursor finally: cursor.close() class DBAPITestCase(DBAPITestCaseBase): def test_no_host_and_dsn(self): with self.assertRaises(ValueError) as e: self.create_connection(host=None) self.assertEqual(str(e.exception), 'host or dsn is required') def test_simple(self): with self.created_connection() as connection: cursor = connection.cursor() rv = cursor.execute('SELECT 1') self.assertIsNone(rv) self.assertEqual(cursor.fetchall(), [(1, )]) def test_from_dsn(self): connection = connect( 'clickhouse://{user}:{password}@{host}:{port}/{database}'.format( user=self.user, password=self.password, host=self.host, port=self.port, database=self.database ) ) cursor = connection.cursor() rv = cursor.execute('SELECT 1') self.assertIsNone(rv) self.assertEqual(cursor.fetchall(), [(1, )]) connection.close() def test_connect_default_params(self): connection = connect(host=self.host) cursor = connection.cursor() rv = cursor.execute('SELECT 1') self.assertIsNone(rv) self.assertEqual(cursor.fetchall(), [(1, )]) connection.close() def test_execute_fetchone(self): with self.created_cursor() as cursor: cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertIsInstance(cursor._rows, list) self.assertEqual(cursor.fetchone(), (0, )) self.assertEqual(cursor.fetchone(), (1, )) self.assertEqual(cursor.fetchone(), (2, )) self.assertEqual(cursor.fetchone(), (3, )) self.assertEqual(cursor.fetchone(), None) def test_execute_fetchmany(self): with self.created_cursor() as cursor: cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertIsInstance(cursor._rows, list) self.assertEqual(cursor.fetchmany(), [(0, )]) self.assertEqual(cursor.fetchmany(None), [(1, )]) self.assertEqual(cursor.fetchmany(0), []) self.assertEqual(cursor.fetchmany(-1), [(2, ), (3, )]) cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertEqual(cursor.fetchmany(1), [(0, )]) self.assertEqual(cursor.fetchmany(2), [(1, ), (2, )]) self.assertEqual(cursor.fetchmany(3), [(3, )]) self.assertEqual(cursor.fetchmany(3), []) cursor.arraysize = 2 cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertEqual(cursor.fetchmany(), [(0,), (1,)]) self.assertEqual(cursor.fetchmany(), [(2,), (3,)]) def test_execute_fetchall(self): with self.created_cursor() as cursor: cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertEqual(cursor.rowcount, 4) self.assertEqual(cursor.fetchall(), [(0,), (1,), (2,), (3,)]) def test_executemany(self): with self.created_cursor() as cursor, self.create_table('a UInt32'): data = [(0, ), (1, ), (2, )] rv = cursor.executemany('INSERT INTO test VALUES', data) self.assertIsNone(rv, None) self.assertEqual(cursor.rowcount, 3) cursor.execute('SELECT * FROM test') self.assertEqual(cursor.fetchall(), data) def test_fake_transactions(self): with self.created_connection() as connection: connection.commit() connection.rollback() def test_exception_execute(self): with self.created_cursor(user='wrong_user') as cursor: with self.assertRaises(OperationalError) as e: cursor.execute('SELECT 1') code = 516 if self.server_version > (20, ) else 192 self.assertIn('Code: {}'.format(code), str(e.exception)) def test_exception_executemany(self): with self.created_cursor(user='wrong_user') as cursor: with self.assertRaises(OperationalError) as e: cursor.executemany('INSERT INTO test VALUES', [(0, )]) code = 516 if self.server_version > (20, ) else 192 self.assertIn('Code: {}'.format(code), str(e.exception)) self.assertEqual(cursor.rowcount, -1) def test_rowcount_insert_from_select(self): with self.created_cursor() as cursor, self.create_table('a UInt8'): cursor.execute( 'INSERT INTO test ' 'SELECT number FROM system.numbers LIMIT 4' ) self.assertEqual(cursor.rowcount, -1) def test_execute_insert(self): with self.created_cursor() as cursor, self.create_table('a UInt8'): cursor.execute('INSERT INTO test VALUES', [[4]]) self.assertEqual(cursor.rowcount, 1) def test_description(self): with self.created_cursor() as cursor: self.assertIsNone(cursor.description) cursor.execute('SELECT CAST(1 AS UInt32) AS test') desc = cursor.description self.assertEqual(len(desc), 1) self.assertEqual(desc[0].name, 'test') self.assertEqual(desc[0].type_code, 'UInt32') def test_pep249_sizes(self): with self.created_cursor() as cursor: cursor.setinputsizes(0) cursor.setoutputsize(0) def test_ddl(self): with self.created_cursor() as cursor: cursor.execute('DROP TABLE IF EXISTS test') self.assertEqual(cursor.fetchall(), []) self.assertEqual(cursor.rowcount, -1) def test_remember_last_host(self): self.n_calls = 0 getaddrinfo = socket.getaddrinfo def side_getaddrinfo(host, *args, **kwargs): if host == 'wrong_host': self.n_calls += 1 raise socket.error(-2, 'Name or service not known') return getaddrinfo(host, *args, **kwargs) with patch('socket.getaddrinfo') as mocked_getaddrinfo: mocked_getaddrinfo.side_effect = side_getaddrinfo conn_kwargs = { 'host': 'wrong_host', 'port': 1234, 'alt_hosts': '{}:{}'.format(self.host, self.port) } with self.created_connection(**conn_kwargs) as connection: cursor = connection.cursor() cursor.execute('SELECT 1') self.assertEqual(cursor.fetchall(), [(1, )]) cursor.close() cursor = connection.cursor() cursor.execute('SELECT 1') self.assertEqual(cursor.fetchall(), [(1, )]) cursor.close() # Last host must be remembered and getaddrinfo must call exactly # once with host == 'wrong_host'. self.assertEqual(self.n_calls, 1) def test_remove_cursor_from_connection_on_closing(self): with self.created_connection() as connection: self.assertEqual(len(connection.cursors), 0) cur = connection.cursor() self.assertEqual(len(connection.cursors), 1) cur.close() self.assertEqual(len(connection.cursors), 0) class StreamingTestCase(DBAPITestCaseBase): def test_fetchone(self): with self.created_cursor() as cursor: cursor.set_stream_results(True, 2) cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertIsInstance(cursor._rows, types.GeneratorType) self.assertEqual(cursor.fetchone(), (0, )) self.assertEqual(cursor.fetchone(), (1, )) self.assertEqual(cursor.fetchone(), (2, )) self.assertEqual(cursor.fetchone(), (3, )) self.assertEqual(cursor.fetchone(), None) def test_fetchmany(self): with self.created_cursor() as cursor: cursor.set_stream_results(True, 2) cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertIsInstance(cursor._rows, types.GeneratorType) self.assertEqual(cursor.fetchmany(), [(0, )]) self.assertEqual(cursor.fetchmany(None), [(1, )]) self.assertEqual(cursor.fetchmany(0), []) self.assertEqual(cursor.fetchmany(-1), [(2, ), (3, )]) cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertEqual(cursor.fetchmany(1), [(0, )]) self.assertEqual(cursor.fetchmany(2), [(1, ), (2, )]) self.assertEqual(cursor.fetchmany(3), [(3, )]) self.assertEqual(cursor.fetchmany(3), []) def test_fetchall(self): with self.created_cursor() as cursor: cursor.set_stream_results(True, 2) cursor.execute('SELECT number FROM system.numbers LIMIT 4') # Check rowcount before and after fetch. self.assertEqual(cursor.rowcount, -1) self.assertEqual(cursor.fetchall(), [(0, ), (1, ), (2, ), (3, )]) self.assertEqual(cursor.rowcount, -1) class ReprTestCase(DBAPITestCaseBase): def test_cursor_repr(self): with self.created_cursor() as cursor: self.assertIn('closed: False', str(cursor)) def test_connection_repr(self): with self.created_connection() as conn: self.assertIn('closed: False', str(conn)) class ExtrasTestCase(DBAPITestCaseBase): def test_columns_with_types_select(self): with self.created_cursor() as cursor: self.assertIsNone(cursor.columns_with_types) cursor.execute( 'SELECT CAST(number AS UInt64) AS x ' 'FROM system.numbers LIMIT 4' ) cursor.fetchall() self.assertEqual(cursor.columns_with_types, [('x', 'UInt64')]) def test_columns_with_types_insert(self): with self.created_cursor() as cursor, self.create_table('a UInt8'): cursor.executemany('INSERT INTO test (a) VALUES', [(123, )]) self.assertIsNone(cursor.columns_with_types) def test_columns_with_types_streaming(self): with self.created_cursor() as cursor: cursor.set_stream_results(True, 2) cursor.execute( 'SELECT CAST(number AS UInt64) AS x ' 'FROM system.numbers LIMIT 4' ) self.assertEqual(cursor.columns_with_types, [('x', 'UInt64')]) list(cursor) self.assertEqual(cursor.columns_with_types, [('x', 'UInt64')]) def test_set_external_tables(self): with self.created_cursor() as cursor: data = [(0, ), (1, ), (2, )] cursor.set_external_table('table1', [('x', 'UInt32')], data) cursor.execute('SELECT * FROM table1') self.assertEqual(cursor.fetchall(), data) def test_settings(self): with self.created_cursor() as cursor: cursor.set_settings({'max_threads': 100500}) cursor.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_threads'", ) self.assertEqual(cursor.fetchall(), [('max_threads', '100500', 1)]) def test_set_query_id(self): with self.created_cursor() as cursor: query_id = 'my_query_id' cursor.set_query_id(query_id) cursor.execute( 'SELECT query_id ' 'FROM system.processes ' 'WHERE query_id = %(query_id)s', {'query_id': query_id} ) self.assertEqual(cursor.fetchall(), [(query_id, )]) def test_types_check(self): with self.created_cursor() as cursor, self.create_table('a UInt8'): cursor.set_types_check(True) data = [(300, )] cursor.executemany('INSERT INTO test (a) VALUES', data) cursor.execute('SELECT * FROM test') self.assertEqual(cursor.fetchall(), [(44, )]) def test_cursor_iteration(self): with self.created_cursor() as cursor: cursor.execute('SELECT number FROM system.numbers LIMIT 4') self.assertEqual(list(cursor), [(0,), (1,), (2,), (3,)]) def test_context_managers(self): with self.create_connection() as connection: with connection.cursor() as cursor: cursor.execute('SELECT 1') self.assertEqual(cursor.fetchall(), [(1, )]) class InterfaceTestCase(DBAPITestCaseBase): def test_execute_after_close(self): with self.created_cursor() as cursor: cursor.close() with self.assertRaises(InterfaceError) as e: cursor.execute('SELECT 1') self.assertEqual(str(e.exception), 'cursor already closed') def test_create_cursor_on_closed_connection(self): connection = self.create_connection() connection.close() with self.assertRaises(InterfaceError) as e: connection.cursor() self.assertEqual(str(e.exception), 'connection already closed') def test_execute_fetch_before_query(self): with self.created_cursor() as cursor: with self.assertRaises(ProgrammingError) as e: cursor.fetchall() self.assertEqual(str(e.exception), 'no results to fetch') python-clickhouse-driver-0.2.3/tests/test_errors.py000066400000000000000000000006541420676740400225630ustar00rootroot00000000000000import pickle import clickhouse_driver.errors as err def picklable(o): picked = pickle.loads(pickle.dumps(o)) assert repr(o) == repr(picked) assert str(o) == str(picked) def test_exception_picklable(): picklable(err.Error('foo')) picklable(err.Error(message='foo')) picklable(err.ServerException('foo', 0, Exception())) picklable(err.ServerException(message='foo', code=0, nested=Exception())) python-clickhouse-driver-0.2.3/tests/test_external_tables.py000066400000000000000000000022031420676740400244130ustar00rootroot00000000000000 from tests.testcase import BaseTestCase class ExternalTablesTestCase(BaseTestCase): def test_select(self): tables = [{ 'name': 'test', 'structure': [('x', 'Int32'), ('y', 'Array(Int32)')], 'data': [ {'x': 100, 'y': [2, 4, 6, 8]}, {'x': 500, 'y': [1, 3, 5, 7]}, ] }] rv = self.client.execute('SELECT * FROM test', external_tables=tables) self.assertEqual(rv, [(100, [2, 4, 6, 8]), (500, [1, 3, 5, 7])]) def test_send_empty_table(self): tables = [{ 'name': 'test', 'structure': [('x', 'Int32')], 'data': [] }] rv = self.client.execute('SELECT * FROM test', external_tables=tables) self.assertEqual(rv, []) def test_send_empty_table_structure(self): tables = [{ 'name': 'test', 'structure': [], 'data': [] }] with self.assertRaises(ValueError) as e: self.client.execute('SELECT * FROM test', external_tables=tables) self.assertIn('Empty table "test" structure', str(e.exception)) python-clickhouse-driver-0.2.3/tests/test_insert.py000066400000000000000000000177701420676740400225620ustar00rootroot00000000000000from datetime import date from tests.testcase import BaseTestCase from clickhouse_driver import errors from clickhouse_driver.errors import ServerException class InsertTestCase(BaseTestCase): def test_type_mismatch(self): with self.create_table('a Float32'): with self.assertRaises(errors.TypeMismatchError): data = [(date(2012, 10, 25), )] self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_no_such_column(self): with self.create_table('a Float32'): with self.assertRaises(ServerException): data = [(1, )] self.client.execute( 'INSERT INTO test (b) VALUES', data ) def test_data_malformed_rows(self): with self.create_table('a Int8'), self.assertRaises(TypeError): data = [1] self.client.execute( 'INSERT INTO test (a) VALUES', data ) def test_data_less_columns_then_expected(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, )] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) self.assertEqual(str(e.exception), 'Expected 2 columns, got 1') def test_data_more_columns_then_expected(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, 2, 3)] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) self.assertEqual(str(e.exception), 'Expected 2 columns, got 3') def test_data_different_rows_length(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, 2), (3, )] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) self.assertEqual(str(e.exception), 'Different rows length') def test_data_different_rows_length_from_dicts(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(KeyError): data = [{'a': 1, 'b': 2}, {'a': 3}] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) def test_data_unsupported_row_type(self): with self.create_table('a Int8'): with self.assertRaises(TypeError) as e: data = [1] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('dict, list or tuple is expected', str(e.exception)) def test_data_dicts_ok(self): with self.create_table('a Int8, b Int8'): data = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}] self.client.execute( 'INSERT INTO test (a, b) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1\t2\n3\t4\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(1, 2), (3, 4)]) def test_data_generator_type(self): with self.create_table('a Int8'): data = ((x, ) for x in range(3)) self.client.execute( 'INSERT INTO test (a) VALUES', data ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '0\n1\n2\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(0,), (1, ), (2, )]) def test_data_dicts_mixed_with_lists(self): with self.create_table('a Int8'): with self.assertRaises(TypeError) as e: data = [{'a': 1}, (2, )] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('dict is expected', str(e.exception)) with self.assertRaises(TypeError) as e: data = [(1, ), {'a': 2}] self.client.execute( 'INSERT INTO test (a) VALUES', data, types_check=True ) self.assertIn('list or tuple is expected', str(e.exception)) def test_empty_insert(self): with self.create_table('a Int8'): self.client.execute( 'INSERT INTO test (a) VALUES', [] ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '') inserted = self.client.execute(query) self.assertEqual(inserted, []) def test_insert_from_select(self): with self.create_table('a UInt64'): inserted = self.client.execute( 'INSERT INTO test (a) ' 'SELECT number FROM system.numbers LIMIT 5' ) self.assertEqual(inserted, []) def test_insert_return(self): with self.create_table('a Int8'): rv = self.client.execute( 'INSERT INTO test (a) VALUES', [] ) self.assertEqual(rv, 0) rv = self.client.execute( 'INSERT INTO test (a) VALUES', [(x,) for x in range(5)] ) self.assertEqual(rv, 5) class InsertColumnarTestCase(BaseTestCase): def test_insert_tuple_ok(self): with self.create_table('a Int8, b Int8'): data = [(1, 2, 3), (4, 5, 6)] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, columnar=True ) query = 'SELECT * FROM test' inserted = self.emit_cli(query) self.assertEqual(inserted, '1\t4\n2\t5\n3\t6\n') inserted = self.client.execute(query) self.assertEqual(inserted, [(1, 4), (2, 5), (3, 6)]) inserted = self.client.execute(query, columnar=True) self.assertEqual(inserted, [(1, 2, 3), (4, 5, 6)]) def test_insert_data_different_column_length(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, 2, 3), (4, 5)] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, columnar=True ) self.assertEqual(str(e.exception), 'Expected 3 rows, got 2') def test_data_less_columns_then_expected(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, 2)] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, columnar=True ) self.assertEqual(str(e.exception), 'Expected 2 columns, got 1') def test_data_more_columns_then_expected(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(ValueError) as e: data = [(1, 2), (3, 4), (5, 6)] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, columnar=True ) self.assertEqual(str(e.exception), 'Expected 2 columns, got 3') def test_data_invalid_types(self): with self.create_table('a Int8, b Int8'): with self.assertRaises(TypeError) as e: data = [(1, 2), {'a': 3, 'b': 4}] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, types_check=True, columnar=True ) self.assertIn('list or tuple is expected', str(e.exception)) with self.assertRaises(TypeError) as e: data = [(1, 2), 3] self.client.execute( 'INSERT INTO test (a, b) VALUES', data, types_check=True, columnar=True ) self.assertIn('list or tuple is expected', str(e.exception)) python-clickhouse-driver-0.2.3/tests/test_opentelemetry.py000066400000000000000000000055021420676740400241400ustar00rootroot00000000000000from tests.testcase import BaseTestCase from tests.util import capture_logging class OpenTelemetryTestCase(BaseTestCase): required_server_version = (20, 11, 2) def test_server_logs(self): tracestate = 'tracestate' traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' settings = { 'opentelemetry_tracestate': tracestate, 'opentelemetry_traceparent': traceparent } with self.created_client(settings=settings) as client: with capture_logging('clickhouse_driver.log', 'INFO') as buffer: settings = {'send_logs_level': 'trace'} query = 'SELECT 1' client.execute(query, settings=settings) value = buffer.getvalue() self.assertIn('OpenTelemetry', value) self.assertIn('1af7651916cd43dd8448eb211c80319c', value) def test_no_tracestate(self): traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' settings = { 'opentelemetry_traceparent': traceparent } with self.created_client(settings=settings) as client: with capture_logging('clickhouse_driver.log', 'INFO') as buffer: settings = {'send_logs_level': 'trace'} query = 'SELECT 1' client.execute(query, settings=settings) value = buffer.getvalue() self.assertIn('OpenTelemetry', value) self.assertIn('1af7651916cd43dd8448eb211c80319c', value) def test_bad_traceparent(self): settings = {'opentelemetry_traceparent': 'bad'} with self.created_client(settings=settings) as client: with self.assertRaises(ValueError) as e: client.execute('SELECT 1') self.assertEqual( str(e.exception), 'unexpected length 3, expected 55' ) traceparent = '00-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-yyyyyyyyyyyyyyyy-01' settings = {'opentelemetry_traceparent': traceparent} with self.created_client(settings=settings) as client: with self.assertRaises(ValueError) as e: client.execute('SELECT 1') self.assertEqual( str(e.exception), 'Malformed traceparant header: {}'.format(traceparent) ) def test_bad_traceparent_version(self): settings = { 'opentelemetry_traceparent': '01-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-01' } with self.created_client(settings=settings) as client: with self.assertRaises(ValueError) as e: client.execute('SELECT 1') self.assertEqual( str(e.exception), 'unexpected version 01, expected 00' ) python-clickhouse-driver-0.2.3/tests/test_query_info.py000066400000000000000000000130411420676740400234210ustar00rootroot00000000000000from contextlib import contextmanager from clickhouse_driver import errors from tests.testcase import BaseTestCase class QueryInfoTestCase(BaseTestCase): @property def sample_query(self): return 'SELECT * FROM test GROUP BY foo ORDER BY foo DESC LIMIT 5' @contextmanager def sample_table(self): with self.create_table('foo UInt8'): self.client.execute('INSERT INTO test (foo) VALUES', [(i,) for i in range(42)]) self.client.reset_last_query() yield def test_default_value(self): self.assertIsNone(self.client.last_query) def test_store_last_query_after_execute(self): with self.sample_table(): self.client.execute(self.sample_query) last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.profile_info) self.assertEqual(last_query.profile_info.rows_before_limit, 42) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 42) self.assertEqual(last_query.progress.bytes, 42) self.assertEqual(last_query.progress.total_rows, 0) self.assertGreater(last_query.elapsed, 0) def test_last_query_after_execute_iter(self): with self.sample_table(): list(self.client.execute_iter(self.sample_query)) last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.profile_info) self.assertEqual(last_query.profile_info.rows_before_limit, 42) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 42) self.assertEqual(last_query.progress.bytes, 42) self.assertEqual(last_query.progress.total_rows, 0) self.assertEqual(last_query.elapsed, 0) def test_last_query_after_execute_with_progress(self): with self.sample_table(): progress = self.client.execute_with_progress(self.sample_query) list(progress) progress.get_result() last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.profile_info) self.assertEqual(last_query.profile_info.rows_before_limit, 42) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 42) self.assertEqual(last_query.progress.bytes, 42) self.assertEqual(last_query.progress.total_rows, 0) self.assertEqual(last_query.elapsed, 0) def test_last_query_progress_total_rows(self): self.client.execute('SELECT max(number) FROM numbers(10)') last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.profile_info) self.assertEqual(last_query.profile_info.rows_before_limit, 10) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 10) self.assertEqual(last_query.progress.bytes, 80) total_rows = 10 if self.server_version > (19, 4) else 0 self.assertEqual(last_query.progress.total_rows, total_rows) self.assertGreater(last_query.elapsed, 0) def test_last_query_after_execute_insert(self): with self.sample_table(): self.client.execute('INSERT INTO test (foo) VALUES', [(i,) for i in range(42)]) last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 0) self.assertEqual(last_query.progress.bytes, 0) self.assertGreater(last_query.elapsed, 0) def test_override_after_subsequent_queries(self): query = 'SELECT * FROM test WHERE foo < %(i)s ORDER BY foo LIMIT 5' with self.sample_table(): for i in range(1, 10): self.client.execute(query, {'i': i}) profile_info = self.client.last_query.profile_info self.assertEqual(profile_info.rows_before_limit, i) def test_reset_last_query(self): with self.sample_table(): self.client.execute(self.sample_query) self.assertIsNotNone(self.client.last_query) self.client.reset_last_query() self.assertIsNone(self.client.last_query) def test_reset_on_query_error(self): with self.assertRaises(errors.ServerException): self.client.execute('SELECT answer FROM universe') self.assertIsNone(self.client.last_query) def test_progress_info_increment(self): self.client.execute( 'SELECT x FROM (' 'SELECT number AS x FROM numbers(100000000)' ') ORDER BY x ASC LIMIT 10' ) last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.progress) self.assertGreater(last_query.progress.rows, 100000000) self.assertGreater(last_query.progress.bytes, 800000000) total_rows = 100000000 if self.server_version > (19, 4) else 0 self.assertEqual(last_query.progress.total_rows, total_rows) def test_progress_info_ddl(self): self.client.execute('DROP TABLE IF EXISTS foo') last_query = self.client.last_query self.assertIsNotNone(last_query) self.assertIsNotNone(last_query.progress) self.assertEqual(last_query.progress.rows, 0) self.assertEqual(last_query.progress.bytes, 0) self.assertGreater(last_query.elapsed, 0) python-clickhouse-driver-0.2.3/tests/test_settings.py000066400000000000000000000121021420676740400230760ustar00rootroot00000000000000from clickhouse_driver.errors import ServerException, ErrorCodes from tests.testcase import BaseTestCase from tests.util import require_server_version class SettingTestCase(BaseTestCase): def test_settings_immutable(self): settings = {'strings_encoding': 'utf-8'} self.client.execute('SELECT 1', settings=settings) self.assertEqual(settings, {'strings_encoding': 'utf-8'}) def test_int_apply(self): settings = {'max_query_size': 142} rv = self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_query_size'", settings=settings ) self.assertEqual(rv, [('max_query_size', '142', 1)]) def test_float_apply(self): settings = {'totals_auto_threshold': 1.23} rv = self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'totals_auto_threshold'", settings=settings ) self.assertEqual(rv, [('totals_auto_threshold', '1.23', 1)]) def test_bool_apply(self): settings = {'force_index_by_date': 1} rv = self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'force_index_by_date'", settings=settings ) self.assertEqual(rv, [('force_index_by_date', '1', 1)]) @require_server_version(1, 1, 54388) def test_char_apply(self): settings = {'format_csv_delimiter': 'd'} rv = self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'format_csv_delimiter'", settings=settings ) self.assertEqual(rv, [('format_csv_delimiter', 'd', 1)]) def test_max_threads_apply(self): settings = {'max_threads': 100500} rv = self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_threads'", settings=settings ) self.assertEqual(rv, [('max_threads', '100500', 1)]) settings = {'max_threads': 'auto'} self.client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_threads'", settings=settings ) def test_unknown_setting(self): # For both cases unknown setting will be ignored: # - rev >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS # the setting will be ignored by the server with the warning message # (since clickhouse-server does not ignore only important settings, # the one that has important flag) # - otherwise the unknown setting will be ignored by the driver. settings = {'unknown_setting': 100500} self.client.execute('SELECT 1', settings=settings) # DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS is 20.1.2+ @require_server_version(20, 1, 2) def test_unknown_setting_is_important(self): # In case of rev >= # DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS and setting # marked as important, then the query should fail. settings = {'unknown_setting': 100500} with self.created_client(settings_is_important=True) as client: with self.assertRaises(ServerException) as e: client.execute('SELECT 1', settings=settings) self.assertEqual(e.exception.code, ErrorCodes.UNKNOWN_SETTING) def test_client_settings(self): settings = {'max_query_size': 142} with self.created_client(settings=settings) as client: rv = client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_query_size'" ) self.assertEqual(rv, [('max_query_size', '142', 1)]) def test_query_settings_override_client_settings(self): client_settings = {'max_query_size': 142} query_settings = {'max_query_size': 242} with self.created_client(settings=client_settings) as client: rv = client.execute( "SELECT name, value, changed FROM system.settings " "WHERE name = 'max_query_size'", settings=query_settings ) self.assertEqual(rv, [('max_query_size', '242', 1)]) class LimitsTestCase(BaseTestCase): def test_max_result_rows_apply(self): query = 'SELECT number FROM system.numbers LIMIT 10' settings = {'max_result_rows': 5} with self.assertRaises(ServerException) as e: self.client.execute(query, settings=settings) # New servers return TOO_MANY_ROWS_OR_BYTES. # Old servers return TOO_MANY_ROWS. error_codes = { ErrorCodes.TOO_MANY_ROWS_OR_BYTES, ErrorCodes.TOO_MANY_ROWS } self.assertIn(e.exception.code, error_codes) settings = {'max_result_rows': 5, 'result_overflow_mode': 'break'} rv = self.client.execute(query, settings=settings) self.assertEqual(len(rv), 10) rv = self.client.execute(query) self.assertEqual(len(rv), 10) python-clickhouse-driver-0.2.3/tests/test_substitution.py000066400000000000000000000165241420676740400240260ustar00rootroot00000000000000# coding=utf-8 from __future__ import unicode_literals from datetime import date, datetime from decimal import Decimal from unittest.mock import Mock from uuid import UUID from enum import IntEnum, Enum from pytz import timezone from tests.testcase import BaseTestCase from tests.util import patch_env_tz class ParametersSubstitutionTestCase(BaseTestCase): single_tpl = 'SELECT %(x)s' double_tpl = 'SELECT %(x)s, %(y)s' def assert_subst(self, tpl, params, sql): ctx = Mock() ctx.server_info.timezone = 'Europe/Moscow' self.assertEqual(self.client.substitute_params(tpl, params, ctx), sql) def test_int(self): params = {'x': 123} self.assert_subst(self.single_tpl, params, 'SELECT 123') rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [(123, )]) def test_null(self): params = {'x': None} self.assert_subst(self.single_tpl, params, 'SELECT NULL') rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [(None, )]) def test_date(self): d = date(2017, 10, 16) params = {'x': d} self.assert_subst(self.single_tpl, params, "SELECT '2017-10-16'") rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [('2017-10-16', )]) tpl = 'SELECT CAST(%(x)s AS Date)' self.assert_subst(tpl, params, "SELECT CAST('2017-10-16' AS Date)") rv = self.client.execute(tpl, params) self.assertEqual(rv, [(d, )]) def test_datetime(self): dt = datetime(2017, 10, 16, 0, 18, 50) params = {'x': dt} self.assert_subst(self.single_tpl, params, "SELECT '2017-10-16 00:18:50'") rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [('2017-10-16 00:18:50', )]) tpl = 'SELECT CAST(%(x)s AS DateTime)' self.assert_subst(tpl, params, "SELECT CAST('2017-10-16 00:18:50' AS DateTime)") rv = self.client.execute(tpl, params) self.assertEqual(rv, [(dt, )]) def test_datetime_with_timezone(self): dt = datetime(2017, 7, 14, 5, 40, 0) params = {'x': timezone('Asia/Kamchatka').localize(dt)} self.assert_subst(self.single_tpl, params, "SELECT '2017-07-13 20:40:00'") tpl = ( 'SELECT toDateTime(toInt32(toDateTime(%(x)s))), ' 'toInt32(toDateTime(%(x)s))' ) with patch_env_tz('Asia/Novosibirsk'): # use server timezone rv = self.client.execute( tpl, params, settings={'use_client_time_zone': False} ) self.assertEqual( rv, [(datetime(2017, 7, 13, 20, 40, 0), 1499967600)] ) query = ( "SELECT " "toDateTime(toInt32(toDateTime('{0}', 'Asia/Kamchatka'))), " "toInt32(toDateTime('{0}', 'Asia/Kamchatka'))" ).format('2017-07-14 05:40:00') rv = self.emit_cli(query, use_client_time_zone=0) self.assertEqual(rv, '2017-07-13 20:40:00\t1499967600\n') # use client timezone rv = self.client.execute( tpl, params, settings={'use_client_time_zone': True} ) self.assertEqual( rv, [(datetime(2017, 7, 14, 0, 40, 0), 1499967600)] ) query = ( "SELECT " "toDateTime(toInt32(toDateTime('{0}', 'Asia/Kamchatka'))), " "toInt32(toDateTime('{0}', 'Asia/Kamchatka'))" ).format('2017-07-14 05:40:00') rv = self.emit_cli(query, use_client_time_zone=1) self.assertEqual(rv, '2017-07-14 00:40:00\t1499967600\n') def test_string(self): params = {'x': 'test\t\n\x16', 'y': 'тест\t\n\x16'} self.assert_subst(self.double_tpl, params, "SELECT 'test\\t\\n\x16', 'тест\\t\\n\x16'") rv = self.client.execute(self.double_tpl, params) self.assertEqual(rv, [('test\t\n\x16', 'тест\t\n\x16')]) params = {'x': "'"} self.assert_subst(self.single_tpl, params, "SELECT '\\''") rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [("'", )]) params = {'x': "\\"} self.assert_subst(self.single_tpl, params, "SELECT '\\\\'") rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [("\\", )]) def test_array(self): params = {'x': [1, None, 2]} self.assert_subst(self.single_tpl, params, 'SELECT [1, NULL, 2]') rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [([1, None, 2], )]) params = {'x': [[1, 2, 3], [4, 5], [6, 7]]} self.assert_subst(self.single_tpl, params, 'SELECT [[1, 2, 3], [4, 5], [6, 7]]') rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [([[1, 2, 3], [4, 5], [6, 7]], )]) def test_tuple(self): params = {'x': (1, None, 2)} self.assert_subst('SELECT * FROM test WHERE a IN %(x)s', params, 'SELECT * FROM test WHERE a IN (1, NULL, 2)') with self.create_table('a Int32'): self.client.execute('INSERT INTO test (a) VALUES', [(1, )]) self.client.execute('INSERT INTO test (a) VALUES', [(2, )]) query = 'SELECT * FROM test WHERE a IN (1)' inserted = self.client.execute(query, columnar=True) self.assertEqual(inserted, [(1,)]) def test_enum(self): class A(IntEnum): hello = -1 world = 2 params = {'x': A.hello, 'y': A.world} self.assert_subst(self.double_tpl, params, 'SELECT -1, 2') rv = self.client.execute(self.double_tpl, params) self.assertEqual(rv, [(-1, 2)]) class A(Enum): hello = 'hello' world = 'world' params = {'x': A.hello, 'y': A.world} self.assert_subst(self.double_tpl, params, "SELECT 'hello', 'world'") rv = self.client.execute(self.double_tpl, params) self.assertEqual(rv, [('hello', 'world')]) def test_float(self): params = {'x': 1e-12, 'y': 123.45} self.assert_subst(self.double_tpl, params, 'SELECT 1e-12, 123.45') rv = self.client.execute(self.double_tpl, params) self.assertEqual(rv, [(params['x'], params['y'])]) def test_decimal(self): params = {'x': Decimal('1e-2'), 'y': Decimal('123.45')} self.assert_subst(self.double_tpl, params, 'SELECT 0.01, 123.45') rv = self.client.execute(self.double_tpl, params) self.assertEqual(rv, [(0.01, 123.45)]) def test_uuid(self): params = {'x': UUID('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d')} self.assert_subst(self.single_tpl, params, "SELECT 'c0fcbba9-0752-44ed-a5d6-4dfb4342b89d'") rv = self.client.execute(self.single_tpl, params) self.assertEqual(rv, [('c0fcbba9-0752-44ed-a5d6-4dfb4342b89d', )]) def test_substitute_object(self): params = object() with self.assertRaises(ValueError) as e: self.client.substitute_params(self.single_tpl, params, Mock()) self.assertEqual(e.exception.args[0], 'Parameters are expected in dict form') python-clickhouse-driver-0.2.3/tests/test_varint.py000066400000000000000000000007451420676740400225530ustar00rootroot00000000000000from io import BytesIO from unittest import TestCase from clickhouse_driver.varint import read_varint, write_varint class VarIntTestCase(TestCase): def test_check_not_negative(self): n = 0x9FFFFFFF buf = BytesIO() write_varint(n, buf) val = buf.getvalue() self.assertEqual(b'\xFF\xFF\xFF\xFF\t', val) buf = BytesIO(val) buf.read_one = lambda: ord(buf.read(1)) m = read_varint(buf) self.assertEqual(m, n) python-clickhouse-driver-0.2.3/tests/testcase.py000066400000000000000000000073471420676740400220310ustar00rootroot00000000000000import configparser from contextlib import contextmanager import subprocess from unittest import TestCase from clickhouse_driver.client import Client from tests import log from tests.util import skip_by_server_version file_config = configparser.ConfigParser() file_config.read(['setup.cfg']) log.configure(file_config.get('log', 'level')) class BaseTestCase(TestCase): required_server_version = None server_version = None clickhouse_client_binary = file_config.get('db', 'client') host = file_config.get('db', 'host') port = file_config.getint('db', 'port') database = file_config.get('db', 'database') user = file_config.get('db', 'user') password = file_config.get('db', 'password') client = None client_kwargs = None cli_client_kwargs = None @classmethod def emit_cli(cls, statement, database=None, encoding='utf-8', **kwargs): if database is None: database = cls.database args = [ cls.clickhouse_client_binary, '--database', database, '--host', cls.host, '--port', str(cls.port), '--query', str(statement) ] for key, value in kwargs.items(): args.extend(['--' + key, str(value)]) process = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) output = process.communicate() out, err = output if err: raise RuntimeError( 'Error during communication. {}'.format(err) ) return out.decode(encoding) def _create_client(self, **kwargs): client_kwargs = { 'port': self.port, 'database': self.database, 'user': self.user, 'password': self.password } client_kwargs.update(kwargs) return Client(self.host, **client_kwargs) def created_client(self, **kwargs): return self._create_client(**kwargs) @classmethod def setUpClass(cls): cls.emit_cli( 'DROP DATABASE IF EXISTS {}'.format(cls.database), 'default' ) cls.emit_cli('CREATE DATABASE {}'.format(cls.database), 'default') version_str = cls.emit_cli('SELECT version()').strip() cls.server_version = tuple(int(x) for x in version_str.split('.')) super(BaseTestCase, cls).setUpClass() def setUp(self): super(BaseTestCase, self).setUp() required = self.required_server_version if required and required > self.server_version: skip_by_server_version(self, self.required_server_version) if callable(self.client_kwargs): client_kwargs = self.client_kwargs(self.server_version) else: client_kwargs = self.client_kwargs client_kwargs = client_kwargs or {} self.client = self._create_client(**client_kwargs) def tearDown(self): self.client.disconnect() super(BaseTestCase, self).tearDown() @classmethod def tearDownClass(cls): cls.emit_cli('DROP DATABASE {}'.format(cls.database)) super(BaseTestCase, cls).tearDownClass() @contextmanager def create_table(self, columns, **kwargs): if self.cli_client_kwargs: if callable(self.cli_client_kwargs): cli_client_kwargs = self.cli_client_kwargs() if cli_client_kwargs: kwargs.update(cli_client_kwargs) else: kwargs.update(self.cli_client_kwargs) self.emit_cli( 'CREATE TABLE test ({}) ''ENGINE = Memory'.format(columns), **kwargs ) try: yield except Exception: raise finally: self.emit_cli('DROP TABLE test') python-clickhouse-driver-0.2.3/tests/util.py000066400000000000000000000043341420676740400211640ustar00rootroot00000000000000import os from contextlib import contextmanager from functools import wraps import logging from io import StringIO from time import tzset from unittest.mock import patch import tzlocal def skip_by_server_version(testcase, version_required): testcase.skipTest( 'Mininum revision required: {}'.format( '.'.join(str(x) for x in version_required) ) ) def require_server_version(*version_required): def check(f): @wraps(f) def wrapper(*args, **kwargs): self = args[0] self.client.connection.connect() current = self.client.connection.server_info.version_tuple() if version_required <= current: return f(*args, **kwargs) else: skip_by_server_version(self, version_required) return wrapper return check class LoggingCapturer(object): def __init__(self, logger_name, level): self.old_stdout_handlers = [] self.logger = logging.getLogger(logger_name) self.level = level super(LoggingCapturer, self).__init__() def __enter__(self): buffer = StringIO() self.new_handler = logging.StreamHandler(buffer) self.logger.addHandler(self.new_handler) self.old_logger_level = self.logger.level self.logger.setLevel(self.level) return buffer def __exit__(self, *exc_info): self.logger.setLevel(self.old_logger_level) self.logger.removeHandler(self.new_handler) capture_logging = LoggingCapturer def bust_tzlocal_cache(): try: tzlocal.unix._cache_tz = None tzlocal.unix._cache_tz_name = None except AttributeError: pass try: tzlocal.win32._cache_tz = None tzlocal.unix._cache_tz_name = None except AttributeError: pass @contextmanager def patch_env_tz(tz_name): bust_tzlocal_cache() # Although in many cases, changing the TZ environment variable may # affect the output of functions like localtime() without calling # tzset(), this behavior should not be relied on. # https://docs.python.org/3/library/time.html#time.tzset with patch.dict(os.environ, {'TZ': tz_name}): tzset() yield tzset() python-clickhouse-driver-0.2.3/testsrequire.py000066400000000000000000000010041420676740400215730ustar00rootroot00000000000000import os import sys USE_NUMPY = bool(int(os.getenv('USE_NUMPY', '0'))) tests_require = [ 'pytest', 'parameterized', 'freezegun', 'zstd', 'clickhouse-cityhash>=1.0.2.1' ] if sys.implementation.name == 'pypy': tests_require.append('lz4<=3.0.1') else: tests_require.append('lz4') if USE_NUMPY: tests_require.extend(['numpy', 'pandas']) try: from pip import main as pipmain except ImportError: from pip._internal import main as pipmain pipmain(['install'] + tests_require) python-clickhouse-driver-0.2.3/valgrind.supp000066400000000000000000000001571420676740400212110ustar00rootroot00000000000000{ # See https://bugs.python.org/issue42176 Memcheck:Cond fun:PyUnicode_Decode }