Skip to content

Commit 499c99c

Browse files
l0lawrenceallenkim0129
authored andcommitted
[EH/SB] ran black (Azure#38210)
* ran black * fix pylint * black sb * pylint * spacing
1 parent 2d4b381 commit 499c99c

File tree

369 files changed

+11862
-14123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+11862
-14123
lines changed

sdk/eventhub/azure-eventhub/azure/eventhub/_buffered_producer/_buffered_producer.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
*,
3535
amqp_transport: AmqpTransport,
3636
max_buffer_length: int,
37-
max_wait_time: float = 1
37+
max_wait_time: float = 1,
3838
):
3939
self._buffered_queue: queue.Queue = queue.Queue()
4040
self._max_buffer_len = max_buffer_length
@@ -59,9 +59,7 @@ def start(self):
5959
self._running = True
6060
if self._max_wait_time:
6161
self._last_send_time = time.time()
62-
self._check_max_wait_time_future = self._executor.submit(
63-
self.check_max_wait_time_worker
64-
)
62+
self._check_max_wait_time_future = self._executor.submit(self.check_max_wait_time_worker)
6563

6664
def stop(self, flush=True, timeout_time=None, raise_error=False):
6765
self._running = False
@@ -80,9 +78,7 @@ def stop(self, flush=True, timeout_time=None, raise_error=False):
8078
try:
8179
self._check_max_wait_time_future.result(remain_timeout)
8280
except Exception as exc: # pylint: disable=broad-except
83-
_LOGGER.warning(
84-
"Partition %r stopped with error %r", self.partition_id, exc
85-
)
81+
_LOGGER.warning("Partition %r stopped with error %r", self.partition_id, exc)
8682
self._producer.close()
8783

