Skip to content

Commit edfe37e

Browse files
committed
Trimming some whitespace
1 parent 5bf5e6c commit edfe37e

16 files changed

+98
-52
lines changed

contract-tests/service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ def status():
5454
}
5555
return (json.dumps(body), 200, {'Content-type': 'application/json'})
5656

57+
5758
@app.route('/', methods=['DELETE'])
5859
def delete_stop_service():
5960
global_log.info("Test service has told us to exit")
6061
os._exit(0)
6162

63+
6264
@app.route('/', methods=['POST'])
6365
def post_create_stream():
6466
global stream_counter, streams
@@ -74,6 +76,7 @@ def post_create_stream():
7476

7577
return ('', 201, {'Location': resource_url})
7678

79+
7780
@app.route('/streams/<id>', methods=['POST'])
7881
def post_stream_command(id):
7982
global streams
@@ -87,6 +90,7 @@ def post_stream_command(id):
8790
return ('', 400)
8891
return ('', 204)
8992

93+
9094
@app.route('/streams/<id>', methods=['DELETE'])
9195
def delete_stream(id):
9296
global streams
@@ -97,6 +101,7 @@ def delete_stream(id):
97101
stream.close()
98102
return ('', 204)
99103

104+
100105
if __name__ == "__main__":
101106
port = default_port
102107
if sys.argv[len(sys.argv) - 1] != 'service.py':

contract-tests/stream_entity.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
http_client = urllib3.PoolManager()
1717

18+
1819
def millis_to_seconds(t):
1920
return None if t is None else t / 1000
2021

@@ -27,7 +28,7 @@ def __init__(self, options):
2728
self.closed = False
2829
self.callback_counter = 0
2930
self.sse = None
30-
31+
3132
thread = threading.Thread(target=self.run)
3233
thread.start()
3334

@@ -91,7 +92,7 @@ def do_command(self, command: str) -> bool:
9192
self.log.info('Test service sent command: %s' % command)
9293
# currently we support no special commands
9394
return False
94-
95+
9596
def send_message(self, message):
9697
global http_client
9798

ld_eventsource/actions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Action:
66
"""
77
Base class for objects that can be returned by :attr:`.SSEClient.all`.
88
"""
9+
910
pass
1011

1112

@@ -66,19 +67,19 @@ def __repr__(self):
6667
self._event,
6768
json.dumps(self._data),
6869
"None" if self._id is None else json.dumps(self._id),
69-
"None" if self._last_event_id is None else json.dumps(self._last_event_id)
70+
"None" if self._last_event_id is None else json.dumps(self._last_event_id),
7071
)
7172

7273

7374
class Comment(Action):
7475
"""
7576
A comment received by :class:`.SSEClient`.
76-
77+
7778
Comment lines (any line beginning with a colon) have no significance in the SSE specification
7879
and can be ignored, but if you want to see them, use :attr:`.SSEClient.all`. They will never
7980
be returned by :attr:`.SSEClient.events`.
8081
"""
81-
82+
8283
def __init__(self, comment: str):
8384
self._comment = comment
8485

@@ -104,6 +105,7 @@ class Start(Action):
104105
A ``Start`` is returned for the first successful connection. If the client reconnects
105106
after a failure, there will be a :class:`.Fault` followed by a ``Start``.
106107
"""
108+
107109
pass
108110

109111

@@ -121,7 +123,7 @@ class Fault(Action):
121123

122124
def __init__(self, error: Optional[Exception]):
123125
self.__error = error
124-
126+
125127
@property
126128
def error(self) -> Optional[Exception]:
127129
"""

ld_eventsource/config/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .connect_strategy import (ConnectionClient, ConnectionResult,
2-
ConnectStrategy)
1+
from .connect_strategy import ConnectionClient, ConnectionResult, ConnectStrategy
32
from .error_strategy import ErrorStrategy
43
from .retry_delay_strategy import RetryDelayStrategy

ld_eventsource/config/connect_strategy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __exit__(self, type, value, traceback):
120120
# _HttpConnectStrategy and _HttpConnectionClient are defined here rather than in http.py to avoid
121121
# a circular module reference.
122122

123+
123124
class _HttpConnectStrategy(ConnectStrategy):
124125
def __init__(self, params: _HttpConnectParams):
125126
self.__params = params

