Skip to content

Commit

Permalink
Switch to httpx to ease async support.
Browse files Browse the repository at this point in the history
Ref #30
  • Loading branch information
jaraco committed Jun 1, 2024
1 parent cb93d96 commit 12bd0c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies = [
"xmltodict",
"more_itertools",
"jaraco.context",
"httpx",
]
dynamic = ["version"]

Expand Down
16 changes: 6 additions & 10 deletions wolframalpha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import json
import getpass
import os
import urllib.parse
import urllib.request
import contextlib
import collections
from typing import Dict, Any, Callable, Tuple

import httpx
import xmltodict
from jaraco.context import suppress
from more_itertools import always_iterable
Expand Down Expand Up @@ -117,14 +116,11 @@ def query(self, input, params=(), **kwargs):
input=input,
appid=self.app_id,
)
data = itertools.chain(params, data.items(), kwargs.items())

query = urllib.parse.urlencode(tuple(data))
url = 'https://api.wolframalpha.com/v2/query?' + query
resp = urllib.request.urlopen(url)
assert resp.headers.get_content_type() == 'text/xml'
assert resp.headers.get_param('charset') == 'utf-8'
doc = xmltodict.parse(resp, postprocessor=Document.make)

url = 'https://api.wolframalpha.com/v2/query'
resp = httpx.get(url, params=data | kwargs)
assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8'
doc = xmltodict.parse(resp.content, postprocessor=Document.make)
return doc['queryresult']


Expand Down

1 comment on commit 12bd0c7

@jaraco
Copy link
Owner Author

@jaraco jaraco commented on 12bd0c7 Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broke support for params. No linter caught it.

Please sign in to comment.