@brief Parse connection strings of the form [username[/password]@][hostname][:port][/database] Separation characters (/@:) and the backslash (\) need to be escaped. @returns A tuple (username, password, hostname, port, database). Field not specified wil
(connectionStr)
| 866 | |
| 867 | |
| 868 | def parseConnectionStr(connectionStr): |
| 869 | """ |
| 870 | @brief Parse connection strings of the form |
| 871 | <tt>[username[/password]@][hostname][:port][/database]</tt> |
| 872 | |
| 873 | Separation characters (/@:) and the backslash (\) need to be escaped. |
| 874 | @returns A tuple (username, password, hostname, port, database). Field not |
| 875 | specified will be None. |
| 876 | """ |
| 877 | match = re.search( |
| 878 | r'((?P<user>([^/@:\\]|\\/|\\@|\\:|\\\\)+)' + |
| 879 | r'(/(?P<password>([^/@:\\]|\\/|\\@|\\:|\\\\)*))?@)?' + |
| 880 | r'(?P<host>([^/@:\\]|\\/|\\@|\\:|\\\\)+)?' + |
| 881 | r'(:(?P<port>[0-9]+))?' + |
| 882 | r'(/(?P<database>([^/@:\\]|\\/|\\@|\\:|\\\\)+))?', connectionStr) |
| 883 | return ( |
| 884 | unescape(match.group('user')), |
| 885 | unescape(match.group('password')), |
| 886 | unescape(match.group('host')), |
| 887 | match.group('port'), |
| 888 | unescape(match.group('database'))) |
| 889 | # ------------------------------------------------------------------------------ |
| 890 | |
| 891 |