ld_eventsource/config/error_strategy.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ErrorStrategy:
88
"""
99
Base class of strategies for determining how SSEClient should handle a stream error or the
1010
end of a stream.
11-
11+
1212
The parameter that SSEClient passes to :meth:`apply()` is either ``None`` if the server ended
1313
the stream normally, or an exception. If it is an exception, it could be an I/O exception
1414
(failure to connect, broken connection, etc.), or one of the error types defined in this
@@ -25,7 +25,7 @@ class ErrorStrategy:
2525
With either option, it is still always possible to explicitly reconnect the stream by calling
2626
:meth:`.SSEClient.start()` again, or simply by trying to read from :attr:`.SSEClient.events`
2727
or :attr:`.SSEClient.all` again.
28-
28+
2929
Subclasses should be immutable. To implement strategies that behave differently on consecutive
3030
retries, the strategy should return a new instance of its own class as the second return value
3131
from ``apply``, rather than modifying the state of the existing instance. This makes it easy
@@ -74,7 +74,7 @@ def continue_with_max_attempts(max_attempts: int) -> ErrorStrategy:
7474
:param max_attempts: the maximum number of consecutive retries
7575
"""
7676
return _MaxAttemptsErrorStrategy(max_attempts, 0)
77-
77+
7878
@staticmethod
7979
def continue_with_time_limit(max_time: float) -> ErrorStrategy:
8080
"""
@@ -90,7 +90,7 @@ def from_lambda(fn: Callable[[Optional[Exception]], Tuple[bool, Optional[ErrorSt
9090
"""
9191
Convenience method for creating an ErrorStrategy whose ``apply`` method is equivalent to
9292
the given lambda.
93-
93+
9494
The one difference is that the second return value is an ``Optional[ErrorStrategy]`` which
9595
can be None to mean "no change", since the lambda cannot reference the strategy's ``self``.
9696
"""
@@ -100,26 +100,28 @@ def from_lambda(fn: Callable[[Optional[Exception]], Tuple[bool, Optional[ErrorSt
100100
class _LambdaErrorStrategy(ErrorStrategy):
101101
def __init__(self, fn: Callable[[Optional[Exception]], Tuple[bool, Optional[ErrorStrategy]]]):
102102
self.__fn = fn
103-
103+
104104
def apply(self, exception: Optional[Exception]) -> Tuple[bool, ErrorStrategy]:
105105
should_raise, maybe_next = self.__fn(exception)
106106
return (should_raise, maybe_next or self)
107107

108+
108109
class _MaxAttemptsErrorStrategy(ErrorStrategy):
109110
def __init__(self, max_attempts: int, counter: int):
110111
self.__max_attempts = max_attempts
111112
self.__counter = counter
112-
113+
113114
def apply(self, exception: Optional[Exception]) -> Tuple[bool, ErrorStrategy]:
114115
if self.__counter >= self.__max_attempts:
115116
return (ErrorStrategy.FAIL, self)
116117
return (ErrorStrategy.CONTINUE, _MaxAttemptsErrorStrategy(self.__max_attempts, self.__counter + 1))
117118

119+
118120
class _TimeLimitErrorStrategy(ErrorStrategy):
119121
def __init__(self, max_time: float, start_time: float):
120122
self.__max_time = max_time
121123
self.__start_time = start_time
122-
124+
123125
def apply(self, exception: Optional[Exception]) -> Tuple[bool, ErrorStrategy]:
124126
if self.__start_time == 0:
125127
return (ErrorStrategy.CONTINUE, _TimeLimitErrorStrategy(self.__max_time, time.time()))

ld_eventsource/config/retry_delay_strategy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def apply(self, base_delay: float) -> Tuple[float, RetryDelayStrategy]:
120120
delay, maybe_next = self.__fn(base_delay)
121121
return (delay, maybe_next or self)
122122

123+
123124
class _ReusableRandom:
124125
def __init__(self, seed: float):
125126
self.__seed = seed

ld_eventsource/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class HTTPStatusError(Exception):
32
"""
43
This exception indicates that the client was able to connect to the server, but that
@@ -8,11 +7,12 @@ class HTTPStatusError(Exception):
87
def __init__(self, status: int):
98
super().__init__("HTTP error %d" % status)
109
self._status = status
11-
10+
1211
@property
1312
def status(self) -> int:
1413
return self._status
1514

15+
1616
class HTTPContentTypeError(Exception):
1717
"""
1818
This exception indicates that the HTTP response did not have the expected content
@@ -22,7 +22,7 @@ class HTTPContentTypeError(Exception):
2222
def __init__(self, content_type: str):
2323
super().__init__("invalid content type \"%s\"" % content_type)
2424
self._content_type = content_type
25-
25+
2626
@property
2727
def content_type(self) -> str:
2828
return self._content_type

ld_eventsource/http.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def __init__(
2626
@property
2727
def url(self) -> str:
2828
return self.__url
29-
29+
3030
@property
3131
def headers(self) -> Optional[dict]:
3232
return self.__headers
33-
33+
3434
@property
3535
def pool(self) -> Optional[PoolManager]:
3636
return self.__pool
37-
37+
3838
@property
3939
def urllib3_request_options(self) -> Optional[dict]:
4040
return self.__urllib3_request_options
@@ -46,10 +46,10 @@ def __init__(self, params: _HttpConnectParams, logger: Logger):
4646
self.__pool = params.pool or PoolManager()
4747
self.__should_close_pool = params.pool is not None
4848
self.__logger = logger
49-
49+
5050
def connect(self, last_event_id: Optional[str]) -> Tuple[Iterator[bytes], Callable]:
5151
self.__logger.info("Connecting to stream at %s" % self.__params.url)
52-
52+
5353
headers = self.__params.headers.copy() if self.__params.headers else {}
5454
headers['Cache-Control'] = 'no-cache'
5555
headers['Accept'] = 'text/event-stream'

ld_eventsource/reader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class _BufferedLineReader:
88
Helper class that encapsulates the logic for reading UTF-8 stream data as a series of text lines,
99
each of which can be terminated by \n, \r, or \r\n.
1010
"""
11+
1112
@staticmethod
1213
def lines_from(chunks):
1314
"""
@@ -49,6 +50,7 @@ def lines_from(chunks):
4950
for line in lines:
5051
yield line.decode()
5152

53+
5254
class _SSEReader:
5355
def __init__(
5456
self,
@@ -59,11 +61,11 @@ def __init__(
5961
self._lines_source = lines_source
6062
self._last_event_id = last_event_id
6163
self._set_retry = set_retry
62-
64+
6365
@property
6466
def last_event_id(self):
6567
return self._last_event_id
66-
68+
6769
@property
6870
def events_and_comments(self):
6971
event_type = ""

0 commit comments

Comments
 (0)