Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerhancock committed Nov 10, 2023
1 parent ae58f12 commit 638523d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
3 changes: 1 addition & 2 deletions patent_client/epo/ops/published/manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ..session import OpsAsyncSession
from ..session import OpsAuthenticationError
from .model.search import Inpadoc
from patent_client.util.hishel_util import cache_disabled


class TestPublished:
Expand Down Expand Up @@ -54,7 +53,7 @@ def test_issue_41(self):
def test_issue_76_no_credential(self):
good_session = api.asession
api.asession = OpsAsyncSession()
with cache_disabled(asession):
with asession.cache_disabled():
with pytest.raises(OpsAuthenticationError):
pub = Inpadoc.objects.get("EP3082535A1")
api.asession = good_session
Expand Down
4 changes: 2 additions & 2 deletions patent_client/epo/ops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from patent_client import SETTINGS
from patent_client.session import PatentClientSession
from patent_client.util.asyncio_util import SyncProxy
from patent_client.util.hishel_util import cache_disabled


NS = {
"http://ops.epo.org": None,
Expand Down Expand Up @@ -58,7 +58,7 @@ async def request(self, *args, **kwargs):

async def get_token(self):
auth_url = "https://ops.epo.org/3.2/auth/accesstoken"
with cache_disabled(self):
with self.cache_disabled():
response = await super(OpsAsyncSession, self).request(
"post",
auth_url,
Expand Down
11 changes: 11 additions & 0 deletions patent_client/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -57,3 +58,13 @@ async def adownload(self, url, method: str = "GET", path: Optional[str | Path] =
async for chunk in response.aiter_bytes():
f.write(chunk)
return path

@contextmanager
def cache_disabled(session):
if hasattr(session._transport, "_transport"):
cached_transport = session._transport._transport
session._transport = session._transport._transport
yield
session._transport = cached_transport
else:
yield
4 changes: 2 additions & 2 deletions patent_client/uspto/peds/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .model import Document
from .model import PedsPage
from .session import session
from patent_client.util.hishel_util import cache_disabled


type_map = {
"string": str,
Expand All @@ -30,7 +30,7 @@ def __init__(self):

@classmethod
async def is_online(cls) -> bool:
with cache_disabled(session):
with session.cache_disabled():
response = await session.get("https://ped.uspto.gov/api/search-fields")
if response.status_code == 200:
return True
Expand Down
3 changes: 1 addition & 2 deletions patent_client/uspto/public_search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .model import PublicSearchBiblioPage
from .model import PublicSearchDocument
from .session import session
from patent_client.util.hishel_util import cache_disabled


class UsptoException(Exception):
Expand Down Expand Up @@ -100,7 +99,7 @@ async def get_document(self, bib) -> "PublicSearchDocument":

async def get_session(self):
url = "https://ppubs.uspto.gov/dirsearch-public/users/me/session"
with cache_disabled(session):
with session.cache_disabled():
response = await session.post(url, json=-1) # json=str(random.randint(10000, 99999)))
self.session = response.json()
self.case_id = self.session["userCase"]["caseId"]
Expand Down
12 changes: 0 additions & 12 deletions patent_client/util/hishel_util.py

This file was deleted.

0 comments on commit 638523d

Please sign in to comment.