Implemented UNPROCESSED type.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent f1249f8 · Browse files · 3 files·+28 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+28 added−2 removed
- other:+28 added−2 removed
Provenance
- Commit
563017b- Tree
4f4c17d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
f1249f8
3 files changed+28 added−2 removed
modified:click/__init__.py+2 added-2 removed
23 unmodified lines24 password_option, version_option, help_option25 26 # Types27 from .types import ParamType, File, Path, Choice, IntRange, STRING, INT, \28- FLOAT, BOOL, UUID28+ FLOAT, BOOL, UUID, UNPROCESSED29 30 # Utilities31 from .utils import echo, get_binary_stream, get_text_stream, open_file, \32 format_filename, get_app_dir25 unmodified lines58 'version_option', 'help_option',59 60 # Types61 'ParamType', 'File', 'Path', 'Choice', 'IntRange', 'STRING', 'INT',62- 'FLOAT', 'BOOL', 'UUID',62+ 'FLOAT', 'BOOL', 'UUID', 'UNPROCESSED',63 64 # Utilities65 'echo', 'get_binary_stream', 'get_text_stream', 'open_file',66 'format_filename', 'get_app_dir',19 unmodified linesmodified:click/types.py+24 added
82 unmodified lines83 value = str(value).decode('utf-8', 'replace')84 self.fail(value, param, ctx)85 86 87+class UnprocessedParamType(ParamType):88+ name = 'text'89+90+ def convert(self, value, param, ctx):91+ return value92+93+ def __repr__(self):94+ return 'UNPROCESSED'95+96+97 class StringParamType(ParamType):98 name = 'text'99 100 def convert(self, value, param, ctx):339 unmodified lines440 pass441 return FuncParamType(ty)442 443 444+#: A dummy parameter type that just does nothing. From a user's445+#: perspective this appears to just be the same as `STRING` but internally446+#: no string conversion takes place. This is necessary to achieve the447+#: same bytes/unicode behavior on Python 2/3 in situations where you want448+#: to not convert argument types. This is usually useful when working449+#: with file paths as they can appear in bytes and unicode.450+#:451+#: For path related uses the :class:`Path` type is a better choice but452+#: there are situations where an unprocessed type is useful which is why453+#: it is is provided.454+#:455+#: .. versionadded:: 4.0456+UNPROCESSED = UnprocessedParamType()457+458 #: A unicode string parameter type which is the implicit default. This459 #: can also be selected by using ``str`` as type.460 STRING = StringParamType()461 14 unmodified linesmodified:CHANGES+2 added
10 unmodified lines11 - Added `color` parameters to lots of interfaces that directly or indirectly12 call into echoing. This previously was always autodetection (with the13 exception of the `echo_via_pager` function). Now you can forcefully14 enable or disable it, overriding the auto detection of Click.15+- Added an `UNPROCESSED` type which does not perform any type changes which16+ simplifies text handling on 2.x / 3.x in some special advanced usecases.17 18 Version 3.319 -----------20 176 unmodified lines