Show More
@@ -213,10 +213,23 cl_args = ( | |||||
213 | action='store_true', dest='NOSEP', default=NoDefault, |
|
213 | action='store_true', dest='NOSEP', default=NoDefault, | |
214 | help="Eliminate all spacing between prompts.") |
|
214 | help="Eliminate all spacing between prompts.") | |
215 | ), |
|
215 | ), | |
|
216 | (('-term_title',), dict( | |||
|
217 | action='store_true', dest='TERM_TITLE', default=NoDefault, | |||
|
218 | help="Enable auto setting the terminal title.") | |||
|
219 | ), | |||
|
220 | (('-noterm_title',), dict( | |||
|
221 | action='store_false', dest='TERM_TITLE', default=NoDefault, | |||
|
222 | help="Disable auto setting the terminal title.") | |||
|
223 | ), | |||
216 | (('-xmode',), dict( |
|
224 | (('-xmode',), dict( | |
217 | type=str, dest='XMODE', default=NoDefault, |
|
225 | type=str, dest='XMODE', default=NoDefault, | |
218 | help="Exception mode ('Plain','Context','Verbose')") |
|
226 | help="Exception mode ('Plain','Context','Verbose')") | |
219 | ), |
|
227 | ), | |
|
228 | # These are only here to get the proper deprecation warnings | |||
|
229 | (('-pylab','-wthread','-qthread','-q4thread','-gthread'), dict( | |||
|
230 | action='store_true', dest='THREADED_SHELL', default=NoDefault, | |||
|
231 | help="These command line flags are deprecated, see the 'gui' magic.") | |||
|
232 | ), | |||
220 | ) |
|
233 | ) | |
221 |
|
234 | |||
222 |
|
235 | |||
@@ -244,11 +257,9 class IPythonApp(Application): | |||||
244 | if clc.CLASSIC: clc.QUICK = 1 |
|
257 | if clc.CLASSIC: clc.QUICK = 1 | |
245 |
|
258 | |||
246 | # Display the deprecation warnings about threaded shells |
|
259 | # Display the deprecation warnings about threaded shells | |
247 | # if opts_all.pylab == 1: threaded_shell_warning() |
|
260 | if hasattr(clc, 'THREADED_SHELL'): | |
248 |
|
|
261 | threaded_shell_warning() | |
249 | # if opts_all.qthread == 1: threaded_shell_warning() |
|
262 | del clc['THREADED_SHELL'] | |
250 | # if opts_all.q4thread == 1: threaded_shell_warning() |
|
|||
251 | # if opts_all.gthread == 1: threaded_shell_warning() |
|
|||
252 |
|
263 | |||
253 | def load_file_config(self): |
|
264 | def load_file_config(self): | |
254 | if hasattr(self.command_line_config, 'QUICK'): |
|
265 | if hasattr(self.command_line_config, 'QUICK'): | |
@@ -276,22 +287,13 class IPythonApp(Application): | |||||
276 | config.XMODE = 'Plain' |
|
287 | config.XMODE = 'Plain' | |
277 |
|
288 | |||
278 | # All this should be moved to traitlet handlers in InteractiveShell |
|
289 | # All this should be moved to traitlet handlers in InteractiveShell | |
|
290 | # But, currently InteractiveShell doesn't have support for changing | |||
|
291 | # these values at runtime. Once we support that, this should | |||
|
292 | # be moved there!!! | |||
279 | if hasattr(config, 'NOSEP'): |
|
293 | if hasattr(config, 'NOSEP'): | |
280 | if config.NOSEP: |
|
294 | if config.NOSEP: | |
281 | config.SEPARATE_IN = config.SEPARATE_OUT = config.SEPARATE_OUT2 = '0' |
|
295 | config.SEPARATE_IN = config.SEPARATE_OUT = config.SEPARATE_OUT2 = '0' | |
282 |
|
296 | |||
283 | if hasattr(config, 'SEPARATE_IN'): |
|
|||
284 | if config.SEPARATE_IN == '0': config.SEPARATE_IN = '' |
|
|||
285 | config.SEPARATE_IN = config.SEPARATE_IN.replace('\\n','\n') |
|
|||
286 |
|
||||
287 | if hasattr(config, 'SEPARATE_OUT'): |
|
|||
288 | if config.SEPARATE_OUT == '0': config.SEPARATE_OUT = '' |
|
|||
289 | config.SEPARATE_OUT = config.SEPARATE_OUT.replace('\\n','\n') |
|
|||
290 |
|
||||
291 | if hasattr(config, 'SEPARATE_OUT'): |
|
|||
292 | if config.SEPARATE_OUT2 == '0': config.SEPARATE_OUT2 = '' |
|
|||
293 | config.SEPARATE_OUT2 = config.SEPARATE_OUT2.replace('\\n','\n') |
|
|||
294 |
|
||||
295 | def construct(self): |
|
297 | def construct(self): | |
296 | # I am a little hesitant to put these into InteractiveShell itself. |
|
298 | # I am a little hesitant to put these into InteractiveShell itself. | |
297 | # But that might be the place for them |
|
299 | # But that might be the place for them |
@@ -53,9 +53,10 from IPython.utils.ipstruct import Struct | |||||
53 | from IPython.utils import PyColorize |
|
53 | from IPython.utils import PyColorize | |
54 | from IPython.utils.genutils import * |
|
54 | from IPython.utils.genutils import * | |
55 | from IPython.utils.strdispatch import StrDispatch |
|
55 | from IPython.utils.strdispatch import StrDispatch | |
|
56 | from IPython.utils.platutils import toggle_set_term_title, set_term_title | |||
56 |
|
57 | |||
57 | from IPython.utils.traitlets import ( |
|
58 | from IPython.utils.traitlets import ( | |
58 | Int, Float, Str, CBool, CaselessStrEnum, Enum |
|
59 | Int, Float, Str, CBool, CaselessStrEnum, Enum, List | |
59 | ) |
|
60 | ) | |
60 |
|
61 | |||
61 | #----------------------------------------------------------------------------- |
|
62 | #----------------------------------------------------------------------------- | |
@@ -170,6 +171,19 def get_default_editor(): | |||||
170 | ed = 'notepad' # same in Windows! |
|
171 | ed = 'notepad' # same in Windows! | |
171 | return ed |
|
172 | return ed | |
172 |
|
173 | |||
|
174 | ||||
|
175 | class SeparateStr(Str): | |||
|
176 | """A Str subclass to validate separate_in, separate_out, etc. | |||
|
177 | ||||
|
178 | This is a Str based traitlet that converts '0'->'' and '\\n'->'\n'. | |||
|
179 | """ | |||
|
180 | ||||
|
181 | def validate(self, obj, value): | |||
|
182 | if value == '0': value = '' | |||
|
183 | value = value.replace('\\n','\n') | |||
|
184 | return super(SeparateStr, self).validate(obj, value) | |||
|
185 | ||||
|
186 | ||||
173 | #----------------------------------------------------------------------------- |
|
187 | #----------------------------------------------------------------------------- | |
174 | # Main IPython class |
|
188 | # Main IPython class | |
175 | #----------------------------------------------------------------------------- |
|
189 | #----------------------------------------------------------------------------- | |
@@ -195,12 +209,10 def get_default_editor(): | |||||
195 | class InteractiveShell(Component, Magic): |
|
209 | class InteractiveShell(Component, Magic): | |
196 | """An enhanced console for Python.""" |
|
210 | """An enhanced console for Python.""" | |
197 |
|
211 | |||
198 | alias = [] |
|
|||
199 | autocall = Enum((0,1,2), config_key='AUTOCALL') |
|
212 | autocall = Enum((0,1,2), config_key='AUTOCALL') | |
200 | autoedit_syntax = CBool(False, config_key='AUTOEDIT_SYNTAX') |
|
213 | autoedit_syntax = CBool(False, config_key='AUTOEDIT_SYNTAX') | |
201 | autoindent = CBool(True, config_key='AUTOINDENT') |
|
214 | autoindent = CBool(True, config_key='AUTOINDENT') | |
202 | automagic = CBool(True, config_key='AUTOMAGIC') |
|
215 | automagic = CBool(True, config_key='AUTOMAGIC') | |
203 | autoexec = [] |
|
|||
204 | display_banner = CBool(True, config_key='DISPLAY_BANNER') |
|
216 | display_banner = CBool(True, config_key='DISPLAY_BANNER') | |
205 | banner = Str('') |
|
217 | banner = Str('') | |
206 | banner1 = Str(default_banner, config_key='BANNER1') |
|
218 | banner1 = Str(default_banner, config_key='BANNER1') | |
@@ -212,34 +224,35 class InteractiveShell(Component, Magic): | |||||
212 | colors = CaselessStrEnum(('NoColor','LightBG','Linux'), |
|
224 | colors = CaselessStrEnum(('NoColor','LightBG','Linux'), | |
213 | default_value='LightBG', config_key='COLORS') |
|
225 | default_value='LightBG', config_key='COLORS') | |
214 | confirm_exit = CBool(True, config_key='CONFIRM_EXIT') |
|
226 | confirm_exit = CBool(True, config_key='CONFIRM_EXIT') | |
215 | debug = CBool(False) |
|
227 | debug = CBool(False, config_key='DEBUG') | |
216 | deep_reload = CBool(False, config_key='DEEP_RELOAD') |
|
228 | deep_reload = CBool(False, config_key='DEEP_RELOAD') | |
217 | embedded = CBool(False) |
|
229 | embedded = CBool(False) | |
218 | editor = Str(get_default_editor(), config_key='EDITOR') |
|
230 | editor = Str(get_default_editor(), config_key='EDITOR') | |
219 | filename = Str("<ipython console>") |
|
231 | filename = Str("<ipython console>") | |
220 | help = CBool(False) |
|
232 | interactive = CBool(False, config_key='INTERACTIVE') | |
221 | interactive = CBool(False) |
|
|||
222 | logstart = CBool(False, config_key='LOGSTART') |
|
233 | logstart = CBool(False, config_key='LOGSTART') | |
223 | logfile = Str('', config_key='LOGFILE') |
|
234 | logfile = Str('', config_key='LOGFILE') | |
224 | logplay = Str('', config_key='LOGPLAY') |
|
235 | logplay = Str('', config_key='LOGPLAY') | |
225 | multi_line_specials = CBool(True) |
|
236 | multi_line_specials = CBool(True, config_key='MULTI_LINE_SPECIALS') | |
226 |
object_info_string_level = |
|
237 | object_info_string_level = Enum((0,1,2), default_value=0, | |
227 | pager = Str('less') |
|
238 | config_keys='OBJECT_INFO_STRING_LEVEL') | |
|
239 | pager = Str('less', config_key='PAGER') | |||
228 | pdb = CBool(False, config_key='PDB') |
|
240 | pdb = CBool(False, config_key='PDB') | |
229 | pprint = CBool(True, config_key='PPRINT') |
|
241 | pprint = CBool(True, config_key='PPRINT') | |
230 | profile = Str('', config_key='PROFILE') |
|
242 | profile = Str('', config_key='PROFILE') | |
231 | prompt_in1 = Str('In [\\#]: ', config_key='PROMPT_IN1') |
|
243 | prompt_in1 = Str('In [\\#]: ', config_key='PROMPT_IN1') | |
232 | prompt_in2 = Str(' .\\D.: ', config_key='PROMPT_IN2') |
|
244 | prompt_in2 = Str(' .\\D.: ', config_key='PROMPT_IN2') | |
233 | prompt_out = Str('Out[\\#]: ', config_key='PROMPT_OUT1') |
|
245 | prompt_out = Str('Out[\\#]: ', config_key='PROMPT_OUT1') | |
234 | prompts_pad_left = CBool(True) |
|
246 | prompts_pad_left = CBool(True, config_key='PROMPTS_PAD_LEFT') | |
235 | pydb = CBool(False) |
|
247 | quiet = CBool(False, config_key='QUIET') | |
236 | quiet = CBool(False) |
|
|||
237 |
|
248 | |||
238 | readline_use = CBool(True, config_key='READLINE_USE') |
|
249 | readline_use = CBool(True, config_key='READLINE_USE') | |
239 |
readline_merge_completions = CBool(True |
|
250 | readline_merge_completions = CBool(True, | |
240 | readline_omit__names = Int(0) |
|
251 | config_key='READLINE_MERGE_COMPLETIONS') | |
241 | readline_remove_delims = '-/~' |
|
252 | readline_omit__names = Enum((0,1,2), default_value=0, | |
242 | readline_parse_and_bind = [ |
|
253 | config_key='READLINE_OMIT_NAMES') | |
|
254 | readline_remove_delims = Str('-/~', config_key='READLINE_REMOVE_DELIMS') | |||
|
255 | readline_parse_and_bind = List([ | |||
243 | 'tab: complete', |
|
256 | 'tab: complete', | |
244 | '"\C-l": possible-completions', |
|
257 | '"\C-l": possible-completions', | |
245 | 'set show-all-if-ambiguous on', |
|
258 | 'set show-all-if-ambiguous on', | |
@@ -255,19 +268,25 class InteractiveShell(Component, Magic): | |||||
255 | '"\e[B": history-search-forward', |
|
268 | '"\e[B": history-search-forward', | |
256 | '"\C-k": kill-line', |
|
269 | '"\C-k": kill-line', | |
257 | '"\C-u": unix-line-discard', |
|
270 | '"\C-u": unix-line-discard', | |
258 | ] |
|
271 | ], allow_none=False, config_key='READLINE_PARSE_AND_BIND' | |
|
272 | ) | |||
259 |
|
273 | |||
260 | screen_length = Int(0, config_key='SCREEN_LENGTH') |
|
274 | screen_length = Int(0, config_key='SCREEN_LENGTH') | |
261 | separate_in = Str('\n', config_key='SEPARATE_IN') |
|
275 | ||
262 | separate_out = Str('', config_key='SEPARATE_OUT') |
|
276 | # Use custom TraitletTypes that convert '0'->'' and '\\n'->'\n' | |
263 |
separate_ |
|
277 | separate_in = SeparateStr('\n', config_key='SEPARATE_IN') | |
264 | system_header = Str('IPython system call: ') |
|
278 | separate_out = SeparateStr('', config_key='SEPARATE_OUT') | |
265 | system_verbose = CBool(False) |
|
279 | separate_out2 = SeparateStr('', config_key='SEPARATE_OUT2') | |
266 | term_title = CBool(True) |
|
280 | ||
267 | wildcards_case_sensitive = CBool(True) |
|
281 | system_header = Str('IPython system call: ', config_key='SYSTEM_HEADER') | |
|
282 | system_verbose = CBool(False, config_key='SYSTEM_VERBOSE') | |||
|
283 | term_title = CBool(False, config_key='TERM_TITLE') | |||
|
284 | wildcards_case_sensitive = CBool(True, config_key='WILDCARDS_CASE_SENSITIVE') | |||
268 | xmode = CaselessStrEnum(('Context','Plain', 'Verbose'), |
|
285 | xmode = CaselessStrEnum(('Context','Plain', 'Verbose'), | |
269 | default_value='Context', config_key='XMODE') |
|
286 | default_value='Context', config_key='XMODE') | |
270 | magic_docstrings = CBool(False) |
|
287 | ||
|
288 | alias = List(allow_none=False, config_key='ALIAS') | |||
|
289 | autoexec = List(allow_none=False) | |||
271 |
|
290 | |||
272 | # class attribute to indicate whether the class supports threads or not. |
|
291 | # class attribute to indicate whether the class supports threads or not. | |
273 | # Subclasses with thread support should override this as needed. |
|
292 | # Subclasses with thread support should override this as needed. | |
@@ -285,6 +304,7 class InteractiveShell(Component, Magic): | |||||
285 | super(InteractiveShell, self).__init__(parent, config=config, name=name) |
|
304 | super(InteractiveShell, self).__init__(parent, config=config, name=name) | |
286 |
|
305 | |||
287 | self.init_instance_attrs() |
|
306 | self.init_instance_attrs() | |
|
307 | self.init_term_title() | |||
288 | self.init_usage(usage) |
|
308 | self.init_usage(usage) | |
289 | self.init_banner(banner1, banner2) |
|
309 | self.init_banner(banner1, banner2) | |
290 | self.init_embedded(embedded) |
|
310 | self.init_embedded(embedded) | |
@@ -343,6 +363,9 class InteractiveShell(Component, Magic): | |||||
343 | num_lines_bot = self.separate_in.count('\n')+1 |
|
363 | num_lines_bot = self.separate_in.count('\n')+1 | |
344 | return self.screen_length - num_lines_bot |
|
364 | return self.screen_length - num_lines_bot | |
345 |
|
365 | |||
|
366 | def _term_title_changed(self, name, new_value): | |||
|
367 | self.init_term_title() | |||
|
368 | ||||
346 | #------------------------------------------------------------------------- |
|
369 | #------------------------------------------------------------------------- | |
347 | # init_* methods called by __init__ |
|
370 | # init_* methods called by __init__ | |
348 | #------------------------------------------------------------------------- |
|
371 | #------------------------------------------------------------------------- | |
@@ -386,6 +409,14 class InteractiveShell(Component, Magic): | |||||
386 | # Indentation management |
|
409 | # Indentation management | |
387 | self.indent_current_nsp = 0 |
|
410 | self.indent_current_nsp = 0 | |
388 |
|
411 | |||
|
412 | def init_term_title(self): | |||
|
413 | # Enable or disable the terminal title. | |||
|
414 | if self.term_title: | |||
|
415 | toggle_set_term_title(True) | |||
|
416 | set_term_title('IPython: ' + abbrev_cwd()) | |||
|
417 | else: | |||
|
418 | toggle_set_term_title(False) | |||
|
419 | ||||
389 | def init_usage(self, usage=None): |
|
420 | def init_usage(self, usage=None): | |
390 | if usage is None: |
|
421 | if usage is None: | |
391 | self.usage = interactive_usage |
|
422 | self.usage = interactive_usage | |
@@ -564,7 +595,7 class InteractiveShell(Component, Magic): | |||||
564 |
|
595 | |||
565 | # Now the history file |
|
596 | # Now the history file | |
566 | try: |
|
597 | try: | |
567 |
histfname = 'history-%s' % self. |
|
598 | histfname = 'history-%s' % self.profile | |
568 | except AttributeError: |
|
599 | except AttributeError: | |
569 | histfname = 'history' |
|
600 | histfname = 'history' | |
570 | self.histfile = os.path.join(self.config.IPYTHONDIR, histfname) |
|
601 | self.histfile = os.path.join(self.config.IPYTHONDIR, histfname) | |
@@ -903,8 +934,8 class InteractiveShell(Component, Magic): | |||||
903 | self.call_pdb = self.pdb |
|
934 | self.call_pdb = self.pdb | |
904 |
|
935 | |||
905 | def init_exec_commands(self): |
|
936 | def init_exec_commands(self): | |
906 |
for cmd in self. |
|
937 | for cmd in self.config.EXECUTE: | |
907 |
|
|
938 | print "execute:", cmd | |
908 | self.api.runlines(cmd) |
|
939 | self.api.runlines(cmd) | |
909 |
|
940 | |||
910 | batchrun = False |
|
941 | batchrun = False |
@@ -2856,8 +2856,7 Defaulting color scheme to 'NoColor'""" | |||||
2856 | try: |
|
2856 | try: | |
2857 | os.chdir(os.path.expanduser(ps)) |
|
2857 | os.chdir(os.path.expanduser(ps)) | |
2858 | if self.shell.term_title: |
|
2858 | if self.shell.term_title: | |
2859 | #print 'set term title:',self.shell.term_title # dbg |
|
2859 | platutils.set_term_title('IPython: ' + abbrev_cwd()) | |
2860 | platutils.set_term_title('IPy ' + abbrev_cwd()) |
|
|||
2861 | except OSError: |
|
2860 | except OSError: | |
2862 | print sys.exc_info()[1] |
|
2861 | print sys.exc_info()[1] | |
2863 | else: |
|
2862 | else: | |
@@ -2870,7 +2869,7 Defaulting color scheme to 'NoColor'""" | |||||
2870 | else: |
|
2869 | else: | |
2871 | os.chdir(self.shell.home_dir) |
|
2870 | os.chdir(self.shell.home_dir) | |
2872 | if self.shell.term_title: |
|
2871 | if self.shell.term_title: | |
2873 |
platutils.set_term_title( |
|
2872 | platutils.set_term_title('IPython: ' + '~') | |
2874 | cwd = os.getcwd() |
|
2873 | cwd = os.getcwd() | |
2875 | dhist = self.shell.user_ns['_dh'] |
|
2874 | dhist = self.shell.user_ns['_dh'] | |
2876 |
|
2875 |
@@ -54,7 +54,6 def toggle_set_term_title(val): | |||||
54 |
|
54 | |||
55 | def set_term_title(title): |
|
55 | def set_term_title(title): | |
56 | """Set terminal title using the necessary platform-dependent calls.""" |
|
56 | """Set terminal title using the necessary platform-dependent calls.""" | |
57 |
|
||||
58 | if _platutils.ignore_termtitle: |
|
57 | if _platutils.ignore_termtitle: | |
59 | return |
|
58 | return | |
60 | _platutils.set_term_title(title) |
|
59 | _platutils.set_term_title(title) |
@@ -17,17 +17,18 import os | |||||
17 |
|
17 | |||
18 | ignore_termtitle = True |
|
18 | ignore_termtitle = True | |
19 |
|
19 | |||
|
20 | ||||
20 | def _dummy_op(*a, **b): |
|
21 | def _dummy_op(*a, **b): | |
21 | """ A no-op function """ |
|
22 | """ A no-op function """ | |
22 |
|
23 | |||
23 |
|
24 | |||
24 | def _set_term_title_xterm(title): |
|
25 | def _set_term_title_xterm(title): | |
25 | """ Change virtual terminal title in xterm-workalikes """ |
|
26 | """ Change virtual terminal title in xterm-workalikes """ | |
26 |
|
||||
27 | sys.stdout.write('\033]0;%s\007' % title) |
|
27 | sys.stdout.write('\033]0;%s\007' % title) | |
28 |
|
28 | |||
|
29 | TERM = os.environ.get('TERM','') | |||
29 |
|
30 | |||
30 | if os.environ.get('TERM','') == 'xterm': |
|
31 | if (TERM == 'xterm') or (TERM == 'xterm-color'): | |
31 | set_term_title = _set_term_title_xterm |
|
32 | set_term_title = _set_term_title_xterm | |
32 | else: |
|
33 | else: | |
33 | set_term_title = _dummy_op |
|
34 | set_term_title = _dummy_op |
@@ -26,6 +26,7 try: | |||||
26 | """Set terminal title using ctypes to access the Win32 APIs.""" |
|
26 | """Set terminal title using ctypes to access the Win32 APIs.""" | |
27 | SetConsoleTitleW(title) |
|
27 | SetConsoleTitleW(title) | |
28 |
|
28 | |||
|
29 | ||||
29 | except ImportError: |
|
30 | except ImportError: | |
30 | def set_term_title(title): |
|
31 | def set_term_title(title): | |
31 | """Set terminal title using the 'title' command.""" |
|
32 | """Set terminal title using the 'title' command.""" |
@@ -52,10 +52,15 Authors: | |||||
52 | import inspect |
|
52 | import inspect | |
53 | import sys |
|
53 | import sys | |
54 | import types |
|
54 | import types | |
55 | from types import InstanceType, ClassType, FunctionType |
|
55 | from types import ( | |
|
56 | InstanceType, ClassType, FunctionType, | |||
|
57 | ListType, TupleType | |||
|
58 | ) | |||
56 |
|
59 | |||
57 | ClassTypes = (ClassType, type) |
|
60 | ClassTypes = (ClassType, type) | |
58 |
|
61 | |||
|
62 | SequenceTypes = (ListType, TupleType) | |||
|
63 | ||||
59 | #----------------------------------------------------------------------------- |
|
64 | #----------------------------------------------------------------------------- | |
60 | # Basic classes |
|
65 | # Basic classes | |
61 | #----------------------------------------------------------------------------- |
|
66 | #----------------------------------------------------------------------------- | |
@@ -860,7 +865,9 class CBool(Bool): | |||||
860 | except: |
|
865 | except: | |
861 | self.error(obj, value) |
|
866 | self.error(obj, value) | |
862 |
|
867 | |||
|
868 | ||||
863 | class Enum(TraitletType): |
|
869 | class Enum(TraitletType): | |
|
870 | """An enum that whose value must be in a given sequence.""" | |||
864 |
|
871 | |||
865 | def __init__(self, values, default_value=None, allow_none=True, **metadata): |
|
872 | def __init__(self, values, default_value=None, allow_none=True, **metadata): | |
866 | self.values = values |
|
873 | self.values = values | |
@@ -884,6 +891,7 class Enum(TraitletType): | |||||
884 | return result |
|
891 | return result | |
885 |
|
892 | |||
886 | class CaselessStrEnum(Enum): |
|
893 | class CaselessStrEnum(Enum): | |
|
894 | """An enum of strings that are caseless in validate.""" | |||
887 |
|
895 | |||
888 | def validate(self, obj, value): |
|
896 | def validate(self, obj, value): | |
889 | if value is None: |
|
897 | if value is None: | |
@@ -897,3 +905,21 class CaselessStrEnum(Enum): | |||||
897 | if v.lower() == value.lower(): |
|
905 | if v.lower() == value.lower(): | |
898 | return v |
|
906 | return v | |
899 | self.error(obj, value) |
|
907 | self.error(obj, value) | |
|
908 | ||||
|
909 | ||||
|
910 | class List(Instance): | |||
|
911 | """An instance of a Python list.""" | |||
|
912 | ||||
|
913 | def __init__(self, default_value=None, allow_none=True, **metadata): | |||
|
914 | """Create a list traitlet type from a list or tuple. | |||
|
915 | ||||
|
916 | The default value is created by doing ``list(default_value)``, | |||
|
917 | which creates a copy of the ``default_value``. | |||
|
918 | """ | |||
|
919 | if default_value is None: | |||
|
920 | args = ((),) | |||
|
921 | elif isinstance(default_value, SequenceTypes): | |||
|
922 | args = (default_value,) | |||
|
923 | ||||
|
924 | super(List,self).__init__(klass=list, args=args, | |||
|
925 | allow_none=allow_none, **metadata) |
General Comments 0
You need to be logged in to leave comments.
Login now