Skip to content

Commit b3d73f1

Browse files
Michael IkemannAlyxion
Michael Ikemann
authored andcommitted
Reverting PyCharm formatting
1 parent b9005ee commit b3d73f1

File tree

3 files changed

+28
-46
lines changed

3 files changed

+28
-46
lines changed

nicegui/client.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def is_auto_index_client(self) -> bool:
9797
@property
9898
def ip(self) -> Optional[str]:
9999
"""Return the IP address of the client, or None if the client is not connected."""
100-
return self.environ['asgi.scope']['client'][
101-
0] if self.environ else None # pylint: disable=unsubscriptable-object
100+
return self.environ['asgi.scope']['client'][0] if self.environ else None # pylint: disable=unsubscriptable-object
102101

103102
@property
104103
def has_socket_connection(self) -> bool:
@@ -137,13 +136,12 @@ def build_response(self, request: Request, status_code: int = 200) -> Response:
137136
'request': request,
138137
'version': __version__,
139138
'elements': elements.replace('&', '&')
140-
.replace('<', '&lt;')
141-
.replace('>', '&gt;')
142-
.replace('`', '&#96;')
143-
.replace('$', '&#36;'),
139+
.replace('<', '&lt;')
140+
.replace('>', '&gt;')
141+
.replace('`', '&#96;')
142+
.replace('$', '&#36;'),
144143
'head_html': self.head_html,
145-
'body_html': '<style>' + '\n'.join(vue_styles) + '</style>\n' + self.body_html + '\n' + '\n'.join(
146-
vue_html),
144+
'body_html': '<style>' + '\n'.join(vue_styles) + '</style>\n' + self.body_html + '\n' + '\n'.join(vue_html),
147145
'vue_scripts': '\n'.join(vue_scripts),
148146
'imports': json.dumps(imports),
149147
'js_imports': '\n'.join(js_imports),
@@ -258,7 +256,6 @@ def handle_handshake(self) -> None:
258256

259257
def handle_disconnect(self) -> None:
260258
"""Wait for the browser to reconnect; invoke disconnect handlers if it doesn't."""
261-
262259
async def handle_disconnect() -> None:
263260
if self.page.reconnect_timeout is not None:
264261
delay = self.page.reconnect_timeout
@@ -271,7 +268,6 @@ async def handle_disconnect() -> None:
271268
self.safe_invoke(t)
272269
if not self.shared:
273270
self.delete()
274-
275271
self._disconnect_task = background_tasks.create(handle_disconnect())
276272

277273
def handle_event(self, msg: Dict) -> None:
@@ -295,7 +291,6 @@ def safe_invoke(self, func: Union[Callable[..., Any], Awaitable]) -> None:
295291
async def func_with_client():
296292
with self:
297293
await func
298-
299294
background_tasks.create(func_with_client())
300295
else:
301296
with self:
@@ -304,7 +299,6 @@ async def func_with_client():
304299
async def result_with_client():
305300
with self:
306301
await result
307-
308302
background_tasks.create(result_with_client())
309303
except Exception as e:
310304
core.app.handle_exception(e)
@@ -359,4 +353,4 @@ async def prune_instances(cls) -> None:
359353
except Exception:
360354
# NOTE: make sure the loop doesn't crash
361355
log.exception('Error while pruning clients')
362-
await asyncio.sleep(10)
356+
await asyncio.sleep(10)

nicegui/page.py

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ async def decorated(*dec_args, **dec_kwargs) -> Response:
106106
async def wait_for_result() -> None:
107107
with client:
108108
return await result
109-
110109
task = background_tasks.create(wait_for_result())
111110
deadline = time.time() + self.response_timeout
112111
while task and not client.is_waiting_for_connection and not task.done():

nicegui/storage.py

+21-32
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
from .context import get_slot_stack
1717
from .logging import log
1818

19-
request_contextvar: contextvars.ContextVar[Optional[Request]] = contextvars.ContextVar(
20-
'request_var', default=None)
19+
request_contextvar: contextvars.ContextVar[Optional[Request]] = contextvars.ContextVar('request_var', default=None)
2120

2221

2322
class ReadOnlyDict(MutableMapping):
2423

25-
def __init__(self, data: Dict[Any, Any],
26-
write_error_message: str = 'Read-only dict') -> None:
24+
def __init__(self, data: Dict[Any, Any], write_error_message: str = 'Read-only dict') -> None:
2725
self._data: Dict[Any, Any] = data
2826
self._write_error_message: str = write_error_message
2927

