Skip to content

Commit 8fdfd81

Browse files
committed
simplify HTTP4xxClientError subclasses
1 parent 7bcdd92 commit 8fdfd81

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

fastcore/_modidx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@
333333
'fastcore.net': { 'fastcore.net.HTTP4xxClientError': ('net.html#http4xxclienterror', 'fastcore/net.py'),
334334
'fastcore.net.HTTP5xxServerError': ('net.html#http5xxservererror', 'fastcore/net.py'),
335335
'fastcore.net.Request.summary': ('net.html#request.summary', 'fastcore/net.py'),
336-
'fastcore.net._mk_error': ('net.html#_mk_error', 'fastcore/net.py'),
337336
'fastcore.net._socket_det': ('net.html#_socket_det', 'fastcore/net.py'),
338337
'fastcore.net.do_request': ('net.html#do_request', 'fastcore/net.py'),
339338
'fastcore.net.start_client': ('net.html#start_client', 'fastcore/net.py'),

fastcore/net.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,11 @@ def urlopener():
8989
(431,'Header Fields Too Large'),(451,'Legal Reasons')
9090
)
9191

92-
def _mk_error(nm, code, msg):
93-
cls = get_class(nm, 'url', 'hdrs', 'fp', sup=HTTP4xxClientError, msg=msg, code=code)
94-
def _init(self, url, hdrs, fp, msg=msg, code=code): super(cls, self).__init__(url, code, msg, hdrs, fp)
95-
cls.__init__ = _init
96-
return cls
97-
9892
for code,msg in _httperrors:
9993
nm = f'HTTP{code}{msg.replace(" ","")}Error'
100-
globals()[nm] = ExceptionsHTTP[code] = _mk_error(nm, code, msg)
94+
def _init(self, url, hdrs, fp, msg=msg, code=code): HTTP4xxClientError.__init__(self, url, code, msg, hdrs, fp)
95+
cls = type(nm, (HTTP4xxClientError,), {'__init__':_init})
96+
globals()[nm] = ExceptionsHTTP[code] = cls
10197

10298
# %% ../nbs/03b_net.ipynb 16
10399
_all_ = ['HTTP400BadRequestError', 'HTTP401UnauthorizedError', 'HTTP402PaymentRequiredError', 'HTTP403ForbiddenError', 'HTTP404NotFoundError', 'HTTP405MethodNotAllowedError', 'HTTP406NotAcceptableError', 'HTTP407ProxyAuthRequiredError', 'HTTP408RequestTimeoutError', 'HTTP409ConflictError', 'HTTP410GoneError', 'HTTP411LengthRequiredError', 'HTTP412PreconditionFailedError', 'HTTP413PayloadTooLargeError', 'HTTP414URITooLongError', 'HTTP415UnsupportedMediaTypeError', 'HTTP416RangeNotSatisfiableError', 'HTTP417ExpectationFailedError', 'HTTP418AmAteapotError', 'HTTP421MisdirectedRequestError', 'HTTP422UnprocessableEntityError', 'HTTP423LockedError', 'HTTP424FailedDependencyError', 'HTTP425TooEarlyError', 'HTTP426UpgradeRequiredError', 'HTTP428PreconditionRequiredError', 'HTTP429TooManyRequestsError', 'HTTP431HeaderFieldsTooLargeError', 'HTTP451LegalReasonsError']

nbs/03b_net.ipynb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"text/markdown": [
185185
"---\n",
186186
"\n",
187-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L63){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
187+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L64){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
188188
"\n",
189189
"#### HTTP4xxClientError\n",
190190
"\n",
@@ -195,7 +195,7 @@
195195
"text/plain": [
196196
"---\n",
197197
"\n",
198-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L63){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
198+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L64){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
199199
"\n",
200200
"#### HTTP4xxClientError\n",
201201
"\n",
@@ -223,7 +223,7 @@
223223
"text/markdown": [
224224
"---\n",
225225
"\n",
226-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L68){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
226+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L69){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
227227
"\n",
228228
"#### HTTP5xxServerError\n",
229229
"\n",
@@ -234,7 +234,7 @@
234234
"text/plain": [
235235
"---\n",
236236
"\n",
237-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L68){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
237+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L69){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
238238
"\n",
239239
"#### HTTP5xxServerError\n",
240240
"\n",
@@ -284,15 +284,11 @@
284284
" (431,'Header Fields Too Large'),(451,'Legal Reasons')\n",
285285
")\n",
286286
"\n",
287-
"def _mk_error(nm, code, msg):\n",
288-
" cls = get_class(nm, 'url', 'hdrs', 'fp', sup=HTTP4xxClientError, msg=msg, code=code)\n",
289-
" def _init(self, url, hdrs, fp, msg=msg, code=code): super(cls, self).__init__(url, code, msg, hdrs, fp)\n",
290-
" cls.__init__ = _init\n",
291-
" return cls\n",
292-
"\n",
293287
"for code,msg in _httperrors:\n",
294288
" nm = f'HTTP{code}{msg.replace(\" \",\"\")}Error'\n",
295-
" globals()[nm] = ExceptionsHTTP[code] = _mk_error(nm, code, msg)"
289+
" def _init(self, url, hdrs, fp, msg=msg, code=code): HTTP4xxClientError.__init__(self, url, code, msg, hdrs, fp)\n",
290+
" cls = type(nm, (HTTP4xxClientError,), {'__init__':_init})\n",
291+
" globals()[nm] = ExceptionsHTTP[code] = cls"
296292
]
297293
},
298294
{

0 commit comments

Comments
 (0)