Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An example function for us to write tests for
def parse_connection(connection_string):
"""Work out the user name and password in connection_string
Connection string should be of the form 'database://username@password'
if '@' in connection_string:
# Username is characters between '://' and '@'
slash_position = connection_string.find('://')
at_position = connection_string.find('@')
user_name = connection_string[slash_position+3:at_position]
password = connection_string[at_position+1:]
return user_name, password
if __name__ == "__main__":
print parse_connection('mysql://user@pass')
print parse_connection('a random string')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment