MCPcopy
hub / github.com/pydantic/pydantic / _build_url

Method _build_url

pydantic/v1/networks.py:439–484  ·  view source on GitHub ↗
(cls, m: Match[str], url: str, parts: 'Parts')

Source from the content-addressed store, hash-verified

437
438 @classmethod
439 def _build_url(cls, m: Match[str], url: str, parts: 'Parts') -> 'MultiHostDsn':
440 hosts_parts: List['HostParts'] = []
441 host_re = host_regex()
442 for host in m.groupdict()['hosts'].split(','):
443 d: Parts = host_re.match(host).groupdict() # type: ignore
444 host, tld, host_type, rebuild = cls.validate_host(d)
445 port = d.get('port')
446 cls._validate_port(port)
447 hosts_parts.append(
448 {
449 'host': host,
450 'host_type': host_type,
451 'tld': tld,
452 'rebuild': rebuild,
453 'port': port,
454 }
455 )
456
457 if len(hosts_parts) > 1:
458 return cls(
459 None if any([hp['rebuild'] for hp in hosts_parts]) else url,
460 scheme=parts['scheme'],
461 user=parts['user'],
462 password=parts['password'],
463 path=parts['path'],
464 query=parts['query'],
465 fragment=parts['fragment'],
466 host_type=None,
467 hosts=hosts_parts,
468 )
469 else:
470 # backwards compatibility with single host
471 host_part = hosts_parts[0]
472 return cls(
473 None if host_part['rebuild'] else url,
474 scheme=parts['scheme'],
475 user=parts['user'],
476 password=parts['password'],
477 host=host_part['host'],
478 tld=host_part['tld'],
479 host_type=host_part['host_type'],
480 port=host_part.get('port'),
481 path=parts['path'],
482 query=parts['query'],
483 fragment=parts['fragment'],
484 )
485
486
487class PostgresDsn(MultiHostDsn):

Callers

nothing calls this directly

Calls 4

host_regexFunction · 0.85
validate_hostMethod · 0.80
_validate_portMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected