Refactored the stub implementation of urlopen used for tests