@@ -187,6 +187,7 @@ def build(
187187 cls ,
188188 * ,
189189 scheme = "" ,
190+ authority = None ,
190191 user = None ,
191192 password = None ,
192193 host = "" ,
@@ -199,8 +200,14 @@ def build(
199200 ):
200201 """Creates and returns a new URL"""
201202
202- if not host and scheme :
203- raise ValueError ('Can\' t build URL with "scheme" but without "host".' )
203+ if scheme and (not host and not authority ):
204+ raise ValueError (
205+ 'Can\' t build URL with "scheme" but without "host" or "authority".'
206+ )
207+ if authority and (user or password or host or port ):
208+ raise ValueError (
209+ 'Can\' t mix "authority" with "user", "password", "host" or "port".'
210+ )
204211 if port and not host :
205212 raise ValueError ('Can\' t build URL with "port" but without "host".' )
206213 if query and query_string :
@@ -211,7 +218,15 @@ def build(
211218 '"fragment" args, use string values instead.'
212219 )
213220
214- if not user and not password and not host and not port :
221+ if authority :
222+ if encoded :
223+ netloc = authority
224+ else :
225+ tmp = SplitResult ("" , authority , "" , "" , "" )
226+ netloc = cls ._make_netloc (
227+ tmp .username , tmp .password , tmp .hostname , tmp .port , encode = True
228+ )
229+ elif not user and not password and not host and not port :
215230 netloc = ""
216231 else :
217232 netloc = cls ._make_netloc (user , password , host , port , encode = not encoded )
@@ -388,6 +403,26 @@ def scheme(self):
388403 """
389404 return self ._val .scheme
390405
406+ @property
407+ def raw_authority (self ):
408+ """Encoded authority part of URL.
409+
410+ Empty string for relative URLs.
411+
412+ """
413+ return self ._val .netloc
414+
415+ @cached_property
416+ def authority (self ):
417+ """Decoded authority part of URL.
418+
419+ Empty string for relative URLs.
420+
421+ """
422+ return self ._make_netloc (
423+ self .user , self .password , self .host , self .port , encode = False
424+ )
425+
391426 @property
392427 def raw_user (self ):
393428 """Encoded user part of URL.
0 commit comments