URL format

Suppose that the format of a web address is:

scheme://host:port

as for instance http://magraner:1200, where http is the scheme, always ending with a colon and two slash signs, the host is magraner and the port is 1200.

Write the function check_url() that takes a string with a web address in url format, and returns another string showing whether it contains error, following these rules, in the given ordering:

  • If the number of colon sign is not two, the returned string is 'colon error'

  • If the first character of the scheme is not alphabetical the returned string is 'scheme error'

  • If any of the characters following the last colon sign is not a digit, the returned string is 'port error'

In any other case the returned string is 'correct'.

Save this function into the file url_format.py. Examples:

>>> check_url('http://magraner')
'colon error'
>>> check_url('3http://magraner:1200')
'scheme error'
>>> check_url('http://magraner:index')
'port error'
>>> check_url('http://magraner:1200')
'correct'

Note

More tests are provided in file test-url_format.txt

Solution

A solution of these functions is provided in file url_format.py