8884
def put_events(self, events, timeout_time=None):
@@ -102,9 +98,7 @@ def put_events(self, events, timeout_time=None):
10298
# flush the buffer
10399
self.flush(timeout_time=timeout_time)
104100
if timeout_time and time.time() > timeout_time:
105-
raise OperationTimeoutError(
106-
"Failed to enqueue events into buffer due to timeout."
107-
)
101+
raise OperationTimeoutError("Failed to enqueue events into buffer due to timeout.")
108102
with self._lock:
109103
try:
110104
# add single event into current batch
@@ -157,9 +151,7 @@ def flush(self, timeout_time=None, raise_error=True):
157151
_LOGGER.info("Partition %r is sending.", self.partition_id)
158152
self._producer.send(
159153
batch,
160-
timeout=timeout_time - time.time()
161-
if timeout_time
162-
else None,
154+
timeout=timeout_time - time.time() if timeout_time else None,
163155
)
164156
_LOGGER.info(
165157
"Partition %r sending %r events succeeded.",
@@ -184,14 +176,10 @@ def flush(self, timeout_time=None, raise_error=True):
184176
finally:
185177
self._cur_buffered_len -= len(batch)
186178
else:
187-
_LOGGER.info(
188-
"Partition %r fails to flush due to timeout.", self.partition_id
189-
)
179+
_LOGGER.info("Partition %r fails to flush due to timeout.", self.partition_id)
190180
if raise_error:
191181
raise OperationTimeoutError(
192-
"Failed to flush {!r} within {}".format(
193-
self.partition_id, timeout_time
194-
)
182+
"Failed to flush {!r} within {}".format(self.partition_id, timeout_time)
195183
)
196184
break
197185
# after finishing flushing, reset cur batch and put it into the buffer
@@ -202,9 +190,7 @@ def check_max_wait_time_worker(self):
202190
while self._running:
203191
if self._cur_buffered_len > 0:
204192
now_time = time.time()
205-
_LOGGER.info(
206-
"Partition %r worker is checking max_wait_time.", self.partition_id
207-
)
193+
_LOGGER.info("Partition %r worker is checking max_wait_time.", self.partition_id)
208194
# flush the partition if the producer is running beyond the waiting time
209195
# or the buffer is at max capacity
210196
if (now_time - self._last_send_time > self._max_wait_time) or (

sdk/eventhub/azure-eventhub/azure/eventhub/_buffered_producer/_buffered_producer_dispatcher.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
amqp_transport: AmqpTransport,
3535
max_buffer_length: int = 1500,
3636
max_wait_time: float = 1,
37-
executor: Optional[Union[ThreadPoolExecutor, int]] = None
37+
executor: Optional[Union[ThreadPoolExecutor, int]] = None,
3838
):
3939
self._buffered_producers: Dict[str, BufferedProducer] = {}
4040
self._partition_ids: List[str] = partitions
@@ -62,20 +62,14 @@ def _get_partition_id(self, partition_id, partition_key):
6262
if partition_id:
6363
if partition_id not in self._partition_ids:
6464
raise ConnectError(
65-
"Invalid partition {} for the event hub {}".format(
66-
partition_id, self._eventhub_name
67-
)
65+
"Invalid partition {} for the event hub {}".format(partition_id, self._eventhub_name)
6866
)
6967
return partition_id
7068
if isinstance(partition_key, str):
71-
return self._partition_resolver.get_partition_id_by_partition_key(
72-
partition_key
73-
)
69+
return self._partition_resolver.get_partition_id_by_partition_key(partition_key)
7470
return self._partition_resolver.get_next_partition_id()
7571

76-
def enqueue_events(
77-
self, events, *, partition_id=None, partition_key=None, timeout_time=None
78-
):
72+
def enqueue_events(self, events, *, partition_id=None, partition_key=None, timeout_time=None):
7973
pid = self._get_partition_id(partition_id, partition_key)
8074
with self._lock:
8175
try:
@@ -90,7 +84,7 @@ def enqueue_events(
9084
executor=self._executor,
9185
max_wait_time=self._max_wait_time,
9286
max_buffer_length=self._max_buffer_length,
93-
amqp_transport = self._amqp_transport,
87+
amqp_transport=self._amqp_transport,
9488
)
9589
buffered_producer.start()
9690
self._buffered_producers[pid] = buffered_producer
@@ -105,9 +99,7 @@ def flush(self, timeout_time=None):
10599
futures.append(
106100
(
107101
pid,
108-
self._executor.submit(
109-
producer.flush, timeout_time=timeout_time
110-
),
102+
self._executor.submit(producer.flush, timeout_time=timeout_time),
111103
)
112104
)
113105

@@ -123,9 +115,7 @@ def flush(self, timeout_time=None):
123115
_LOGGER.info("Flushing all partitions succeeded")
124116
return
125117

126-
_LOGGER.warning(
127-
"Flushing all partitions partially failed with result %r.", exc_results
128-
)
118+
_LOGGER.warning("Flushing all partitions partially failed with result %r.", exc_results)
129119
raise EventDataSendError(
130120
message="Flushing all partitions partially failed, failed partitions are {!r}"
131121
" Exception details are {!r}".format(exc_results.keys(), exc_results)
@@ -166,9 +156,7 @@ def close(self, *, flush=True, timeout_time=None, raise_error=False):
166156
if raise_error:
167157
raise EventHubError(
168158
message="Stopping all partitions partially failed, failed partitions are {!r}"
169-
" Exception details are {!r}".format(
170-
exc_results.keys(), exc_results
171-
)
159+
" Exception details are {!r}".format(exc_results.keys(), exc_results)
172160
)
173161

174162
if not self._existing_executor:
@@ -182,6 +170,4 @@ def get_buffered_event_count(self, pid):
182170

183171
@property
184172
def total_buffered_event_count(self):
185-
return sum(
186-
(self.get_buffered_event_count(pid) for pid in self._buffered_producers)
187-
)
173+
return sum((self.get_buffered_event_count(pid) for pid in self._buffered_producers))

sdk/eventhub/azure-eventhub/azure/eventhub/_buffered_producer/_partition_resolver.py

Lines changed: 18 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -109,136 +109,46 @@ def compute_hash(data, init_val=0, init_val2=0):
109109

110110
p = 0 # string offset
111111
while lenpos > 12:
112-
a += (
113-
ord(data[p + 0])
114-
+ (ord(data[p + 1]) << 8)
115-
+ (ord(data[p + 2]) << 16)
116-
+ (ord(data[p + 3]) << 24)
117-
)
112+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
118113
a &= 0xFFFFFFFF
119-
b += (
120-
ord(data[p + 4])
121-
+ (ord(data[p + 5]) << 8)
122-
+ (ord(data[p + 6]) << 16)
123-
+ (ord(data[p + 7]) << 24)
124-
)
114+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
125115
b &= 0xFFFFFFFF
126-
c += (
127-
ord(data[p + 8])
128-
+ (ord(data[p + 9]) << 8)
129-
+ (ord(data[p + 10]) << 16)
130-
+ (ord(data[p + 11]) << 24)
131-
)
116+
c += ord(data[p + 8]) + (ord(data[p + 9]) << 8) + (ord(data[p + 10]) << 16) + (ord(data[p + 11]) << 24)
132117
c &= 0xFFFFFFFF
133118
a, b, c = mix(a, b, c)
134119
p += 12
135120
lenpos -= 12
136121

137122
if lenpos == 12:
138-
c += (
139-
ord(data[p + 8])
140-
+ (ord(data[p + 9]) << 8)
141-
+ (ord(data[p + 10]) << 16)
142-
+ (ord(data[p + 11]) << 24)
143-
)
144-
b += (
145-
ord(data[p + 4])
146-
+ (ord(data[p + 5]) << 8)
147-
+ (ord(data[p + 6]) << 16)
148-
+ (ord(data[p + 7]) << 24)
149-
)
150-
a += (
151-
ord(data[p + 0])
152-
+ (ord(data[p + 1]) << 8)
153-
+ (ord(data[p + 2]) << 16)
154-
+ (ord(data[p + 3]) << 24)
155-
)
123+
c += ord(data[p + 8]) + (ord(data[p + 9]) << 8) + (ord(data[p + 10]) << 16) + (ord(data[p + 11]) << 24)
124+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
125+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
156126
if lenpos == 11:
157127
c += ord(data[p + 8]) + (ord(data[p + 9]) << 8) + (ord(data[p + 10]) << 16)
158-
b += (
159-
ord(data[p + 4])
160-
+ (ord(data[p + 5]) << 8)
161-
+ (ord(data[p + 6]) << 16)
162-
+ (ord(data[p + 7]) << 24)
163-
)
164-
a += (
165-
ord(data[p + 0])
166-
+ (ord(data[p + 1]) << 8)
167-
+ (ord(data[p + 2]) << 16)
168-
+ (ord(data[p + 3]) << 24)
169-
)
128+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
129+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
170130
if lenpos == 10:
171131
c += ord(data[p + 8]) + (ord(data[p + 9]) << 8)
172-
b += (
173-
ord(data[p + 4])
174-
+ (ord(data[p + 5]) << 8)
175-
+ (ord(data[p + 6]) << 16)
176-
+ (ord(data[p + 7]) << 24)
177-
)
178-
a += (
179-
ord(data[p + 0])
180-
+ (ord(data[p + 1]) << 8)
181-
+ (ord(data[p + 2]) << 16)
182-
+ (ord(data[p + 3]) << 24)
183-
)
132+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
133+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
184134
if lenpos == 9:
185135
c += ord(data[p + 8])
186-
b += (
187-
ord(data[p + 4])
188-
+ (ord(data[p + 5]) << 8)
189-
+ (ord(data[p + 6]) << 16)
190-
+ (ord(data[p + 7]) << 24)
191-
)
192-
a += (
193-
ord(data[p + 0])
194-
+ (ord(data[p + 1]) << 8)
195-
+ (ord(data[p + 2]) << 16)
196-
+ (ord(data[p + 3]) << 24)
197-
)
136+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
137+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
198138
if lenpos == 8:
199-
b += (
200-
ord(data[p + 4])
201-
+ (ord(data[p + 5]) << 8)
202-
+ (ord(data[p + 6]) << 16)
203-
+ (ord(data[p + 7]) << 24)
204-
)
205-
a += (
206-
ord(data[p + 0])
207-
+ (ord(data[p + 1]) << 8)
208-
+ (ord(data[p + 2]) << 16)
209-
+ (ord(data[p + 3]) << 24)
210-
)
139+
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16) + (ord(data[p + 7]) << 24)
140+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
211141
if lenpos == 7:
212142
b += ord(data[p + 4]) + (ord(data[p + 5]) << 8) + (ord(data[p + 6]) << 16)
213-
a += (
214-
ord(data[p + 0])
215-
+ (ord(data[p + 1]) << 8)
216-
+ (ord(data[p + 2]) << 16)
217-
+ (ord(data[p + 3]) << 24)
218-
)
143+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
219144
if lenpos == 6:
220145
b += (ord(data[p + 5]) << 8) + ord(data[p + 4])
221-
a += (
222-
ord(data[p + 0])
223-
+ (ord(data[p + 1]) << 8)
224-
+ (ord(data[p + 2]) << 16)
225-
+ (ord(data[p + 3]) << 24)
226-
)
146+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
227147
if lenpos == 5:
228148
b += ord(data[p + 4])
229-
a += (
230-
ord(data[p + 0])
231-
+ (ord(data[p + 1]) << 8)
232-
+ (ord(data[p + 2]) << 16)
233-
+ (ord(data[p + 3]) << 24)
234-
)
149+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
235150
if lenpos == 4:
236-
a += (
237-
ord(data[p + 0])
238-
+ (ord(data[p + 1]) << 8)
239-
+ (ord(data[p + 2]) << 16)
240-
+ (ord(data[p + 3]) << 24)
241-
)
151+
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16) + (ord(data[p + 3]) << 24)
242152
if lenpos == 3:
243153
a += ord(data[p + 0]) + (ord(data[p + 1]) << 8) + (ord(data[p + 2]) << 16)
244154
if lenpos == 2:

0 commit comments

Comments
 (0)