mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
IMPALA-11624: Bump Impyla dependency to 0.18.0
IMPALA_THRIFT_PY_VERSION is also bumped to 0.16.0p3. As 0.16.0p3 Thrift does not contain Python related patches and Impyla 0.18.0 depends on Thrift 0.16.0, now we are consistently using Thrift 0.16.0 in all Python code. This also bumps the Thrift in the shell's ext-py directory to 0.16.0 (based on the Thrift 0.16.0 pypi tarball with the egg directory removed). Testing: - Ran a GVO job Change-Id: I7265558b0e07959c606cba73cd251c3edfcb3ed5 Reviewed-on: http://gerrit.cloudera.org:8080/18456 Reviewed-by: Michael Smith <michael.smith@cloudera.com> Reviewed-by: Wenzhe Zhou <wzhou@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com> Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
This commit is contained in:
@@ -193,7 +193,7 @@ else
|
||||
export IMPALA_THRIFT_JAVA_VERSION=${IMPALA_THRIFT_POM_VERSION}-p3
|
||||
fi
|
||||
unset IMPALA_THRIFT_JAVA_URL
|
||||
export IMPALA_THRIFT_PY_VERSION=0.11.0-p5
|
||||
export IMPALA_THRIFT_PY_VERSION=0.16.0-p3
|
||||
unset IMPALA_THRIFT_PY_URL
|
||||
|
||||
if [[ $OSTYPE == "darwin"* ]]; then
|
||||
|
||||
@@ -51,7 +51,7 @@ shell/ext-py/prettytable-0.7.2/*
|
||||
shell/ext-py/sasl-0.3.1/*
|
||||
shell/ext-py/six-1.14.0/*
|
||||
shell/ext-py/sqlparse-0.3.1/*
|
||||
shell/ext-py/thrift-0.14.2/*
|
||||
shell/ext-py/thrift-0.16.0/*
|
||||
shell/ext-py/thrift_sasl-0.4.3/*
|
||||
www/d3.v3.min.js
|
||||
www/jquery/jquery-3.5.1.min.js
|
||||
|
||||
@@ -45,7 +45,7 @@ hdfs == 2.0.2
|
||||
docopt == 0.6.2
|
||||
execnet == 1.4.0
|
||||
apipkg == 1.4
|
||||
impyla == 0.18a1
|
||||
impyla == 0.18.0
|
||||
bitarray == 2.3.0
|
||||
pure-sasl == 0.6.2
|
||||
# six == 1.14.0 (specified separately)
|
||||
|
||||
7
shell/.gitignore
vendored
7
shell/.gitignore
vendored
@@ -18,9 +18,9 @@ ext-py/six-1.14.0/six.egg-info/
|
||||
ext-py/sqlparse-0.3.1/dist/
|
||||
ext-py/sqlparse-0.3.1/build/
|
||||
ext-py/sqlparse-0.3.1/sqlparse.egg-info/
|
||||
ext-py/thrift-0.14.2/dist/
|
||||
ext-py/thrift-0.14.2/build/
|
||||
ext-py/thrift-0.14.2/thrift.egg-info/
|
||||
ext-py/thrift-0.16.0/dist/
|
||||
ext-py/thrift-0.16.0/build/
|
||||
ext-py/thrift-0.16.0/thrift.egg-info/
|
||||
ext-py/thrift_sasl-0.4.3/dist/
|
||||
ext-py/thrift_sasl-0.4.3/build/
|
||||
ext-py/thrift_sasl-0.4.3/thrift_sasl.egg-info/
|
||||
@@ -37,5 +37,6 @@ ext-py/sasl-0.2.1/
|
||||
ext-py/six-1.11.0/
|
||||
ext-py/sqlparse-0.1.7/
|
||||
ext-py/sqlparse-0.1.19/
|
||||
ext-py/thrift-0.14.2/
|
||||
ext-py/thrift_sasl-0.4.1/
|
||||
ext-py/thrift_sasl-0.4.2/
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
include_directories(${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
add_custom_target(python_build ALL
|
||||
COMMAND ${THRIFT_COMPILER} --gen py test/test_thrift_file/TestServer.thrift
|
||||
COMMAND ${PYTHON_EXECUTABLE} setup.py build
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "Building Python library"
|
||||
)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test(PythonTestSSLSocket ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_sslsocket.py)
|
||||
add_test(PythonThriftJson ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_json.py)
|
||||
add_test(PythonThriftTransport ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_transport.py)
|
||||
add_test(PythonThriftTBinaryProtocol ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_TBinaryProtocol.py)
|
||||
add_test(PythonThriftTZlibTransport ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_TZlibTransport.py)
|
||||
add_test(PythonThriftProtocol ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_TCompactProtocol.py)
|
||||
add_test(PythonThriftTNonblockingServer ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_TNonblockingServer.py)
|
||||
endif()
|
||||
@@ -1,79 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
AUTOMAKE_OPTIONS = serial-tests
|
||||
DESTDIR ?= /
|
||||
|
||||
if WITH_PY3
|
||||
py3-build:
|
||||
$(PYTHON3) setup.py build
|
||||
py3-test: py3-build
|
||||
$(PYTHON3) test/thrift_json.py
|
||||
$(PYTHON3) test/thrift_transport.py
|
||||
$(PYTHON3) test/test_sslsocket.py
|
||||
$(PYTHON3) test/thrift_TBinaryProtocol.py
|
||||
$(PYTHON3) test/thrift_TZlibTransport.py
|
||||
$(PYTHON3) test/thrift_TCompactProtocol.py
|
||||
$(PYTHON3) test/thrift_TNonblockingServer.py
|
||||
else
|
||||
py3-build:
|
||||
py3-test:
|
||||
endif
|
||||
|
||||
all-local: py3-build
|
||||
$(PYTHON) setup.py build
|
||||
${THRIFT} --gen py test/test_thrift_file/TestServer.thrift
|
||||
|
||||
# We're ignoring prefix here because site-packages seems to be
|
||||
# the equivalent of /usr/local/lib in Python land.
|
||||
# Old version (can't put inline because it's not portable).
|
||||
#$(PYTHON) setup.py install --prefix=$(prefix) --root=$(DESTDIR) $(PYTHON_SETUPUTIL_ARGS)
|
||||
install-exec-hook:
|
||||
$(PYTHON) setup.py install --root=$(DESTDIR) --prefix=$(PY_PREFIX) $(PYTHON_SETUPUTIL_ARGS)
|
||||
|
||||
check-local: all py3-test
|
||||
$(PYTHON) test/thrift_json.py
|
||||
$(PYTHON) test/thrift_transport.py
|
||||
$(PYTHON) test/test_sslsocket.py
|
||||
$(PYTHON) test/test_socket.py
|
||||
$(PYTHON) test/thrift_TBinaryProtocol.py
|
||||
$(PYTHON) test/thrift_TZlibTransport.py
|
||||
$(PYTHON) test/thrift_TCompactProtocol.py
|
||||
$(PYTHON) test/thrift_TNonblockingServer.py
|
||||
|
||||
|
||||
clean-local:
|
||||
$(RM) -r build
|
||||
$(RM) -r gen-py
|
||||
find . -type f \( -iname "*.pyc" \) | xargs rm -f
|
||||
find . -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
|
||||
|
||||
dist-hook:
|
||||
find $(distdir) -type f \( -iname "*.pyc" \) | xargs rm -f
|
||||
find $(distdir) -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
MANIFEST.in \
|
||||
coding_standards.md \
|
||||
compat \
|
||||
setup.py \
|
||||
setup.cfg \
|
||||
src \
|
||||
test \
|
||||
README.md
|
||||
@@ -1,7 +0,0 @@
|
||||
## Python Coding Standards
|
||||
|
||||
Please follow:
|
||||
* [Thrift General Coding Standards](/doc/coding_standards.md)
|
||||
* Code Style for Python Code [PEP8](http://legacy.python.org/dev/peps/pep-0008/)
|
||||
|
||||
When in doubt - check with <http://www.pylint.org/> or online with <http://pep8online.com>.
|
||||
@@ -1,247 +0,0 @@
|
||||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006-2008 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The name of the author may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
#define INTMAX_C INT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
||||
@@ -1,6 +0,0 @@
|
||||
[install]
|
||||
optimize = 1
|
||||
[metadata]
|
||||
description-file = README.md
|
||||
[flake8]
|
||||
max-line-length = 100
|
||||
@@ -1,30 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
|
||||
SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__))
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR)))
|
||||
|
||||
for libpath in glob.glob(os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib.*')):
|
||||
if libpath.endswith('-%d.%d' % (sys.version_info[0], sys.version_info[1])):
|
||||
sys.path.insert(0, libpath)
|
||||
break
|
||||
@@ -1,23 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
service TestServer{
|
||||
string add_and_get_msg(1:string msg)
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
import _import_local_thrift # noqa
|
||||
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
|
||||
from thrift.transport import TTransport
|
||||
|
||||
|
||||
def testNaked(type, data):
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
if type.capitalize() == 'Byte':
|
||||
protocol.writeByte(data)
|
||||
|
||||
if type.capitalize() == 'I16':
|
||||
protocol.writeI16(data)
|
||||
|
||||
if type.capitalize() == 'I32':
|
||||
protocol.writeI32(data)
|
||||
|
||||
if type.capitalize() == 'I64':
|
||||
protocol.writeI64(data)
|
||||
|
||||
if type.capitalize() == 'String':
|
||||
protocol.writeString(data)
|
||||
|
||||
if type.capitalize() == 'Double':
|
||||
protocol.writeDouble(data)
|
||||
|
||||
if type.capitalize() == 'Binary':
|
||||
protocol.writeBinary(data)
|
||||
|
||||
if type.capitalize() == 'Bool':
|
||||
protocol.writeBool(data)
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
if type.capitalize() == 'Byte':
|
||||
return protocol.readByte()
|
||||
|
||||
if type.capitalize() == 'I16':
|
||||
return protocol.readI16()
|
||||
|
||||
if type.capitalize() == 'I32':
|
||||
return protocol.readI32()
|
||||
|
||||
if type.capitalize() == 'I64':
|
||||
return protocol.readI64()
|
||||
|
||||
if type.capitalize() == 'String':
|
||||
return protocol.readString()
|
||||
|
||||
if type.capitalize() == 'Double':
|
||||
return protocol.readDouble()
|
||||
|
||||
if type.capitalize() == 'Binary':
|
||||
return protocol.readBinary()
|
||||
|
||||
if type.capitalize() == 'Bool':
|
||||
return protocol.readBool()
|
||||
|
||||
|
||||
def testField(type, data):
|
||||
TType = {"Bool": 2, "Byte": 3, "Binary": 5, "I16": 6, "I32": 8, "I64": 10, "Double": 11, "String": 12}
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
protocol.writeStructBegin('struct')
|
||||
protocol.writeFieldBegin("field", TType[type.capitalize()], 10)
|
||||
if type.capitalize() == 'Byte':
|
||||
protocol.writeByte(data)
|
||||
|
||||
if type.capitalize() == 'I16':
|
||||
protocol.writeI16(data)
|
||||
|
||||
if type.capitalize() == 'I32':
|
||||
protocol.writeI32(data)
|
||||
|
||||
if type.capitalize() == 'I64':
|
||||
protocol.writeI64(data)
|
||||
|
||||
if type.capitalize() == 'String':
|
||||
protocol.writeString(data)
|
||||
|
||||
if type.capitalize() == 'Double':
|
||||
protocol.writeDouble(data)
|
||||
|
||||
if type.capitalize() == 'Binary':
|
||||
protocol.writeBinary(data)
|
||||
|
||||
if type.capitalize() == 'Bool':
|
||||
protocol.writeBool(data)
|
||||
|
||||
protocol.writeFieldEnd()
|
||||
protocol.writeStructEnd()
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
protocol.readStructBegin()
|
||||
protocol.readFieldBegin()
|
||||
if type.capitalize() == 'Byte':
|
||||
return protocol.readByte()
|
||||
|
||||
if type.capitalize() == 'I16':
|
||||
return protocol.readI16()
|
||||
|
||||
if type.capitalize() == 'I32':
|
||||
return protocol.readI32()
|
||||
|
||||
if type.capitalize() == 'I64':
|
||||
return protocol.readI64()
|
||||
|
||||
if type.capitalize() == 'String':
|
||||
return protocol.readString()
|
||||
|
||||
if type.capitalize() == 'Double':
|
||||
return protocol.readDouble()
|
||||
|
||||
if type.capitalize() == 'Binary':
|
||||
return protocol.readBinary()
|
||||
|
||||
if type.capitalize() == 'Bool':
|
||||
return protocol.readBool()
|
||||
|
||||
protocol.readFieldEnd()
|
||||
protocol.readStructEnd()
|
||||
|
||||
|
||||
def testMessage(data):
|
||||
message = {}
|
||||
message['name'] = data[0]
|
||||
message['type'] = data[1]
|
||||
message['seqid'] = data[2]
|
||||
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
protocol.writeMessageBegin(message['name'], message['type'], message['seqid'])
|
||||
protocol.writeMessageEnd()
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TBinaryProtocol(transport)
|
||||
result = protocol.readMessageBegin()
|
||||
protocol.readMessageEnd()
|
||||
return result
|
||||
|
||||
|
||||
class TestTBinaryProtocol(unittest.TestCase):
|
||||
|
||||
def test_TBinaryProtocol_write_read(self):
|
||||
try:
|
||||
testNaked('Byte', 123)
|
||||
for i in range(0, 128):
|
||||
self.assertEqual(i, testField('Byte', i))
|
||||
self.assertEqual(-i, testField('Byte', -i))
|
||||
|
||||
self.assertEqual(0, testNaked("I16", 0))
|
||||
self.assertEqual(1, testNaked("I16", 1))
|
||||
self.assertEqual(15000, testNaked("I16", 15000))
|
||||
self.assertEqual(0x7fff, testNaked("I16", 0x7fff))
|
||||
self.assertEqual(-1, testNaked("I16", -1))
|
||||
self.assertEqual(-15000, testNaked("I16", -15000))
|
||||
self.assertEqual(-0x7fff, testNaked("I16", -0x7fff))
|
||||
self.assertEqual(32767, testNaked("I16", 32767))
|
||||
self.assertEqual(-32768, testNaked("I16", -32768))
|
||||
|
||||
self.assertEqual(0, testField("I16", 0))
|
||||
self.assertEqual(1, testField("I16", 1))
|
||||
self.assertEqual(7, testField("I16", 7))
|
||||
self.assertEqual(150, testField("I16", 150))
|
||||
self.assertEqual(15000, testField("I16", 15000))
|
||||
self.assertEqual(0x7fff, testField("I16", 0x7fff))
|
||||
self.assertEqual(-1, testField("I16", -1))
|
||||
self.assertEqual(-7, testField("I16", -7))
|
||||
self.assertEqual(-150, testField("I16", -150))
|
||||
self.assertEqual(-15000, testField("I16", -15000))
|
||||
self.assertEqual(-0xfff, testField("I16", -0xfff))
|
||||
|
||||
self.assertEqual(0, testNaked("I32", 0))
|
||||
self.assertEqual(1, testNaked("I32", 1))
|
||||
self.assertEqual(15000, testNaked("I32", 15000))
|
||||
self.assertEqual(0xffff, testNaked("I32", 0xffff))
|
||||
self.assertEqual(-1, testNaked("I32", -1))
|
||||
self.assertEqual(-15000, testNaked("I32", -15000))
|
||||
self.assertEqual(-0xffff, testNaked("I32", -0xffff))
|
||||
self.assertEqual(2147483647, testNaked("I32", 2147483647))
|
||||
self.assertEqual(-2147483647, testNaked("I32", -2147483647))
|
||||
|
||||
self.assertEqual(0, testField("I32", 0))
|
||||
self.assertEqual(1, testField("I32", 1))
|
||||
self.assertEqual(7, testField("I32", 7))
|
||||
self.assertEqual(150, testField("I32", 150))
|
||||
self.assertEqual(15000, testField("I32", 15000))
|
||||
self.assertEqual(31337, testField("I32", 31337))
|
||||
self.assertEqual(0xffff, testField("I32", 0xffff))
|
||||
self.assertEqual(0xffffff, testField("I32", 0xffffff))
|
||||
self.assertEqual(-1, testField("I32", -1))
|
||||
self.assertEqual(-7, testField("I32", -7))
|
||||
self.assertEqual(-150, testField("I32", -150))
|
||||
self.assertEqual(-15000, testField("I32", -15000))
|
||||
self.assertEqual(-0xffff, testField("I32", -0xffff))
|
||||
self.assertEqual(-0xffffff, testField("I32", -0xffffff))
|
||||
|
||||
self.assertEqual(9223372036854775807, testNaked("I64", 9223372036854775807))
|
||||
self.assertEqual(-9223372036854775807, testNaked("I64", -9223372036854775807))
|
||||
self.assertEqual(-0, testNaked("I64", 0))
|
||||
|
||||
self.assertEqual(True, testNaked("Bool", True))
|
||||
self.assertEqual(3.14159261, testNaked("Double", 3.14159261))
|
||||
self.assertEqual("hello thrift", testNaked("String", "hello thrift"))
|
||||
self.assertEqual(True, testField('Bool', True))
|
||||
self.assertEqual(3.1415926, testNaked("Double", 3.1415926))
|
||||
self.assertEqual("hello thrift", testNaked("String", "hello thrift"))
|
||||
|
||||
TMessageType = {"T_CALL": 1, "T_REPLY": 2, "T_EXCEPTION": 3, "T_ONEWAY": 4}
|
||||
test_data = [("short message name", TMessageType['T_CALL'], 0),
|
||||
("1", TMessageType['T_REPLY'], 12345),
|
||||
("loooooooooooooooooooooooooooooooooong", TMessageType['T_EXCEPTION'], 1 << 16),
|
||||
("one way push", TMessageType['T_ONEWAY'], 12),
|
||||
("Janky", TMessageType['T_CALL'], 0)]
|
||||
|
||||
for dt in test_data:
|
||||
result = testMessage(dt)
|
||||
self.assertEqual(result[0], dt[0])
|
||||
self.assertEqual(result[1], dt[1])
|
||||
self.assertEqual(result[2], dt[2])
|
||||
|
||||
except Exception as e:
|
||||
print("Assertion fail")
|
||||
raise e
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,288 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import _import_local_thrift # noqa
|
||||
from thrift.protocol import TCompactProtocol
|
||||
from thrift.transport import TTransport
|
||||
import unittest
|
||||
|
||||
CLEAR = 0
|
||||
FIELD_WRITE = 1
|
||||
VALUE_WRITE = 2
|
||||
CONTAINER_WRITE = 3
|
||||
BOOL_WRITE = 4
|
||||
FIELD_READ = 5
|
||||
CONTAINER_READ = 6
|
||||
VALUE_READ = 7
|
||||
BOOL_READ = 8
|
||||
|
||||
|
||||
def testNaked(type, data):
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
|
||||
if type.capitalize() == 'Byte':
|
||||
protocol.state = VALUE_WRITE
|
||||
protocol.writeByte(data)
|
||||
|
||||
elif type.capitalize() == 'I16':
|
||||
protocol.state = CONTAINER_WRITE
|
||||
protocol.writeI16(data)
|
||||
|
||||
elif type.capitalize() == 'I32':
|
||||
protocol.state = CONTAINER_WRITE
|
||||
protocol.writeI32(data)
|
||||
|
||||
elif type.capitalize() == 'I64':
|
||||
protocol.state = CONTAINER_WRITE
|
||||
protocol.writeI64(data)
|
||||
|
||||
elif type.capitalize() == 'String':
|
||||
protocol.state = CONTAINER_WRITE
|
||||
protocol.writeString(data)
|
||||
|
||||
elif type.capitalize() == 'Double':
|
||||
protocol.state = VALUE_WRITE
|
||||
protocol.writeDouble(data)
|
||||
|
||||
elif type.capitalize() == 'Binary':
|
||||
protocol.state = FIELD_WRITE
|
||||
protocol.writeBinary(data)
|
||||
|
||||
elif type.capitalize() == 'Bool':
|
||||
protocol.state = CONTAINER_WRITE
|
||||
protocol.writeBool(True)
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
if type.capitalize() == 'Byte':
|
||||
protocol.state = VALUE_READ
|
||||
return protocol.readByte()
|
||||
|
||||
elif type.capitalize() == 'I16':
|
||||
protocol.state = CONTAINER_READ
|
||||
return protocol.readI16()
|
||||
|
||||
elif type.capitalize() == 'I32':
|
||||
protocol.state = CONTAINER_READ
|
||||
return protocol.readI32()
|
||||
|
||||
elif type.capitalize() == 'I64':
|
||||
protocol.state = CONTAINER_READ
|
||||
return protocol.readI64()
|
||||
|
||||
elif type.capitalize() == 'String':
|
||||
protocol.state = VALUE_READ
|
||||
return protocol.readString()
|
||||
|
||||
elif type.capitalize() == 'Double':
|
||||
protocol.state = VALUE_READ
|
||||
return protocol.readDouble()
|
||||
|
||||
elif type.capitalize() == 'Binary':
|
||||
protocol.state = FIELD_READ
|
||||
return protocol.readBinary()
|
||||
|
||||
elif type.capitalize() == 'Bool':
|
||||
protocol.state = CONTAINER_READ
|
||||
return protocol.readBool()
|
||||
|
||||
|
||||
def testField(type, data):
|
||||
TType = {"Bool": 2, "Byte": 3, "Binary": 5, "I16": 6, "I32": 8, "I64": 10, "Double": 11, "String": 12}
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
protocol.writeStructBegin('struct')
|
||||
protocol.writeFieldBegin("field", TType[type.capitalize()], 10)
|
||||
if type.capitalize() == 'Byte':
|
||||
protocol.writeByte(data)
|
||||
|
||||
elif type.capitalize() == 'I16':
|
||||
protocol.writeI16(data)
|
||||
|
||||
elif type.capitalize() == 'I32':
|
||||
protocol.writeI32(data)
|
||||
|
||||
elif type.capitalize() == 'I64':
|
||||
protocol.writeI64(data)
|
||||
|
||||
elif type.capitalize() == 'String':
|
||||
protocol.writeString(data)
|
||||
|
||||
elif type.capitalize() == 'Double':
|
||||
protocol.writeDouble(data)
|
||||
|
||||
elif type.capitalize() == 'Binary':
|
||||
protocol.writeBinary(data)
|
||||
|
||||
elif type.capitalize() == 'Bool':
|
||||
protocol.writeBool(data)
|
||||
|
||||
protocol.writeFieldEnd()
|
||||
protocol.writeStructEnd()
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
protocol.readStructBegin()
|
||||
protocol.readFieldBegin()
|
||||
if type.capitalize() == 'Byte':
|
||||
return protocol.readByte()
|
||||
|
||||
elif type.capitalize() == 'I16':
|
||||
return protocol.readI16()
|
||||
|
||||
elif type.capitalize() == 'I32':
|
||||
return protocol.readI32()
|
||||
|
||||
elif type.capitalize() == 'I64':
|
||||
return protocol.readI32()
|
||||
|
||||
elif type.capitalize() == 'String':
|
||||
return protocol.readString()
|
||||
|
||||
elif type.capitalize() == 'Double':
|
||||
return protocol.readDouble()
|
||||
|
||||
elif type.capitalize() == 'Binary':
|
||||
return protocol.readBinary()
|
||||
|
||||
elif type.capitalize() == 'Bool':
|
||||
return protocol.readBool()
|
||||
|
||||
protocol.readFieldEnd()
|
||||
protocol.readStructEnd()
|
||||
|
||||
|
||||
def testMessage(data):
|
||||
message = {}
|
||||
message['name'] = data[0]
|
||||
message['type'] = data[1]
|
||||
message['seqid'] = data[2]
|
||||
|
||||
buf = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
protocol.writeMessageBegin(message['name'], message['type'], message['seqid'])
|
||||
protocol.writeMessageEnd()
|
||||
|
||||
transport.flush()
|
||||
data_r = buf.getvalue()
|
||||
|
||||
buf = TTransport.TMemoryBuffer(data_r)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
result = protocol.readMessageBegin()
|
||||
protocol.readMessageEnd()
|
||||
return result
|
||||
|
||||
|
||||
class TestTCompactProtocol(unittest.TestCase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
unittest.TestCase.__init__(self, *args, **kwargs)
|
||||
|
||||
def test_TCompactProtocol_write_read(self):
|
||||
try:
|
||||
testNaked('Byte', 123)
|
||||
for i in range(0, 128):
|
||||
self.assertEqual(i, testField('Byte', i))
|
||||
self.assertEqual(-i, testField('Byte', -i))
|
||||
|
||||
self.assertEqual(0, testNaked("I16", 0))
|
||||
self.assertEqual(1, testNaked("I16", 1))
|
||||
self.assertEqual(15000, testNaked("I16", 15000))
|
||||
self.assertEqual(0x7fff, testNaked('I16', 0x7fff))
|
||||
self.assertEqual(-1, testNaked('I16', -1))
|
||||
self.assertEqual(-15000, testNaked('I16', -15000))
|
||||
self.assertEqual(-0x7fff, testNaked('I16', -0x7fff))
|
||||
self.assertEqual(32767, testNaked('I16', 32767))
|
||||
|
||||
self.assertEqual(0, testField('I16', 0))
|
||||
self.assertEqual(1, testField('I16', 1))
|
||||
self.assertEqual(7, testField('I16', 7))
|
||||
self.assertEqual(150, testField('I16', 150))
|
||||
self.assertEqual(15000, testField('I16', 15000))
|
||||
self.assertEqual(0x7fff, testField('I16', 0x7fff))
|
||||
self.assertEqual(-1, testField('I16', -1))
|
||||
self.assertEqual(-7, testField('I16', -7))
|
||||
self.assertEqual(-150, testField('I16', -150))
|
||||
self.assertEqual(-15000, testField('I16', -15000))
|
||||
self.assertEqual(-0xfff, testField('I16', -0xfff))
|
||||
|
||||
self.assertEqual(0, testNaked('I32', 0))
|
||||
self.assertEqual(1, testNaked('I32', 1))
|
||||
self.assertEqual(15000, testNaked('I32', 15000))
|
||||
self.assertEqual(0xfff, testNaked('I32', 0xfff))
|
||||
self.assertEqual(-1, testNaked('I32', -1))
|
||||
self.assertEqual(-15000, testNaked('I32', -15000))
|
||||
self.assertEqual(-0xfff, testNaked('I32', -0xfff))
|
||||
self.assertEqual(2147483647, testNaked('I32', 2147483647))
|
||||
self.assertEqual(-2147483647, testNaked('I32', -2147483647))
|
||||
|
||||
self.assertEqual(0, testField('I32', 0))
|
||||
self.assertEqual(1, testField('I32', 1))
|
||||
self.assertEqual(7, testField('I32', 7))
|
||||
self.assertEqual(150, testField('I32', 150))
|
||||
self.assertEqual(15000, testField('I32', 15000))
|
||||
self.assertEqual(31337, testField('I32', 31337))
|
||||
self.assertEqual(0xffff, testField('I32', 0xffff))
|
||||
self.assertEqual(0xffffff, testField('I32', 0xffffff))
|
||||
self.assertEqual(-1, testField('I32', -1))
|
||||
self.assertEqual(-7, testField('I32', -7))
|
||||
self.assertEqual(-150, testField('I32', -150))
|
||||
self.assertEqual(-15000, testField('I32', -15000))
|
||||
self.assertEqual(-0xffff, testField('I32', -0xffff))
|
||||
self.assertEqual(-0xffffff, testField('I32', -0xffffff))
|
||||
|
||||
self.assertEqual(9223372036854775807, testNaked("I64", 9223372036854775807))
|
||||
self.assertEqual(-9223372036854775807, testNaked('I64', -9223372036854775807))
|
||||
self.assertEqual(-0, testNaked('I64', 0))
|
||||
self.assertEqual(True, testNaked('Bool', True))
|
||||
self.assertEqual(3.14159261, testNaked('Double', 3.14159261))
|
||||
self.assertEqual("hello thrift", testNaked('String', "hello thrift"))
|
||||
self.assertEqual(True, testField('Bool', True))
|
||||
self.assertEqual(3.14159261, testField('Double', 3.14159261))
|
||||
self.assertEqual("hello thrift", testField('String', "hello thrift"))
|
||||
TMessage = {"T_CALL": 1, "T_REPLY": 2, "T_EXCEPTION": 3, "T_ONEWAY": 4}
|
||||
test_data = [("short message name", TMessage["T_CALL"], 0),
|
||||
("1", TMessage["T_REPLY"], 12345),
|
||||
("loooooooooooooooooooong", TMessage["T_EXCEPTION"], 1 << 16),
|
||||
("one way push", TMessage["T_ONEWAY"], 12),
|
||||
("JANKY", TMessage["T_CALL"], 0)]
|
||||
for dt in test_data:
|
||||
result = testMessage(dt)
|
||||
self.assertEqual(result[0], dt[0])
|
||||
self.assertEqual(result[1], dt[1])
|
||||
self.assertEqual(result[2], dt[2])
|
||||
except Exception as e:
|
||||
print("Assertion fail")
|
||||
raise e
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,101 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import unittest
|
||||
import time
|
||||
|
||||
gen_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "gen-py")
|
||||
sys.path.append(gen_path)
|
||||
import _import_local_thrift # noqa
|
||||
from TestServer import TestServer
|
||||
from thrift.transport import TSocket, TTransport
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
from thrift.server import TNonblockingServer
|
||||
|
||||
|
||||
class Handler:
|
||||
|
||||
def add_and_get_msg(self, msg):
|
||||
return msg
|
||||
|
||||
|
||||
class Server:
|
||||
|
||||
def __init__(self):
|
||||
handler = Handler()
|
||||
processor = TestServer.Processor(handler)
|
||||
transport = TSocket.TServerSocket("127.0.0.1", 30030)
|
||||
self.server = TNonblockingServer.TNonblockingServer(processor, transport)
|
||||
|
||||
def start_server(self):
|
||||
print("-------start server ------\n")
|
||||
self.server.serve()
|
||||
print("------stop server -----\n")
|
||||
|
||||
def close_server(self):
|
||||
self.server.stop()
|
||||
self.server.close()
|
||||
|
||||
|
||||
class Client:
|
||||
|
||||
def start_client(self):
|
||||
transport = TSocket.TSocket("127.0.0.1", 30030)
|
||||
trans = TTransport.TFramedTransport(transport)
|
||||
protocol = TBinaryProtocol.TBinaryProtocol(trans)
|
||||
client = TestServer.Client(protocol)
|
||||
trans.open()
|
||||
self.msg = client.add_and_get_msg("hello thrift")
|
||||
|
||||
def get_message(self):
|
||||
try:
|
||||
msg = self.msg
|
||||
return msg
|
||||
except AttributeError as e:
|
||||
raise e
|
||||
print("self.msg not exit\n")
|
||||
|
||||
|
||||
class TestNonblockingServer(unittest.TestCase):
|
||||
|
||||
def test_normalconnection(self):
|
||||
serve = Server()
|
||||
client = Client()
|
||||
|
||||
serve_thread = threading.Thread(target=serve.start_server)
|
||||
client_thread = threading.Thread(target=client.start_client)
|
||||
serve_thread.start()
|
||||
time.sleep(10)
|
||||
client_thread.start()
|
||||
client_thread.join(0.5)
|
||||
try:
|
||||
msg = client.get_message()
|
||||
self.assertEqual("hello thrift", msg)
|
||||
except AssertionError as e:
|
||||
raise e
|
||||
print("assert failure")
|
||||
finally:
|
||||
serve.close_server()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,99 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import unittest
|
||||
import random
|
||||
import string
|
||||
|
||||
import _import_local_thrift # noqa
|
||||
from thrift.transport import TTransport
|
||||
from thrift.transport import TZlibTransport
|
||||
|
||||
|
||||
def generate_random_buff():
|
||||
data = []
|
||||
buf_len = 1024 * 32
|
||||
index = 0
|
||||
|
||||
while index < buf_len:
|
||||
run_len = random.randint(1, 64)
|
||||
if index + run_len > buf_len:
|
||||
run_len = buf_len - index
|
||||
for i in range(run_len):
|
||||
data.extend(random.sample(string.printable, 1))
|
||||
index += 1
|
||||
|
||||
new_data = ''.join(data)
|
||||
return new_data
|
||||
|
||||
|
||||
class TestTZlibTransport(unittest.TestCase):
|
||||
|
||||
def test_write_then_read(self):
|
||||
buff = TTransport.TMemoryBuffer()
|
||||
trans = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
zlib_trans = TZlibTransport.TZlibTransport(trans)
|
||||
data_w = generate_random_buff()
|
||||
zlib_trans.write(data_w.encode('utf-8'))
|
||||
zlib_trans.flush()
|
||||
|
||||
value = buff.getvalue()
|
||||
zlib_trans.close()
|
||||
|
||||
buff = TTransport.TMemoryBuffer(value)
|
||||
trans = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
zlib_trans = TZlibTransport.TZlibTransport(trans)
|
||||
data_r = zlib_trans.read(len(data_w))
|
||||
zlib_trans.close()
|
||||
|
||||
try:
|
||||
self.assertEqual(data_w, data_r.decode('utf-8'))
|
||||
self.assertEqual(len(data_w), len(data_r.decode('utf-8')))
|
||||
except AssertionError:
|
||||
raise
|
||||
|
||||
def test_after_flushd_write_then_read(self):
|
||||
buff = TTransport.TMemoryBuffer()
|
||||
trans = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
zlib_trans = TZlibTransport.TZlibTransport(trans)
|
||||
data_w_1 = "hello thrift !@#" * 50
|
||||
zlib_trans.write(data_w_1.encode('utf-8'))
|
||||
zlib_trans.flush()
|
||||
data_w_2 = "{'name': 'thrift', 1: ['abcd' , 233, ('a','c')]}" * 20
|
||||
zlib_trans.write(data_w_2.encode('utf-8'))
|
||||
zlib_trans.flush()
|
||||
|
||||
value = buff.getvalue()
|
||||
zlib_trans.close()
|
||||
|
||||
buff = TTransport.TMemoryBuffer(value)
|
||||
trans = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
zlib_trans = TZlibTransport.TZlibTransport(trans)
|
||||
data_r = zlib_trans.read(len(data_w_1) + len(data_w_2))
|
||||
zlib_trans.close()
|
||||
|
||||
try:
|
||||
self.assertEqual(data_w_1 + data_w_2, data_r.decode('utf-8'))
|
||||
self.assertEqual(len(data_w_1) + len(data_w_2), len(data_r.decode('utf-8')))
|
||||
except AssertionError:
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,116 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import _import_local_thrift # noqa
|
||||
from thrift.protocol.TJSONProtocol import TJSONProtocol
|
||||
from thrift.transport import TTransport
|
||||
|
||||
#
|
||||
# In order to run the test under Windows. We need to create symbolic link
|
||||
# name 'thrift' to '../src' folder by using:
|
||||
#
|
||||
# mklink /D thrift ..\src
|
||||
#
|
||||
|
||||
|
||||
class TestJSONString(unittest.TestCase):
|
||||
|
||||
def test_escaped_unicode_string(self):
|
||||
unicode_json = b'"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab\\udb40\\udc70 unicode"'
|
||||
unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB\U000E0070 unicode'
|
||||
|
||||
buf = TTransport.TMemoryBuffer(unicode_json)
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
|
||||
protocol = TJSONProtocol(transport)
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
unicode_text = unicode_text.encode('utf8')
|
||||
self.assertEqual(protocol.readString(), unicode_text)
|
||||
|
||||
def test_TJSONProtocol_write(self):
|
||||
write_data = '{"software":"thrift","1":[23,1.2010000000000001,32767,2147483647,9223372036854775807],"base64":"aGVsbG8gdGhyaWZ0","bool":0}'
|
||||
|
||||
buff = TTransport.TMemoryBuffer()
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
protocol = TJSONProtocol(transport)
|
||||
protocol.writeJSONObjectStart()
|
||||
protocol.writeJSONString("software")
|
||||
protocol.writeJSONString("thrift")
|
||||
protocol.writeJSONString("1")
|
||||
protocol.writeJSONArrayStart()
|
||||
protocol.writeJSONNumber(23)
|
||||
protocol.writeDouble(1.201)
|
||||
protocol.writeI16(32767)
|
||||
protocol.writeI32(2147483647)
|
||||
protocol.writeI64(9223372036854775807)
|
||||
protocol.writeJSONArrayEnd()
|
||||
protocol.writeJSONString("base64")
|
||||
protocol.writeJSONBase64("hello thrift".encode('utf-8'))
|
||||
protocol.writeJSONString("bool")
|
||||
protocol.writeBool(0)
|
||||
protocol.writeJSONObjectEnd()
|
||||
|
||||
transport.flush()
|
||||
value = buff.getvalue()
|
||||
|
||||
self.assertEqual(write_data, value.decode('utf-8'))
|
||||
|
||||
def test_TJSONProtol_read(self):
|
||||
expected = "{'software':'thrift','1':[23,1.2010000000000001,32767,2147483647,9223372036854775807],'base64':'hello thrift','bool':False}"
|
||||
read_data = '{"software":"thrift","1":[23,1.2010000000000001,32767,2147483647,9223372036854775807],"base64":"aGVsbG8gdGhyaWZ0","bool":0}'
|
||||
|
||||
buff = TTransport.TMemoryBuffer(read_data.encode('utf-8'))
|
||||
transport = TTransport.TBufferedTransportFactory().getTransport(buff)
|
||||
protocol = TJSONProtocol(transport)
|
||||
protocol.readJSONObjectStart()
|
||||
u_1 = protocol.readString()
|
||||
u_2 = protocol.readString()
|
||||
u_3 = protocol.readString()
|
||||
protocol.readJSONArrayStart()
|
||||
u_4 = protocol.readNumber()
|
||||
u_5 = protocol.readDouble()
|
||||
u_6 = protocol.readI16()
|
||||
u_7 = protocol.readI32()
|
||||
u_8 = protocol.readI64()
|
||||
protocol.readJSONArrayEnd()
|
||||
u_9 = protocol.readString()
|
||||
u_10 = protocol.readJSONBase64()
|
||||
u_11 = protocol.readString()
|
||||
u_12 = protocol.readBool()
|
||||
protocol.writeJSONObjectEnd()
|
||||
|
||||
result_read = {}
|
||||
result_read[u_1] = u_2
|
||||
result_read[u_3] = []
|
||||
result_read[u_3].append(u_4)
|
||||
result_read[u_3].append(u_5)
|
||||
result_read[u_3].append(u_6)
|
||||
result_read[u_3].append(u_7)
|
||||
result_read[u_3].append(u_8)
|
||||
result_read[u_9] = u_10.decode('utf-8')
|
||||
result_read[u_11] = u_12
|
||||
|
||||
self.assertEqual(eval(expected), result_read)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,70 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
import _import_local_thrift # noqa
|
||||
from thrift.transport import TTransport
|
||||
|
||||
|
||||
class TestTFileObjectTransport(unittest.TestCase):
|
||||
|
||||
def test_TFileObjectTransport(self):
|
||||
test_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
datatxt_path = os.path.join(test_dir, 'data.txt')
|
||||
buffer = '{"soft":"thrift","version":0.13,"1":true}'
|
||||
with open(datatxt_path, "w+") as f:
|
||||
buf = TTransport.TFileObjectTransport(f)
|
||||
buf.write(buffer)
|
||||
buf.flush()
|
||||
buf.close()
|
||||
|
||||
with open(datatxt_path, "rb") as f:
|
||||
buf = TTransport.TFileObjectTransport(f)
|
||||
value = buf.read(len(buffer)).decode('utf-8')
|
||||
self.assertEqual(buffer, value)
|
||||
buf.close()
|
||||
os.remove(datatxt_path)
|
||||
|
||||
|
||||
class TestMemoryBuffer(unittest.TestCase):
|
||||
|
||||
def test_memorybuffer_write(self):
|
||||
data = '{"1":[1,"hello"],"a":{"A":"abc"},"bool":true,"num":12345}'
|
||||
|
||||
buffer_w = TTransport.TMemoryBuffer()
|
||||
buffer_w.write(data.encode('utf-8'))
|
||||
value = buffer_w.getvalue()
|
||||
self.assertEqual(value.decode('utf-8'), data)
|
||||
buffer_w.close()
|
||||
|
||||
def test_memorybuffer_read(self):
|
||||
data = '{"1":[1, "hello"],"a":{"A":"abc"},"bool":true,"num":12345}'
|
||||
|
||||
buffer_r = TTransport.TMemoryBuffer(data.encode('utf-8'))
|
||||
value_r = buffer_r.read(len(data))
|
||||
value = buffer_r.getvalue()
|
||||
self.assertEqual(value.decode('utf-8'), data)
|
||||
self.assertEqual(value_r.decode('utf-8'), data)
|
||||
buffer_r.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
13
shell/ext-py/thrift-0.16.0/setup.cfg
Normal file
13
shell/ext-py/thrift-0.16.0/setup.cfg
Normal file
@@ -0,0 +1,13 @@
|
||||
[install]
|
||||
optimize = 1
|
||||
|
||||
[metadata]
|
||||
description_file = README.md
|
||||
|
||||
[flake8]
|
||||
max-line-length = 100
|
||||
|
||||
[egg_info]
|
||||
tag_build =
|
||||
tag_date = 0
|
||||
|
||||
@@ -62,6 +62,20 @@ class ve_build_ext(build_ext):
|
||||
raise BuildFailed()
|
||||
|
||||
|
||||
def read_file(path):
|
||||
"""
|
||||
Return the contents of a file
|
||||
|
||||
Arguments:
|
||||
- path: path to the file
|
||||
|
||||
Returns:
|
||||
- contents of the file
|
||||
"""
|
||||
with open(path, "r") as desc_file:
|
||||
return desc_file.read().rstrip()
|
||||
|
||||
|
||||
def run_setup(with_binary):
|
||||
if with_binary:
|
||||
extensions = dict(
|
||||
@@ -91,8 +105,10 @@ def run_setup(with_binary):
|
||||
twisted_deps = ['twisted']
|
||||
|
||||
setup(name='thrift',
|
||||
version='0.14.2',
|
||||
version='0.16.0',
|
||||
description='Python bindings for the Apache Thrift RPC system',
|
||||
long_description=read_file("README.md"),
|
||||
long_description_content_type="text/markdown",
|
||||
author='Apache Thrift Developers',
|
||||
author_email='dev@thrift.apache.org',
|
||||
url='http://thrift.apache.org',
|
||||
@@ -17,6 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "ext/binary.h"
|
||||
namespace apache {
|
||||
namespace thrift {
|
||||
@@ -17,6 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "ext/compact.h"
|
||||
|
||||
namespace apache {
|
||||
@@ -42,6 +42,11 @@ class TProcessPoolServer(TServer):
|
||||
self.stopCondition = Condition()
|
||||
self.postForkCallback = None
|
||||
|
||||
def __getstate__(self):
|
||||
state = self.__dict__.copy()
|
||||
state['workers'] = None
|
||||
return state
|
||||
|
||||
def setPostForkCallback(self, callback):
|
||||
if not callable(callback):
|
||||
raise TypeError("This is not a callback!")
|
||||
@@ -398,6 +398,9 @@ class TSaslClientTransport(TTransportBase, CReadableTransport):
|
||||
"Bad SASL negotiation status: %d (%s)"
|
||||
% (status, challenge))
|
||||
|
||||
def isOpen(self):
|
||||
return self.transport.isOpen()
|
||||
|
||||
def send_sasl_msg(self, status, body):
|
||||
header = pack(">BI", status, len(body))
|
||||
self.transport.write(header + body)
|
||||
@@ -6,5 +6,5 @@ sasl==0.3.1
|
||||
setuptools>=36.8.0
|
||||
six==1.14.0
|
||||
sqlparse==0.3.1
|
||||
thrift==0.14.2
|
||||
thrift==0.16.0
|
||||
thrift_sasl==0.4.3
|
||||
|
||||
Reference in New Issue
Block a user