-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `PathOrUrl` and `FileOrUrl` parameter types extend click's `Path` and `File` parameter types, respectively, by adding support for URLs. If the conversion the base type fails, the provided value is tried as a URL. The problem was that if the provided value was intended to be a local file or path, but conversion failed, the conversion to URL would almost certainly also fail and that would be the returned error message. This would be confusing for users that tried to specify a local path, but it contained a typo or was not readable for other reasons, such as file permissions. When the base type conversion fails, now the parameter types first check whether the provided file or path exists on the local disk. If so, it is assumed that the value was intended to be a local path and an error is returned that the path could not be read. Only then is the path tried as a URL. Here the `URLError` and `socket.timeout` exceptions are caught separately in which case we are almost certainly dealing with a URL which just couldn't be reached (in time). The `urlopen` method can also throw a `ValueError` which is usually when no protocol is defined. In this case an error is returned that explicitly states that the provided value does not correspond to a readable path nor to a reachable URL.
- Loading branch information
Showing
3 changed files
with
102 additions
and
76 deletions.
There are no files selected for viewing
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
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
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