MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / render_as_string

Method render_as_string

lib/sqlalchemy/engine/url.py:630–667  ·  view source on GitHub ↗

Render this :class:`_engine.URL` object as a string. This method is used when the ``__str__()`` or ``__repr__()`` methods are used. The method directly includes additional options. :param hide_password: Defaults to True. The password is not shown in the string

(self, hide_password: bool = True)

Source from the content-addressed store, hash-verified

628 return self.render_as_string(hide_password=hide_password)
629
630 def render_as_string(self, hide_password: bool = True) -> str:
631 """Render this :class:`_engine.URL` object as a string.
632
633 This method is used when the ``__str__()`` or ``__repr__()``
634 methods are used. The method directly includes additional options.
635
636 :param hide_password: Defaults to True. The password is not shown
637 in the string unless this is set to False.
638
639 """
640 s = self.drivername + "://"
641 if self.username is not None:
642 s += quote(self.username, safe=" +")
643 if self.password is not None:
644 s += ":" + (
645 "***"
646 if hide_password
647 else quote(str(self.password), safe=" +")
648 )
649 s += "@"
650 if self.host is not None:
651 if ":" in self.host:
652 s += f"[{self.host}]"
653 else:
654 s += self.host
655 if self.port is not None:
656 s += ":" + str(self.port)
657 if self.database is not None:
658 s += "/" + quote(self.database, safe=" +/")
659 if self.query:
660 keys = list(self.query)
661 keys.sort()
662 s += "?" + "&".join(
663 f"{quote_plus(k)}={quote_plus(element)}"
664 for k in keys
665 for element in util.to_list(self.query[k])
666 )
667 return s
668
669 def __repr__(self) -> str:
670 return self.render_as_string()

Callers 9

__to_string__Method · 0.95
__repr__Method · 0.95
_engine_uriFunction · 0.80
test_rfc1738Method · 0.80
test_rfc1738_passwordMethod · 0.80
test_query_stringMethod · 0.80
test_urlattrMethod · 0.80

Calls 2

sortMethod · 0.45
joinMethod · 0.45

Tested by 6

test_rfc1738Method · 0.64
test_rfc1738_passwordMethod · 0.64
test_query_stringMethod · 0.64
test_urlattrMethod · 0.64