@@ -65,7 +63,6 @@ def backup(self) -> None:
6563
async def backup() -> None:
6664
async with aiofiles.open(self.filepath, 'w', encoding=self.encoding) as f:
6765
await f.write(json.dumps(self))
68-
6966
if core.loop:
7067
background_tasks.create_lazy(backup(), name=self.filepath.stem)
7168
else:
@@ -74,8 +71,7 @@ async def backup() -> None:
7471

7572
class RequestTrackingMiddleware(BaseHTTPMiddleware):
7673

77-
async def dispatch(self, request: Request,
78-
call_next: RequestResponseEndpoint) -> Response:
74+
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
7975
request_contextvar.set(request)
8076
if 'id' not in request.session:
8177
request.session['id'] = str(uuid.uuid4())
@@ -100,8 +96,7 @@ class Storage:
10096
def __init__(self) -> None:
10197
self.path = Path(os.environ.get('NICEGUI_STORAGE_PATH', '.nicegui')).resolve()
10298
self.migrate_to_utf8()
103-
self._general = PersistentDict(self.path / 'storage-general.json',
104-
encoding='utf-8')
99+
self._general = PersistentDict(self.path / 'storage-general.json', encoding='utf-8')
105100
self._users: Dict[str, PersistentDict] = {}
106101

107102
@property
@@ -115,11 +110,9 @@ def browser(self) -> Union[ReadOnlyDict, Dict]:
115110
request: Optional[Request] = request_contextvar.get()
116111
if request is None:
117112
if self._is_in_auto_index_context():
118-
raise RuntimeError(
119-
'app.storage.browser can only be used with page builder functions '
120-
'(https://nicegui.io/documentation/page)')
121-
raise RuntimeError(
122-
'app.storage.browser needs a storage_secret passed in ui.run()')
113+
raise RuntimeError('app.storage.browser can only be used with page builder functions '
114+
'(https://nicegui.io/documentation/page)')
115+
raise RuntimeError('app.storage.browser needs a storage_secret passed in ui.run()')
123116
if request.state.responded:
124117
return ReadOnlyDict(
125118
request.session,
@@ -137,27 +130,14 @@ def user(self) -> Dict:
137130
request: Optional[Request] = request_contextvar.get()
138131
if request is None:
139132
if self._is_in_auto_index_context():
140-
raise RuntimeError(
141-
'app.storage.user can only be used with page builder functions '
142-
'(https://nicegui.io/documentation/page)')
143-
raise RuntimeError(
144-
'app.storage.user needs a storage_secret passed in ui.run()')
133+
raise RuntimeError('app.storage.user can only be used with page builder functions '
134+
'(https://nicegui.io/documentation/page)')
135+
raise RuntimeError('app.storage.user needs a storage_secret passed in ui.run()')
145136
session_id = request.session['id']
146137
if session_id not in self._users:
147-
self._users[session_id] = PersistentDict(
148-
self.path / f'storage-user-{session_id}.json', encoding='utf-8')
138+
self._users[session_id] = PersistentDict(self.path / f'storage-user-{session_id}.json', encoding='utf-8')
149139
return self._users[session_id]
150140

151-
@property
152-
def session(self) -> Dict:
153-
"""Volatile client storage that is persisted on the server (where NiceGUI is
154-
executed) on a per client/per connection basis.
155-
156-
Note that this kind of storage can only be used in single page applications
157-
where the client connection is preserved between page changes."""
158-
client = context.get_client()
159-
return client.state
160-
161141
@staticmethod
162142
def _is_in_auto_index_context() -> bool:
163143
try:
@@ -170,6 +150,15 @@ def general(self) -> Dict:
170150
"""General storage shared between all users that is persisted on the server (where NiceGUI is executed)."""
171151
return self._general
172152

153+
@property
154+
def session(self) -> Dict:
155+
"""Volatile client storage that is persisted on the server (where NiceGUI is
156+
executed) on a per client/per connection basis.
157+
Note that this kind of storage can only be used in single page applications
158+
where the client connection is preserved between page changes."""
159+
client = context.get_client()
160+
return client.state
161+
173162
def clear(self) -> None:
174163
"""Clears all storage."""
175164
self._general.clear()
@@ -192,4 +181,4 @@ def migrate_to_utf8(self) -> None:
192181
log.warning(f'Could not load storage file {filepath}')
193182
data = {}
194183
filepath.rename(new_filepath)
195-
new_filepath.write_text(json.dumps(data), encoding='utf-8')
184+
new_filepath.write_text(json.dumps(data), encoding='utf-8')

0 commit comments

Comments
 (0)