comparison mercurial/httppeer.py @ 50925:d718eddf01d9

safehasattr: drop usage in favor of hasattr The two functions should now be equivalent at least in their usage in core.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 31 Aug 2023 23:56:15 +0200
parents 60f9602b413e
children 18c8c18993f0
comparison
equal deleted inserted replaced
50924:7a8ea1397816 50925:d718eddf01d9
63 63
64 64
65 class _multifile: 65 class _multifile:
66 def __init__(self, *fileobjs): 66 def __init__(self, *fileobjs):
67 for f in fileobjs: 67 for f in fileobjs:
68 if not util.safehasattr(f, 'length'): 68 if not hasattr(f, 'length'):
69 raise ValueError( 69 raise ValueError(
70 b'_multifile only supports file objects that ' 70 b'_multifile only supports file objects that '
71 b'have a length but this one does not:', 71 b'have a length but this one does not:',
72 type(f), 72 type(f),
73 f, 73 f,
178 q += sorted(args.items()) 178 q += sorted(args.items())
179 179
180 qs = b'?%s' % urlreq.urlencode(q) 180 qs = b'?%s' % urlreq.urlencode(q)
181 cu = b"%s%s" % (repobaseurl, qs) 181 cu = b"%s%s" % (repobaseurl, qs)
182 size = 0 182 size = 0
183 if util.safehasattr(data, 'length'): 183 if hasattr(data, 'length'):
184 size = data.length 184 size = data.length
185 elif data is not None: 185 elif data is not None:
186 size = len(data) 186 size = len(data)
187 if data is not None and 'Content-Type' not in headers: 187 if data is not None and 'Content-Type' not in headers:
188 headers['Content-Type'] = 'application/mercurial-0.1' 188 headers['Content-Type'] = 'application/mercurial-0.1'