##// END OF EJS Templates
Merge pull request #2140 from bfroehle/2to3_has_key...
Thomas Kluyver -
r7873:aed04922 merge
parent child Browse files
Show More
@@ -82,7 +82,7 b' class Config(dict):'
82 def _merge(self, other):
82 def _merge(self, other):
83 to_update = {}
83 to_update = {}
84 for k, v in other.iteritems():
84 for k, v in other.iteritems():
85 if not self.has_key(k):
85 if k not in self:
86 to_update[k] = v
86 to_update[k] = v
87 else: # I have this key
87 else: # I have this key
88 if isinstance(v, Config):
88 if isinstance(v, Config):
@@ -204,11 +204,11 b' class TestConfig(TestCase):'
204 c = Config()
204 c = Config()
205 c.a = 10
205 c.a = 10
206 self.assertEquals(c.a, 10)
206 self.assertEquals(c.a, 10)
207 self.assertEquals(c.has_key('b'), False)
207 self.assertEquals('b' in c, False)
208
208
209 def test_auto_section(self):
209 def test_auto_section(self):
210 c = Config()
210 c = Config()
211 self.assertEquals(c.has_key('A'), True)
211 self.assertEquals('A' in c, True)
212 self.assertEquals(c._has_section('A'), False)
212 self.assertEquals(c._has_section('A'), False)
213 A = c.A
213 A = c.A
214 A.foo = 'hi there'
214 A.foo = 'hi there'
@@ -164,7 +164,7 b' class AliasManager(Configurable):'
164 self.alias_table[name] = (nargs, cmd)
164 self.alias_table[name] = (nargs, cmd)
165
165
166 def undefine_alias(self, name):
166 def undefine_alias(self, name):
167 if self.alias_table.has_key(name):
167 if name in self.alias_table:
168 del self.alias_table[name]
168 del self.alias_table[name]
169
169
170 def validate_alias(self, name, cmd):
170 def validate_alias(self, name, cmd):
@@ -102,7 +102,7 b' class DisplayPublisher(Configurable):'
102 """
102 """
103
103
104 # The default is to simply write the plain text data using io.stdout.
104 # The default is to simply write the plain text data using io.stdout.
105 if data.has_key('text/plain'):
105 if 'text/plain' in data:
106 print(data['text/plain'], file=io.stdout)
106 print(data['text/plain'], file=io.stdout)
107
107
108 def clear_output(self, stdout=True, stderr=True, other=True):
108 def clear_output(self, stdout=True, stderr=True, other=True):
@@ -228,7 +228,7 b' class CodeMagics(Magics):'
228
228
229 if opts_prev:
229 if opts_prev:
230 args = '_%s' % last_call[0]
230 args = '_%s' % last_call[0]
231 if not shell.user_ns.has_key(args):
231 if args not in shell.user_ns:
232 args = last_call[1]
232 args = last_call[1]
233
233
234 # use last_call to remember the state of the previous call, but don't
234 # use last_call to remember the state of the previous call, but don't
@@ -263,7 +263,7 b' python-profiler package from non-free.""")'
263 print '\n*** Profile printout saved to text file',\
263 print '\n*** Profile printout saved to text file',\
264 repr(text_file)+'.',sys_exit
264 repr(text_file)+'.',sys_exit
265
265
266 if opts.has_key('r'):
266 if 'r' in opts:
267 return stats
267 return stats
268 else:
268 else:
269 return None
269 return None
@@ -214,9 +214,9 b' class NamespaceMagics(Magics):'
214 psearch = shell.inspector.psearch
214 psearch = shell.inspector.psearch
215
215
216 # select case options
216 # select case options
217 if opts.has_key('i'):
217 if 'i' in opts:
218 ignore_case = True
218 ignore_case = True
219 elif opts.has_key('c'):
219 elif 'c' in opts:
220 ignore_case = False
220 ignore_case = False
221 else:
221 else:
222 ignore_case = not shell.wildcards_case_sensitive
222 ignore_case = not shell.wildcards_case_sensitive
@@ -656,7 +656,7 b' class NamespaceMagics(Magics):'
656
656
657 opts, regex = self.parse_options(parameter_s,'f')
657 opts, regex = self.parse_options(parameter_s,'f')
658
658
659 if opts.has_key('f'):
659 if 'f' in opts:
660 ans = True
660 ans = True
661 else:
661 else:
662 try:
662 try:
@@ -35,7 +35,7 b' class PluginManager(Configurable):'
35 def register_plugin(self, name, plugin):
35 def register_plugin(self, name, plugin):
36 if not isinstance(plugin, Plugin):
36 if not isinstance(plugin, Plugin):
37 raise TypeError('Expected Plugin, got: %r' % plugin)
37 raise TypeError('Expected Plugin, got: %r' % plugin)
38 if self.plugins.has_key(name):
38 if name in self.plugins:
39 raise KeyError('Plugin with name already exists: %r' % name)
39 raise KeyError('Plugin with name already exists: %r' % name)
40 self.plugins[name] = plugin
40 self.plugins[name] = plugin
41
41
@@ -892,7 +892,7 b' class VerboseTB(TBTools):'
892 for name_full in unique_names:
892 for name_full in unique_names:
893 name_base = name_full.split('.',1)[0]
893 name_base = name_full.split('.',1)[0]
894 if name_base in frame.f_code.co_varnames:
894 if name_base in frame.f_code.co_varnames:
895 if locals.has_key(name_base):
895 if name_base in locals:
896 try:
896 try:
897 value = repr(eval(name_full,locals))
897 value = repr(eval(name_full,locals))
898 except:
898 except:
@@ -901,7 +901,7 b' class VerboseTB(TBTools):'
901 value = undefined
901 value = undefined
902 name = tpl_local_var % name_full
902 name = tpl_local_var % name_full
903 else:
903 else:
904 if frame.f_globals.has_key(name_base):
904 if name_base in frame.f_globals:
905 try:
905 try:
906 value = repr(eval(name_full,frame.f_globals))
906 value = repr(eval(name_full,frame.f_globals))
907 except:
907 except:
@@ -119,7 +119,7 b' class StoreMagics(Magics):'
119 ip = self.shell
119 ip = self.shell
120 db = ip.db
120 db = ip.db
121 # delete
121 # delete
122 if opts.has_key('d'):
122 if 'd' in opts:
123 try:
123 try:
124 todel = args[0]
124 todel = args[0]
125 except IndexError:
125 except IndexError:
@@ -130,11 +130,11 b' class StoreMagics(Magics):'
130 except:
130 except:
131 raise UsageError("Can't delete variable '%s'" % todel)
131 raise UsageError("Can't delete variable '%s'" % todel)
132 # reset
132 # reset
133 elif opts.has_key('z'):
133 elif 'z' in opts:
134 for k in db.keys('autorestore/*'):
134 for k in db.keys('autorestore/*'):
135 del db[k]
135 del db[k]
136
136
137 elif opts.has_key('r'):
137 elif 'r' in opts:
138 refresh_variables(ip)
138 refresh_variables(ip)
139
139
140
140
@@ -1832,7 +1832,7 b' def which (filename):'
1832 if os.access (filename, os.X_OK):
1832 if os.access (filename, os.X_OK):
1833 return filename
1833 return filename
1834
1834
1835 if not os.environ.has_key('PATH') or os.environ['PATH'] == '':
1835 if 'PATH' not in os.environ or os.environ['PATH'] == '':
1836 p = os.defpath
1836 p = os.defpath
1837 else:
1837 else:
1838 p = os.environ['PATH']
1838 p = os.environ['PATH']
@@ -216,13 +216,13 b' class IPythonWidget(FrontendWidget):'
216 content = msg['content']
216 content = msg['content']
217 prompt_number = content.get('execution_count', 0)
217 prompt_number = content.get('execution_count', 0)
218 data = content['data']
218 data = content['data']
219 if data.has_key('text/html'):
219 if 'text/html' in data:
220 self._append_plain_text(self.output_sep, True)
220 self._append_plain_text(self.output_sep, True)
221 self._append_html(self._make_out_prompt(prompt_number), True)
221 self._append_html(self._make_out_prompt(prompt_number), True)
222 html = data['text/html']
222 html = data['text/html']
223 self._append_plain_text('\n', True)
223 self._append_plain_text('\n', True)
224 self._append_html(html + self.output_sep2, True)
224 self._append_html(html + self.output_sep2, True)
225 elif data.has_key('text/plain'):
225 elif 'text/plain' in data:
226 self._append_plain_text(self.output_sep, True)
226 self._append_plain_text(self.output_sep, True)
227 self._append_html(self._make_out_prompt(prompt_number), True)
227 self._append_html(self._make_out_prompt(prompt_number), True)
228 text = data['text/plain']
228 text = data['text/plain']
@@ -245,10 +245,10 b' class IPythonWidget(FrontendWidget):'
245 metadata = msg['content']['metadata']
245 metadata = msg['content']['metadata']
246 # In the regular IPythonWidget, we simply print the plain text
246 # In the regular IPythonWidget, we simply print the plain text
247 # representation.
247 # representation.
248 if data.has_key('text/html'):
248 if 'text/html' in data:
249 html = data['text/html']
249 html = data['text/html']
250 self._append_html(html, True)
250 self._append_html(html, True)
251 elif data.has_key('text/plain'):
251 elif 'text/plain' in data:
252 text = data['text/plain']
252 text = data['text/plain']
253 self._append_plain_text(text, True)
253 self._append_plain_text(text, True)
254 # This newline seems to be needed for text and html output.
254 # This newline seems to be needed for text and html output.
@@ -117,15 +117,15 b' class RichIPythonWidget(IPythonWidget):'
117 content = msg['content']
117 content = msg['content']
118 prompt_number = content.get('execution_count', 0)
118 prompt_number = content.get('execution_count', 0)
119 data = content['data']
119 data = content['data']
120 if data.has_key('image/svg+xml'):
120 if 'image/svg+xml' in data:
121 self._pre_image_append(msg, prompt_number)
121 self._pre_image_append(msg, prompt_number)
122 self._append_svg(data['image/svg+xml'], True)
122 self._append_svg(data['image/svg+xml'], True)
123 self._append_html(self.output_sep2, True)
123 self._append_html(self.output_sep2, True)
124 elif data.has_key('image/png'):
124 elif 'image/png' in data:
125 self._pre_image_append(msg, prompt_number)
125 self._pre_image_append(msg, prompt_number)
126 self._append_png(decodestring(data['image/png'].encode('ascii')), True)
126 self._append_png(decodestring(data['image/png'].encode('ascii')), True)
127 self._append_html(self.output_sep2, True)
127 self._append_html(self.output_sep2, True)
128 elif data.has_key('image/jpeg') and self._jpg_supported:
128 elif 'image/jpeg' in data and self._jpg_supported:
129 self._pre_image_append(msg, prompt_number)
129 self._pre_image_append(msg, prompt_number)
130 self._append_jpg(decodestring(data['image/jpeg'].encode('ascii')), True)
130 self._append_jpg(decodestring(data['image/jpeg'].encode('ascii')), True)
131 self._append_html(self.output_sep2, True)
131 self._append_html(self.output_sep2, True)
@@ -142,17 +142,17 b' class RichIPythonWidget(IPythonWidget):'
142 metadata = msg['content']['metadata']
142 metadata = msg['content']['metadata']
143 # Try to use the svg or html representations.
143 # Try to use the svg or html representations.
144 # FIXME: Is this the right ordering of things to try?
144 # FIXME: Is this the right ordering of things to try?
145 if data.has_key('image/svg+xml'):
145 if 'image/svg+xml' in data:
146 self.log.debug("display: %s", msg.get('content', ''))
146 self.log.debug("display: %s", msg.get('content', ''))
147 svg = data['image/svg+xml']
147 svg = data['image/svg+xml']
148 self._append_svg(svg, True)
148 self._append_svg(svg, True)
149 elif data.has_key('image/png'):
149 elif 'image/png' in data:
150 self.log.debug("display: %s", msg.get('content', ''))
150 self.log.debug("display: %s", msg.get('content', ''))
151 # PNG data is base64 encoded as it passes over the network
151 # PNG data is base64 encoded as it passes over the network
152 # in a JSON structure so we decode it.
152 # in a JSON structure so we decode it.
153 png = decodestring(data['image/png'].encode('ascii'))
153 png = decodestring(data['image/png'].encode('ascii'))
154 self._append_png(png, True)
154 self._append_png(png, True)
155 elif data.has_key('image/jpeg') and self._jpg_supported:
155 elif 'image/jpeg' in data and self._jpg_supported:
156 self.log.debug("display: %s", msg.get('content', ''))
156 self.log.debug("display: %s", msg.get('content', ''))
157 jpg = decodestring(data['image/jpeg'].encode('ascii'))
157 jpg = decodestring(data['image/jpeg'].encode('ascii'))
158 self._append_jpg(jpg, True)
158 self._append_jpg(jpg, True)
@@ -77,7 +77,7 b' def get_app_wx(*args, **kwargs):'
77 import wx
77 import wx
78 app = wx.GetApp()
78 app = wx.GetApp()
79 if app is None:
79 if app is None:
80 if not kwargs.has_key('redirect'):
80 if 'redirect' not in kwargs:
81 kwargs['redirect'] = False
81 kwargs['redirect'] = False
82 app = wx.PySimpleApp(*args, **kwargs)
82 app = wx.PySimpleApp(*args, **kwargs)
83 return app
83 return app
@@ -176,7 +176,7 b' class InputHookManager(object):'
176 """
176 """
177 if gui is None:
177 if gui is None:
178 self._apps = {}
178 self._apps = {}
179 elif self._apps.has_key(gui):
179 elif gui in self._apps:
180 del self._apps[gui]
180 del self._apps[gui]
181
181
182 def enable_wx(self, app=None):
182 def enable_wx(self, app=None):
@@ -225,7 +225,7 b' class InputHookManager(object):'
225
225
226 This merely sets PyOS_InputHook to NULL.
226 This merely sets PyOS_InputHook to NULL.
227 """
227 """
228 if self._apps.has_key(GUI_WX):
228 if GUI_WX in self._apps:
229 self._apps[GUI_WX]._in_event_loop = False
229 self._apps[GUI_WX]._in_event_loop = False
230 self.clear_inputhook()
230 self.clear_inputhook()
231
231
@@ -265,7 +265,7 b' class InputHookManager(object):'
265
265
266 This merely sets PyOS_InputHook to NULL.
266 This merely sets PyOS_InputHook to NULL.
267 """
267 """
268 if self._apps.has_key(GUI_QT4):
268 if GUI_QT4 in self._apps:
269 self._apps[GUI_QT4]._in_event_loop = False
269 self._apps[GUI_QT4]._in_event_loop = False
270 self.clear_inputhook()
270 self.clear_inputhook()
271
271
@@ -364,7 +364,7 b' class InputHookManager(object):'
364 glut_close, glut_display, \
364 glut_close, glut_display, \
365 glut_idle, inputhook_glut
365 glut_idle, inputhook_glut
366
366
367 if not self._apps.has_key( GUI_GLUT ):
367 if GUI_GLUT not in self._apps:
368 glut.glutInit( sys.argv )
368 glut.glutInit( sys.argv )
369 glut.glutInitDisplayMode( glut_display_mode )
369 glut.glutInitDisplayMode( glut_display_mode )
370 # This is specific to freeglut
370 # This is specific to freeglut
@@ -133,7 +133,7 b' class DictDB(BaseDB):'
133
133
134 def add_record(self, msg_id, rec):
134 def add_record(self, msg_id, rec):
135 """Add a new Task Record, by msg_id."""
135 """Add a new Task Record, by msg_id."""
136 if self._records.has_key(msg_id):
136 if msg_id in self._records:
137 raise KeyError("Already have msg_id %r"%(msg_id))
137 raise KeyError("Already have msg_id %r"%(msg_id))
138 self._records[msg_id] = rec
138 self._records[msg_id] = rec
139
139
@@ -243,11 +243,11 b' def _pull(keys):'
243 user_ns = globals()
243 user_ns = globals()
244 if isinstance(keys, (list,tuple, set)):
244 if isinstance(keys, (list,tuple, set)):
245 for key in keys:
245 for key in keys:
246 if not user_ns.has_key(key):
246 if key not in user_ns:
247 raise NameError("name '%s' is not defined"%key)
247 raise NameError("name '%s' is not defined"%key)
248 return map(user_ns.get, keys)
248 return map(user_ns.get, keys)
249 else:
249 else:
250 if not user_ns.has_key(keys):
250 if keys not in user_ns:
251 raise NameError("name '%s' is not defined"%keys)
251 raise NameError("name '%s' is not defined"%keys)
252 return user_ns.get(keys)
252 return user_ns.get(keys)
253
253
@@ -84,7 +84,7 b' class Struct(dict):'
84 ...
84 ...
85 this is not allowed
85 this is not allowed
86 """
86 """
87 if not self._allownew and not self.has_key(key):
87 if not self._allownew and key not in self:
88 raise KeyError(
88 raise KeyError(
89 "can't create new attribute %s when allow_new_attr(False)" % key)
89 "can't create new attribute %s when allow_new_attr(False)" % key)
90 dict.__setitem__(self, key, value)
90 dict.__setitem__(self, key, value)
@@ -212,7 +212,7 b' class Struct(dict):'
212 {'b': 30}
212 {'b': 30}
213 """
213 """
214 for k in other.keys():
214 for k in other.keys():
215 if self.has_key(k):
215 if k in self:
216 del self[k]
216 del self[k]
217 return self
217 return self
218
218
@@ -262,7 +262,7 b' class Struct(dict):'
262 >>> s.hasattr('get')
262 >>> s.hasattr('get')
263 False
263 False
264 """
264 """
265 return self.has_key(key)
265 return key in self
266
266
267 def allow_new_attr(self, allow = True):
267 def allow_new_attr(self, allow = True):
268 """Set whether new attributes can be created in this Struct.
268 """Set whether new attributes can be created in this Struct.
@@ -465,7 +465,7 b' class HasTraits(object):'
465
465
466
466
467 def _add_notifiers(self, handler, name):
467 def _add_notifiers(self, handler, name):
468 if not self._trait_notifiers.has_key(name):
468 if name not in self._trait_notifiers:
469 nlist = []
469 nlist = []
470 self._trait_notifiers[name] = nlist
470 self._trait_notifiers[name] = nlist
471 else:
471 else:
@@ -474,7 +474,7 b' class HasTraits(object):'
474 nlist.append(handler)
474 nlist.append(handler)
475
475
476 def _remove_notifiers(self, handler, name):
476 def _remove_notifiers(self, handler, name):
477 if self._trait_notifiers.has_key(name):
477 if name in self._trait_notifiers:
478 nlist = self._trait_notifiers[name]
478 nlist = self._trait_notifiers[name]
479 try:
479 try:
480 index = nlist.index(handler)
480 index = nlist.index(handler)
@@ -269,10 +269,11 b" if 'setuptools' in sys.modules:"
269 # so we explicitly disable some 2to3 fixes to be sure we aren't forgetting
269 # so we explicitly disable some 2to3 fixes to be sure we aren't forgetting
270 # anything.
270 # anything.
271 setuptools_extra_args['use_2to3_exclude_fixers'] = [
271 setuptools_extra_args['use_2to3_exclude_fixers'] = [
272 'lib2to3.fixes.fix_except',
273 'lib2to3.fixes.fix_apply',
272 'lib2to3.fixes.fix_apply',
274 'lib2to3.fixes.fix_repr',
273 'lib2to3.fixes.fix_except',
274 'lib2to3.fixes.fix_has_key',
275 'lib2to3.fixes.fix_next',
275 'lib2to3.fixes.fix_next',
276 'lib2to3.fixes.fix_repr',
276 ]
277 ]
277 from setuptools.command.build_py import build_py
278 from setuptools.command.build_py import build_py
278 setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
279 setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
General Comments 0
You need to be logged in to leave comments. Login now