comparison MoinMoin/support/werkzeug/script.py @ 6129:7f12cf241d5e

update werkzeug to 0.12.1, update CHANGES
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Apr 2017 22:42:23 +0200
parents 9f12f41504fc
children
comparison
equal deleted inserted replaced
6128:561b7a9c2bd9 6129:7f12cf241d5e
73 from __future__ import print_function 73 from __future__ import print_function
74 74
75 import sys 75 import sys
76 import inspect 76 import inspect
77 import getopt 77 import getopt
78 from warnings import warn
78 from os.path import basename 79 from os.path import basename
79 from werkzeug._compat import iteritems 80 from werkzeug._compat import iteritems
80 81
81 82
82 argument_types = { 83 argument_types = {
91 'boolean': lambda x: x.lower() in ('1', 'true', 'yes', 'on'), 92 'boolean': lambda x: x.lower() in ('1', 'true', 'yes', 'on'),
92 'string': str, 93 'string': str,
93 'integer': int, 94 'integer': int,
94 'float': float 95 'float': float
95 } 96 }
97
98
99 def _deprecated():
100 warn(DeprecationWarning('werkzeug.script is deprecated and '
101 'will be removed soon'), stacklevel=2)
96 102
97 103
98 def run(namespace=None, action_prefix='action_', args=None): 104 def run(namespace=None, action_prefix='action_', args=None):
99 """Run the script. Participating actions are looked up in the caller's 105 """Run the script. Participating actions are looked up in the caller's
100 namespace if no namespace is given, otherwise in the dict provided. 106 namespace if no namespace is given, otherwise in the dict provided.
107 :param action_prefix: The prefix for the functions. Everything else 113 :param action_prefix: The prefix for the functions. Everything else
108 is ignored. 114 is ignored.
109 :param args: the arguments for the function. If not specified 115 :param args: the arguments for the function. If not specified
110 :data:`sys.argv` without the first argument is used. 116 :data:`sys.argv` without the first argument is used.
111 """ 117 """
118 _deprecated()
112 if namespace is None: 119 if namespace is None:
113 namespace = sys._getframe(1).f_locals 120 namespace = sys._getframe(1).f_locals
114 actions = find_actions(namespace, action_prefix) 121 actions = find_actions(namespace, action_prefix)
115 122
116 if args is None: 123 if args is None:
177 return func(**arguments) 184 return func(**arguments)
178 185
179 186
180 def fail(message, code=-1): 187 def fail(message, code=-1):
181 """Fail with an error.""" 188 """Fail with an error."""
189 _deprecated()
182 print('Error: %s' % message, file=sys.stderr) 190 print('Error: %s' % message, file=sys.stderr)
183 sys.exit(code) 191 sys.exit(code)
184 192
185 193
186 def find_actions(namespace, action_prefix): 194 def find_actions(namespace, action_prefix):
187 """Find all the actions in the namespace.""" 195 """Find all the actions in the namespace."""
196 _deprecated()
188 actions = {} 197 actions = {}
189 for key, value in iteritems(namespace): 198 for key, value in iteritems(namespace):
190 if key.startswith(action_prefix): 199 if key.startswith(action_prefix):
191 actions[key[len(action_prefix):]] = analyse_action(value) 200 actions[key[len(action_prefix):]] = analyse_action(value)
192 return actions 201 return actions
193 202
194 203
195 def print_usage(actions): 204 def print_usage(actions):
196 """Print the usage information. (Help screen)""" 205 """Print the usage information. (Help screen)"""
206 _deprecated()
197 actions = sorted(iteritems(actions)) 207 actions = sorted(iteritems(actions))
198 print('usage: %s <action> [<options>]' % basename(sys.argv[0])) 208 print('usage: %s <action> [<options>]' % basename(sys.argv[0]))
199 print(' %s --help' % basename(sys.argv[0])) 209 print(' %s --help' % basename(sys.argv[0]))
200 print() 210 print()
201 print('actions:') 211 print('actions:')
218 print() 228 print()
219 229
220 230
221 def analyse_action(func): 231 def analyse_action(func):
222 """Analyse a function.""" 232 """Analyse a function."""
233 _deprecated()
223 description = inspect.getdoc(func) or 'undocumented action' 234 description = inspect.getdoc(func) or 'undocumented action'
224 arguments = [] 235 arguments = []
225 args, varargs, kwargs, defaults = inspect.getargspec(func) 236 args, varargs, kwargs, defaults = inspect.getargspec(func)
226 if varargs or kwargs: 237 if varargs or kwargs:
227 raise TypeError('variable length arguments for action not allowed.') 238 raise TypeError('variable length arguments for action not allowed.')
253 value of this function is the initial namespace. 264 value of this function is the initial namespace.
254 :param banner: the banner that is displayed before the shell. If 265 :param banner: the banner that is displayed before the shell. If
255 not specified a generic banner is used instead. 266 not specified a generic banner is used instead.
256 :param use_ipython: if set to `True` ipython is used if available. 267 :param use_ipython: if set to `True` ipython is used if available.
257 """ 268 """
269 _deprecated()
258 if banner is None: 270 if banner is None:
259 banner = 'Interactive Werkzeug Shell' 271 banner = 'Interactive Werkzeug Shell'
260 if init_func is None: 272 if init_func is None:
261 init_func = dict 273 init_func = dict
262 274
265 namespace = init_func() 277 namespace = init_func()
266 if ipython: 278 if ipython:
267 try: 279 try:
268 try: 280 try:
269 from IPython.frontend.terminal.embed import InteractiveShellEmbed 281 from IPython.frontend.terminal.embed import InteractiveShellEmbed
270 sh = InteractiveShellEmbed(banner1=banner) 282 sh = InteractiveShellEmbed.instance(banner1=banner)
271 except ImportError: 283 except ImportError:
272 from IPython.Shell import IPShellEmbed 284 from IPython.Shell import IPShellEmbed
273 sh = IPShellEmbed(banner=banner) 285 sh = IPShellEmbed(banner=banner)
274 except ImportError: 286 except ImportError:
275 pass 287 pass
276 else: 288 else:
277 sh(global_ns={}, local_ns=namespace) 289 sh(local_ns=namespace)
278 return 290 return
279 from code import interact 291 from code import interact
280 interact(banner, local=namespace) 292 interact(banner, local=namespace)
281 return action 293 return action
282 294
302 :param processes: the default number of processes to start. 314 :param processes: the default number of processes to start.
303 :param static_files: optional dict of static files. 315 :param static_files: optional dict of static files.
304 :param extra_files: optional list of extra files to track for reloading. 316 :param extra_files: optional list of extra files to track for reloading.
305 :param ssl_context: optional SSL context for running server in HTTPS mode. 317 :param ssl_context: optional SSL context for running server in HTTPS mode.
306 """ 318 """
319 _deprecated()
320
307 def action(hostname=('h', hostname), port=('p', port), 321 def action(hostname=('h', hostname), port=('p', port),
308 reloader=use_reloader, debugger=use_debugger, 322 reloader=use_reloader, debugger=use_debugger,
309 evalex=use_evalex, threaded=threaded, processes=processes): 323 evalex=use_evalex, threaded=threaded, processes=processes):
310 """Start a new development server.""" 324 """Start a new development server."""
311 from werkzeug.serving import run_simple 325 from werkzeug.serving import run_simple