Skip to content

Commit

Permalink
Merge pull request #704 from doronz88/refactor/fix-deprecation-warnings
Browse files Browse the repository at this point in the history
Refactor/fix deprecation warnings
  • Loading branch information
doronz88 authored Nov 29, 2023
2 parents db87e0d + b46ce20 commit 00e7cc2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
6 changes: 4 additions & 2 deletions pymobiledevice3/ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def make_cert(key, public_key, common_name=None):
cert = cert.issuer_name(issuer)
cert = cert.public_key(public_key)
cert = cert.serial_number(1)
cert = cert.not_valid_before(datetime.utcnow() - timedelta(minutes=1))
cert = cert.not_valid_after(datetime.utcnow() + timedelta(days=365 * 10))
now = datetime.now()
now = now.replace(tzinfo=None)
cert = cert.not_valid_before(now - timedelta(minutes=1))
cert = cert.not_valid_after(now + timedelta(days=365 * 10))
cert = cert.sign(key, hashes.SHA256())
return cert

Expand Down
3 changes: 2 additions & 1 deletion pymobiledevice3/cli/cli_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import signal
import sys
import uuid
from typing import Callable, List, Mapping, Optional, Tuple

Expand Down Expand Up @@ -101,7 +102,7 @@ def wait_return():

def sudo_required(func):
def wrapper(*args, **kwargs):
if os.geteuid() != 0:
if sys.platform != 'win32' and os.geteuid() != 0:
raise AccessDeniedError()
else:
func(*args, **kwargs)
Expand Down
24 changes: 11 additions & 13 deletions pymobiledevice3/tunneld.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os
import signal
from contextlib import suppress
from contextlib import asynccontextmanager, suppress
from typing import Dict, Tuple

import fastapi
Expand Down Expand Up @@ -162,14 +162,23 @@ async def discover_new_devices(self) -> None:

class TunneldRunner:
""" TunneldRunner orchestrate between the webserver and TunneldCore """

@classmethod
def create(cls, host: str, port: int) -> None:
cls(host, port)._run_app()

def __init__(self, host: str, port: int):
@asynccontextmanager
async def lifespan(app: FastAPI):
logging.getLogger('zeroconf').disabled = True
self._tunneld_core.start()
yield
logger.info('Closing tunneld tasks...')
await self._tunneld_core.close()

self.host = host
self.port = port
self._app = FastAPI()
self._app = FastAPI(lifespan=lifespan)
self._tunneld_core = TunneldCore()

@self._app.get('/')
Expand All @@ -193,16 +202,5 @@ async def clear_tunnels() -> fastapi.Response:
self._tunneld_core.clear()
return fastapi.Response(status_code=200, content='Cleared tunnels...')

@self._app.on_event('startup')
async def on_startup() -> None:
""" start TunneldCore """
logging.getLogger('zeroconf').disabled = True
self._tunneld_core.start()

@self._app.on_event('shutdown')
async def on_close() -> None:
logger.info('Closing tunneld tasks...')
await self._tunneld_core.close()

def _run_app(self) -> None:
uvicorn.run(self._app, host=self.host, port=self.port, loop='asyncio')

0 comments on commit 00e7cc2

Please sign in to comment.