Created
June 29, 2013 23:41
-
-
Save andy47/5893154 to your computer and use it in GitHub Desktop.
An example function for us to write tests for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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