Skip to content

Instantly share code, notes, and snippets.

@andy47
Created June 29, 2013 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andy47/5893154 to your computer and use it in GitHub Desktop.
Save andy47/5893154 to your computer and use it in GitHub Desktop.
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