-
Notifications
You must be signed in to change notification settings - Fork 951
Expand file tree
/
Copy path__init__.py
More file actions
173 lines (151 loc) · 4.69 KB
/
__init__.py
File metadata and controls
173 lines (151 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2020 Confluent Inc.
#
# Licensed 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
from ._model import Node # noqa: F401
from ._model import (
ConsumerGroupState,
ConsumerGroupTopicPartitions,
ConsumerGroupType,
ElectionType,
IsolationLevel,
TopicCollection,
TopicPartitionInfo,
)
from .cimpl import (
OFFSET_BEGINNING,
OFFSET_END,
OFFSET_INVALID,
OFFSET_STORED,
TIMESTAMP_CREATE_TIME,
TIMESTAMP_LOG_APPEND_TIME,
TIMESTAMP_NOT_AVAILABLE,
Consumer,
Message,
Producer,
ShareConsumer,
TopicPartition,
Uuid,
consistent,
fnv1a,
libversion,
murmur2,
version,
)
from .deserializing_consumer import DeserializingConsumer
from .error import KafkaError, KafkaException
from .serializing_producer import SerializingProducer
__all__ = [
"admin",
"Consumer",
"ShareConsumer",
"aio",
"KafkaError",
"KafkaException",
"kafkatest",
"libversion",
"version",
"murmur2",
"consistent",
"fnv1a",
"Message",
"OFFSET_BEGINNING",
"OFFSET_END",
"OFFSET_INVALID",
"OFFSET_STORED",
"Producer",
"DeserializingConsumer",
"SerializingProducer",
"TIMESTAMP_CREATE_TIME",
"TIMESTAMP_LOG_APPEND_TIME",
"TIMESTAMP_NOT_AVAILABLE",
"TopicPartition",
"Node",
"ConsumerGroupTopicPartitions",
"ConsumerGroupState",
"ConsumerGroupType",
"Uuid",
"IsolationLevel",
"TopicCollection",
"TopicPartitionInfo",
"ElectionType",
]
__version__ = version()
class ThrottleEvent(object):
"""
ThrottleEvent contains details about a throttled request.
Set up a throttle callback by setting the ``throttle_cb`` configuration
property to a callable that takes a ThrottleEvent object as its only argument.
The callback will be triggered from poll(), consume() or flush() when a request
has been throttled by the broker.
This class is typically not user instantiated.
:ivar str broker_name: The hostname of the broker which throttled the request
:ivar int broker_id: The broker id
:ivar float throttle_time: The amount of time (in seconds) the broker throttled (delayed) the request
"""
def __init__(self, broker_name: str, broker_id: int, throttle_time: float) -> None:
self.broker_name = broker_name
self.broker_id = broker_id
self.throttle_time = throttle_time
def __str__(self) -> str:
return "{}/{} throttled for {} ms".format(self.broker_name, self.broker_id, int(self.throttle_time * 1000))
def _resolve_plugins(plugins: str) -> str:
"""Resolve embedded plugins from the wheel's library directory.
For internal module use only.
:param str plugins: The plugin.library.paths value
"""
from sys import platform
# Location of __init__.py and the embedded library directory
basedir = os.path.dirname(__file__)
if platform in ("win32", "cygwin"):
paths_sep = ";"
ext = ".dll"
libdir = basedir
elif platform in ("linux", "linux2"):
paths_sep = ":"
ext = ".so"
libdir = os.path.join(basedir, ".libs")
elif platform == "darwin":
paths_sep = ":"
ext = ".dylib"
libdir = os.path.join(basedir, ".dylibs")
else:
# Unknown platform, there are probably no embedded plugins.
return plugins
if not os.path.isdir(libdir):
# No embedded library directory, probably not a wheel installation.
return plugins
resolved = []
for plugin in plugins.split(paths_sep):
if "/" in plugin or "\\" in plugin:
# Path specified, leave unchanged
resolved.append(plugin)
continue
# See if the plugin can be found in the wheel's
# embedded library directory.
# The user might not have supplied a file extension, so try both.
good = None
for file in [plugin, plugin + ext]:
fpath = os.path.join(libdir, file)
if os.path.isfile(fpath):
good = fpath
break
if good is not None:
resolved.append(good)
else:
resolved.append(plugin)
return paths_sep.join(resolved)