Skip to content

Commit 3c4d55d

Browse files
committed
fixes #132
1 parent 6204fd4 commit 3c4d55d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

fastcore/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def exec_local(code, var_name):
9999

100100
# Cell
101101
def risinstance(types, obj=None):
102-
"Curried `isinstance` but with args reversed, suitable for `partial`"
102+
"Curried `isinstance` but with args reversed"
103103
if not obj: return partial(risinstance,types)
104104
return isinstance(obj, types)
105105

@@ -586,8 +586,10 @@ def urlread(url, data=None, **kwargs):
586586
if data is not None:
587587
if not isinstance(data, (str,bytes)): data = urlencode(data)
588588
if not isinstance(data, bytes): data = data.encode('ascii')
589-
req=urllib.request.Request(url,headers={'User-Agent': 'Mozilla/5.0'})
590-
with urlopen(req, data=data) as res: return res.read()
589+
cls = urllib.request.Request
590+
if not isinstance(url,cls): url = cls(url)
591+
url.headers['User-Agent'] = 'Mozilla/5.0'
592+
with urlopen(url, data=data) as res: return res.read()
591593

592594
# Cell
593595
def urljson(url, data=None):

nbs/02_utils.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
{
297297
"data": {
298298
"text/plain": [
299-
"<__main__._t at 0x7f150b4c2f40>"
299+
"<__main__._t at 0x7f8a3f586e50>"
300300
]
301301
},
302302
"execution_count": null,
@@ -2194,7 +2194,7 @@
21942194
{
21952195
"data": {
21962196
"text/plain": [
2197-
"['d', 'f', 'e', 'g', 'h', 'b', 'c', 'a']"
2197+
"['h', 'a', 'c', 'f', 'd', 'e', 'b', 'g']"
21982198
]
21992199
},
22002200
"execution_count": null,
@@ -3189,8 +3189,10 @@
31893189
" if data is not None:\n",
31903190
" if not isinstance(data, (str,bytes)): data = urlencode(data)\n",
31913191
" if not isinstance(data, bytes): data = data.encode('ascii')\n",
3192-
" req=urllib.request.Request(url,headers={'User-Agent': 'Mozilla/5.0'})\n",
3193-
" with urlopen(req, data=data) as res: return res.read()"
3192+
" cls = urllib.request.Request\n",
3193+
" if not isinstance(url,cls): url = cls(url)\n",
3194+
" url.headers['User-Agent'] = 'Mozilla/5.0'\n",
3195+
" with urlopen(url, data=data) as res: return res.read()"
31943196
]
31953197
},
31963198
{

0 commit comments

Comments
 (0)