Author: strank Date: 2008-07-23 21:18:19 +0200 (Wed, 23 Jul 2008) New Revision: 5607 Modified: branches/abolish-userstring/languages/__init__.py branches/abolish-userstring/parsers/__init__.py branches/abolish-userstring/parsers/rst/directives/__init__.py branches/abolish-userstring/parsers/rst/directives/admonitions.py branches/abolish-userstring/parsers/rst/directives/body.py branches/abolish-userstring/parsers/rst/directives/images.py branches/abolish-userstring/parsers/rst/directives/misc.py branches/abolish-userstring/parsers/rst/directives/parts.py branches/abolish-userstring/parsers/rst/directives/tables.py branches/abolish-userstring/parsers/rst/languages/__init__.py branches/abolish-userstring/parsers/rst/roles.py branches/abolish-userstring/parsers/rst/states.py branches/abolish-userstring/readers/__init__.py branches/abolish-userstring/readers/python/__init__.py branches/abolish-userstring/readers/python/moduleparser.py branches/abolish-userstring/transforms/frontmatter.py branches/abolish-userstring/transforms/parts.py branches/abolish-userstring/transforms/references.py branches/abolish-userstring/writers/__init__.py branches/abolish-userstring/writers/html4css1/__init__.py branches/abolish-userstring/writers/latex2e/__init__.py branches/abolish-userstring/writers/newlatex2e/__init__.py branches/abolish-userstring/writers/s5_html/__init__.py trunk/docutils/extras/optparse.py trunk/docutils/test/DocutilsTestSupport.py trunk/docutils/test/docutils_difflib.py trunk/docutils/test/test_dependencies.py trunk/docutils/test/test_functional.py trunk/docutils/test/test_language.py trunk/docutils/test/test_nodes.py trunk/docutils/test/test_settings.py trunk/docutils/tools/dev/unicode2rstsubs.py Log: Replace all has_key with the in operator. Modified: branches/abolish-userstring/languages/__init__.py =================================================================== --- branches/abolish-userstring/languages/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/languages/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -14,7 +14,7 @@ _languages = {} def get_language(language_code): - if _languages.has_key(language_code): + if language_code in _languages: return _languages[language_code] module = __import__(language_code, globals(), locals()) _languages[language_code] = module Modified: branches/abolish-userstring/parsers/__init__.py =================================================================== --- branches/abolish-userstring/parsers/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -41,7 +41,7 @@ def get_parser_class(parser_name): """Return the Parser class from the `parser_name` module.""" parser_name = parser_name.lower() - if _parser_aliases.has_key(parser_name): + if parser_name in _parser_aliases: parser_name = _parser_aliases[parser_name] module = __import__(parser_name, globals(), locals()) return module.Parser Modified: branches/abolish-userstring/parsers/rst/directives/__init__.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -76,7 +76,7 @@ normname = directive_name.lower() messages = [] msg_text = [] - if _directives.has_key(normname): + if normname in _directives: return _directives[normname], messages canonicalname = None try: Modified: branches/abolish-userstring/parsers/rst/directives/admonitions.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/admonitions.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/admonitions.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -35,7 +35,7 @@ self.lineno) admonition_node += nodes.title(title_text, '', *textnodes) admonition_node += messages - if self.options.has_key('class'): + if 'class' in self.options: classes = self.options['class'] else: classes = ['admonition-' + nodes.make_id(title_text)] Modified: branches/abolish-userstring/parsers/rst/directives/body.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/body.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/body.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -39,7 +39,7 @@ textnodes, messages = self.state.inline_text(title_text, self.lineno) titles = [nodes.title(title_text, '', *textnodes)] # Sidebar uses this code. - if self.options.has_key('subtitle'): + if 'subtitle' in self.options: textnodes, more_messages = self.state.inline_text( self.options['subtitle'], self.lineno) titles.append(nodes.subtitle(self.options['subtitle'], '', Modified: branches/abolish-userstring/parsers/rst/directives/images.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/images.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/images.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -46,7 +46,7 @@ 'class': directives.class_option} def run(self): - if self.options.has_key('align'): + if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: @@ -66,7 +66,7 @@ reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None - if self.options.has_key('target'): + if 'target' in self.options: block = states.escape2null( self.options['target']).splitlines() block = [line for line in block] Modified: branches/abolish-userstring/parsers/rst/directives/misc.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/misc.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/misc.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -86,7 +86,7 @@ raise self.severe('Problem with "end-before" option of "%s" ' 'directive:\nText not found.' % self.name) include_text = include_text[:before_index] - if self.options.has_key('literal'): + if 'literal' in self.options: literal_block = nodes.literal_block(include_text, include_text, source=path) literal_block.line = 1 @@ -120,20 +120,20 @@ def run(self): if (not self.state.document.settings.raw_enabled or (not self.state.document.settings.file_insertion_enabled - and (self.options.has_key('file') - or self.options.has_key('url')))): + and ('file' in self.options + or 'url' in self.options))): raise self.warning('"%s" directive disabled.' % self.name) attributes = {'format': ' '.join(self.arguments[0].lower().split())} encoding = self.options.get( 'encoding', self.state.document.settings.input_encoding) if self.content: - if self.options.has_key('file') or self.options.has_key('url'): + if 'file' in self.options or 'url' in self.options: raise self.error( '"%s" directive may not both specify an external file ' 'and have content.' % self.name) text = '\n'.join(self.content) - elif self.options.has_key('file'): - if self.options.has_key('url'): + elif 'file' in self.options: + if 'url' in self.options: raise self.error( 'The "file" and "url" options may not be simultaneously ' 'specified for the "%s" directive.' % self.name) @@ -159,7 +159,7 @@ 'Problem with "%s" directive:\n%s: %s' % (self.name, error.__class__.__name__, error)) attributes['source'] = path - elif self.options.has_key('url'): + elif 'url' in self.options: source = self.options['url'] # Do not import urllib2 at the top of the module because # it may fail due to broken SSL dependencies, and it takes @@ -244,12 +244,12 @@ 'Invalid context: the "%s" directive can only be used within ' 'a substitution definition.' % self.name) substitution_definition = self.state_machine.node - if self.options.has_key('trim'): + if 'trim' in self.options: substitution_definition.attributes['ltrim'] = 1 substitution_definition.attributes['rtrim'] = 1 - if self.options.has_key('ltrim'): + if 'ltrim' in self.options: substitution_definition.attributes['ltrim'] = 1 - if self.options.has_key('rtrim'): + if 'rtrim' in self.options: substitution_definition.attributes['rtrim'] = 1 codes = self.comment_pattern.split(self.arguments[0])[0].split() element = nodes.Element() @@ -349,7 +349,7 @@ nodes.literal_block(self.block_text, self.block_text), line=self.lineno) return messages + [error] - if not options.has_key('class'): + if 'class' not in options: try: options['class'] = directives.class_option(new_role_name) except ValueError, detail: @@ -373,7 +373,7 @@ def run(self): if not self.arguments: - if roles._roles.has_key(''): + if '' in roles._roles: # restore the "default" default role del roles._roles[''] return [] Modified: branches/abolish-userstring/parsers/rst/directives/parts.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/parts.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/parts.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -57,13 +57,13 @@ title = nodes.title(title_text, '', *text_nodes) else: messages = [] - if self.options.has_key('local'): + if 'local' in self.options: title = None else: title = nodes.title('', language.labels['contents']) topic = nodes.topic(classes=['contents']) topic['classes'] += self.options.get('class', []) - if self.options.has_key('local'): + if 'local' in self.options: topic['classes'].append('local') if title: name = title.astext() Modified: branches/abolish-userstring/parsers/rst/directives/tables.py =================================================================== --- branches/abolish-userstring/parsers/rst/directives/tables.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/directives/tables.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -49,7 +49,7 @@ source = self.state_machine.get_source(self.lineno - 1) table_head = [] max_header_cols = 0 - if self.options.has_key('header'): # separate table header in option + if 'header' in self.options: # separate table header in option rows, max_header_cols = self.parse_csv_data_into_rows( self.options['header'].split('\n'), self.HeaderDialect(), source) @@ -88,7 +88,7 @@ raise SystemMessagePropagation(error) def get_column_widths(self, max_cols): - if self.options.has_key('widths'): + if 'widths' in self.options: col_widths = self.options['widths'] if len(col_widths) != max_cols: error = self.state_machine.reporter.error( @@ -170,13 +170,13 @@ quoting = csv.QUOTE_MINIMAL def __init__(self, options): - if options.has_key('delim'): + if 'delim' in options: self.delimiter = str(options['delim']) - if options.has_key('keepspace'): + if 'keepspace' in options: self.skipinitialspace = False - if options.has_key('quote'): + if 'quote' in options: self.quotechar = str(options['quote']) - if options.has_key('escape'): + if 'escape' in options: self.doublequote = False self.escapechar = str(options['escape']) csv.Dialect.__init__(self) @@ -206,8 +206,8 @@ def run(self): try: if (not self.state.document.settings.file_insertion_enabled - and (self.options.has_key('file') - or self.options.has_key('url'))): + and ('file' in self.options + or 'url' in self.options)): warning = self.state_machine.reporter.warning( 'File and URL access deactivated; ignoring "%s" ' 'directive.' % self.name, nodes.literal_block( @@ -253,7 +253,7 @@ 'encoding', self.state.document.settings.input_encoding) if self.content: # CSV data is from directive content. - if self.options.has_key('file') or self.options.has_key('url'): + if 'file' in self.options or 'url' in self.options: error = self.state_machine.reporter.error( '"%s" directive may not both specify an external file and' ' have content.' % self.name, nodes.literal_block( @@ -261,9 +261,9 @@ raise SystemMessagePropagation(error) source = self.content.source(0) csv_data = self.content - elif self.options.has_key('file'): + elif 'file' in self.options: # CSV data is from an external file. - if self.options.has_key('url'): + if 'url' in self.options: error = self.state_machine.reporter.error( 'The "file" and "url" options may not be simultaneously' ' specified for the "%s" directive.' % self.name, @@ -289,7 +289,7 @@ % (self.name, error), nodes.literal_block( self.block_text, self.block_text), line=self.lineno) raise SystemMessagePropagation(severe) - elif self.options.has_key('url'): + elif 'url' in self.options: # CSV data is from a URL. # Do not import urllib2 at the top of the module because # it may fail due to broken SSL dependencies, and it takes Modified: branches/abolish-userstring/parsers/rst/languages/__init__.py =================================================================== --- branches/abolish-userstring/parsers/rst/languages/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/languages/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -15,7 +15,7 @@ _languages = {} def get_language(language_code): - if _languages.has_key(language_code): + if language_code in _languages: return _languages[language_code] try: module = __import__(language_code, globals(), locals()) Modified: branches/abolish-userstring/parsers/rst/roles.py =================================================================== --- branches/abolish-userstring/parsers/rst/roles.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/roles.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -101,7 +101,7 @@ messages = [] msg_text = [] - if _roles.has_key(normname): + if normname in _roles: return _roles[normname], messages if role_name: @@ -135,7 +135,7 @@ messages.append(message) # Look the role up in the registry, and return it. - if _role_registry.has_key(canonicalname): + if canonicalname in _role_registry: role_fn = _role_registry[canonicalname] register_local_role(normname, role_fn) return role_fn, messages @@ -171,7 +171,7 @@ """ if not hasattr(role_fn, 'options') or role_fn.options is None: role_fn.options = {'class': directives.class_option} - elif not role_fn.options.has_key('class'): + elif 'class' not in role_fn.options: role_fn.options['class'] = directives.class_option def register_generic_role(canonical_name, node_class): @@ -294,7 +294,7 @@ register_canonical_role('rfc-reference', rfc_reference_role) def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]): - if not options.has_key('format'): + if 'format' not in options: msg = inliner.reporter.error( 'No format (Writer name) is associated with this role: "%s".\n' 'The "raw" role cannot be used directly.\n' @@ -340,7 +340,7 @@ Auxiliary function to set options['classes'] and delete options['class']. """ - if options.has_key('class'): - assert not options.has_key('classes') + if 'class' in options: + assert 'classes' not in options options['classes'] = options['class'] del options['class'] Modified: branches/abolish-userstring/parsers/rst/states.py =================================================================== --- branches/abolish-userstring/parsers/rst/states.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/parsers/rst/states.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -901,8 +901,8 @@ return self.reference(match, lineno, anonymous=1) def standalone_uri(self, match, lineno): - if not match.group('scheme') or urischemes.schemes.has_key( - match.group('scheme').lower()): + if (not match.group('scheme') + or match.group('scheme').lower() in urischemes.schemes): if match.group('email'): addscheme = 'mailto:' else: Modified: branches/abolish-userstring/readers/__init__.py =================================================================== --- branches/abolish-userstring/readers/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/readers/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -101,7 +101,7 @@ def get_reader_class(reader_name): """Return the Reader class from the `reader_name` module.""" reader_name = reader_name.lower() - if _reader_aliases.has_key(reader_name): + if reader_name in _reader_aliases: reader_name = _reader_aliases[reader_name] module = __import__(reader_name, globals(), locals()) return module.Reader Modified: branches/abolish-userstring/readers/python/__init__.py =================================================================== --- branches/abolish-userstring/readers/python/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/readers/python/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -94,7 +94,7 @@ visitation, so parser instances are cached. """ parser_name = parsers._parser_aliases.get(parser_name, parser_name) - if not self.parsers.has_key(parser_name): + if parser_name not in self.parsers: cls = parsers.get_parser_class(parser_name) self.parsers[parser_name] = cls() return self.parsers[parser_name] Modified: branches/abolish-userstring/readers/python/moduleparser.py =================================================================== --- branches/abolish-userstring/readers/python/moduleparser.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/readers/python/moduleparser.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -525,14 +525,14 @@ def note_token(self): if self.type == tokenize.NL: return - del_ws = self.del_ws_prefix.has_key(self.string) - append_ws = not self.no_ws_suffix.has_key(self.string) - if self.openers.has_key(self.string): + del_ws = self.string in self.del_ws_prefix + append_ws = self.string not in self.no_ws_suffix + if self.string in self.openers: self.stack.append(self.string) if (self._type == token.NAME - or self.closers.has_key(self._string)): + or self._string in self.closers): del_ws = 1 - elif self.closers.has_key(self.string): + elif self.string in self.closers: assert self.stack[-1] == self.closers[self.string] self.stack.pop() elif self.string == '`': Modified: branches/abolish-userstring/transforms/frontmatter.py =================================================================== --- branches/abolish-userstring/transforms/frontmatter.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/transforms/frontmatter.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -388,7 +388,7 @@ try: name = field[0][0].astext() normedname = nodes.fully_normalize_name(name) - if not (len(field) == 2 and bibliofields.has_key(normedname) + if not (len(field) == 2 and normedname in bibliofields and self.check_empty_biblio_field(field, name)): raise TransformError canonical = bibliofields[normedname] Modified: branches/abolish-userstring/transforms/parts.py =================================================================== --- branches/abolish-userstring/transforms/parts.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/transforms/parts.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -80,7 +80,7 @@ def apply(self): details = self.startnode.details - if details.has_key('local'): + if 'local' in details: startnode = self.startnode.parent.parent while not (isinstance(startnode, nodes.section) or isinstance(startnode, nodes.document)): @@ -89,7 +89,7 @@ else: startnode = self.document self.toc_id = self.startnode.parent['ids'][0] - if details.has_key('backlinks'): + if 'backlinks' in details: self.backlinks = details['backlinks'] else: self.backlinks = self.document.settings.toc_backlinks Modified: branches/abolish-userstring/transforms/references.py =================================================================== --- branches/abolish-userstring/transforms/references.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/transforms/references.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -240,7 +240,7 @@ del target.multiply_indirect if reftarget.hasattr('refuri'): target['refuri'] = reftarget['refuri'] - if target.has_key('refid'): + if 'refid' in target: del target['refid'] elif reftarget.hasattr('refid'): target['refid'] = reftarget['refid'] @@ -257,7 +257,7 @@ target.resolved = 1 def nonexistent_indirect_target(self, target): - if self.document.nameids.has_key(target['refname']): + if target['refname'] in self.document.nameids: self.indirect_target_error(target, 'which is a duplicate, and ' 'cannot be used as a unique reference') else: @@ -505,7 +505,7 @@ while 1: label = str(startnum) startnum += 1 - if not self.document.nameids.has_key(label): + if label not in self.document.nameids: break footnote.insert(0, nodes.label('', label)) for name in footnote['names']: @@ -600,12 +600,12 @@ """ for footnote in self.document.footnotes: for label in footnote['names']: - if self.document.footnote_refs.has_key(label): + if label in self.document.footnote_refs: reflist = self.document.footnote_refs[label] self.resolve_references(footnote, reflist) for citation in self.document.citations: for label in citation['names']: - if self.document.citation_refs.has_key(label): + if label in self.document.citation_refs: reflist = self.document.citation_refs[label] self.resolve_references(citation, reflist) @@ -666,11 +666,11 @@ for ref in subreflist: refname = ref['refname'] key = None - if defs.has_key(refname): + if refname in defs: key = refname else: normed_name = refname.lower() - if normed.has_key(normed_name): + if normed_name in normed: key = normed[normed_name] if key is None: msg = self.document.reporter.error( @@ -686,14 +686,14 @@ subdef = defs[key] parent = ref.parent index = parent.index(ref) - if (subdef.attributes.has_key('ltrim') - or subdef.attributes.has_key('trim')): + if ('ltrim' in subdef.attributes + or 'trim' in subdef.attributes): if index > 0 and isinstance(parent[index - 1], nodes.Text): parent.replace(parent[index - 1], parent[index - 1].rstrip()) - if (subdef.attributes.has_key('rtrim') - or subdef.attributes.has_key('trim')): + if ('rtrim' in subdef.attributes + or 'trim' in subdef.attributes): if (len(parent) > index + 1 and isinstance(parent[index + 1], nodes.Text)): parent.replace(parent[index + 1], @@ -764,7 +764,7 @@ continue footnote = self.make_target_footnote(target['refuri'], refs, notes) - if not notes.has_key(target['refuri']): + if target['refuri'] not in notes: notes[target['refuri']] = footnote nodelist.append(footnote) # Take care of anonymous references. @@ -774,13 +774,13 @@ if ref.hasattr('refuri'): footnote = self.make_target_footnote(ref['refuri'], [ref], notes) - if not notes.has_key(ref['refuri']): + if ref['refuri'] not in notes: notes[ref['refuri']] = footnote nodelist.append(footnote) self.startnode.replace_self(nodelist) def make_target_footnote(self, refuri, refs, notes): - if notes.has_key(refuri): # duplicate? + if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] @@ -873,7 +873,7 @@ if resolver_function(node): break else: - if self.document.nameids.has_key(refname): + if refname in self.document.nameids: msg = self.document.reporter.error( 'Duplicate target name, cannot be used as a unique ' 'reference: "%s".' % (node['refname']), base_node=node) Modified: branches/abolish-userstring/writers/__init__.py =================================================================== --- branches/abolish-userstring/writers/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/writers/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -127,7 +127,7 @@ def get_writer_class(writer_name): """Return the Writer class from the `writer_name` module.""" writer_name = writer_name.lower() - if _writer_aliases.has_key(writer_name): + if writer_name in _writer_aliases: writer_name = _writer_aliases[writer_name] module = __import__(writer_name, globals(), locals()) return module.Writer Modified: branches/abolish-userstring/writers/html4css1/__init__.py =================================================================== --- branches/abolish-userstring/writers/html4css1/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/writers/html4css1/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -353,13 +353,13 @@ for (name, value) in attributes.items(): atts[name.lower()] = value classes = node.get('classes', []) - if atts.has_key('class'): + if 'class' in atts: classes.append(atts['class']) if classes: atts['class'] = ' '.join(classes) - assert not atts.has_key('id') + assert 'id' not in atts ids.extend(node.get('ids', [])) - if atts.has_key('ids'): + if 'ids' in atts: ids.extend(atts['ids']) del atts['ids'] if ids: @@ -731,9 +731,9 @@ tagname = 'td' del atts['class'] node.parent.column += 1 - if node.has_key('morerows'): + if 'morerows' in node: atts['rowspan'] = node['morerows'] + 1 - if node.has_key('morecols'): + if 'morecols' in node: atts['colspan'] = node['morecols'] + 1 node.parent.column += node['morecols'] self.body.append(self.starttag(node, tagname, '', **atts)) @@ -752,9 +752,9 @@ usable. """ atts = {} - if node.has_key('start'): + if 'start' in node: atts['start'] = node['start'] - if node.has_key('enumtype'): + if 'enumtype' in node: atts['class'] = node['enumtype'] # @@@ To do: prefix, suffix. How? Change prefix/suffix to a # single "format" attribute? Use CSS2? @@ -941,26 +941,26 @@ def visit_image(self, node): atts = {} atts['src'] = node['uri'] - if node.has_key('width'): + if 'width' in node: atts['width'] = node['width'] - if node.has_key('height'): + if 'height' in node: atts['height'] = node['height'] - if node.has_key('scale'): - if Image and not (node.has_key('width') - and node.has_key('height')): + if 'scale' in node: + if Image and not ('width' in node + and 'height' in node): try: im = Image.open(str(atts['src'])) except (IOError, # Source image can't be found or opened UnicodeError): # PIL doesn't like Unicode paths. pass else: - if not atts.has_key('width'): + if 'width' not in atts: atts['width'] = str(im.size[0]) - if not atts.has_key('height'): + if 'height' not in atts: atts['height'] = str(im.size[1]) del im for att_name in 'width', 'height': - if atts.has_key(att_name): + if att_name in atts: match = re.match(r'([0-9.]+)(\S*)$', atts[att_name]) assert match atts[att_name] = '%s%s' % ( @@ -968,7 +968,7 @@ match.group(2)) style = [] for att_name in 'width', 'height': - if atts.has_key(att_name): + if att_name in atts: if re.match(r'^[0-9.]+$', atts[att_name]): # Interpret unitless values as pixels. atts[att_name] += 'px' @@ -984,7 +984,7 @@ suffix = '' else: suffix = '\n' - if node.has_key('align'): + if 'align' in node: if node['align'] == 'center': # "align" attribute is set in surrounding "div" element. self.body.append('<div align="center" class="align-center">') @@ -1210,7 +1210,7 @@ def visit_reference(self, node): atts = {'class': 'reference'} - if node.has_key('refuri'): + if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): @@ -1218,7 +1218,7 @@ self.in_mailto = 1 atts['class'] += ' external' else: - assert node.has_key('refid'), \ + assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' @@ -1364,8 +1364,8 @@ self.body.append('</table>\n') def visit_target(self, node): - if not (node.has_key('refuri') or node.has_key('refid') - or node.has_key('refname')): + if not ('refuri' in node or 'refid' in node + or 'refname' in node): self.body.append(self.starttag(node, 'span', '', CLASS='target')) self.context.append('</span>') else: Modified: branches/abolish-userstring/writers/latex2e/__init__.py =================================================================== --- branches/abolish-userstring/writers/latex2e/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/writers/latex2e/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -1124,9 +1124,9 @@ self.inside_citation_reference_label = 1 else: href = '' - if node.has_key('refid'): + if 'refid' in node: href = node['refid'] - elif node.has_key('refname'): + elif 'refname' in node: href = self.document.nameids[node['refname']] self.body.append('[\\hyperlink{%s}{' % href) @@ -1343,17 +1343,17 @@ # IN WORK BUG TODO HACK continues here # multirow in LaTeX simply will enlarge the cell over several rows # (the following n if n is positive, the former if negative). - if node.has_key('morerows') and node.has_key('morecols'): + if 'morerows' in node and 'morecols' in node: raise NotImplementedError('Cells that ' 'span multiple rows *and* columns are not supported, sorry.') - if node.has_key('morerows'): + if 'morerows' in node: count = node['morerows'] + 1 self.active_table.set_rowspan(self.active_table.get_entry_number()-1,count) self.body.append('\\multirow{%d}{%s}{' % \ (count,self.active_table.get_column_width())) self.context.append('}') # BUG following rows must have empty cells. - elif node.has_key('morecols'): + elif 'morecols' in node: # the vertical bar before column is missing if it is the first column. # the one after always. if self.active_table.get_entry_number() == 1: @@ -1401,10 +1401,10 @@ 'lowerroman':'roman', 'upperroman':'Roman' } enum_suffix = "" - if node.has_key('suffix'): + if 'suffix' in node: enum_suffix = node['suffix'] enum_prefix = "" - if node.has_key('prefix'): + if 'prefix' in node: enum_prefix = node['prefix'] if self.compound_enumerators: pref = "" @@ -1416,7 +1416,7 @@ for ctype, cname in self._enumeration_counters: enum_prefix += '\\%s{%s}.' % (ctype, cname) enum_type = "arabic" - if node.has_key('enumtype'): + if 'enumtype' in node: enum_type = node['enumtype'] if enum_type in enum_style: enum_type = enum_style[enum_type] @@ -1436,7 +1436,7 @@ self.body.append('{\n') self.body.append('\\usecounter{%s}\n' % counter_name) # set start after usecounter, because it initializes to zero. - if node.has_key('start'): + if 'start' in node: self.body.append('\\addtocounter{%s}{%d}\n' \ % (counter_name,node['start']-1)) ## set rightmargin equal to leftmargin @@ -1500,7 +1500,7 @@ self.body.append(':]') def visit_figure(self, node): - if (not node.attributes.has_key('align') or + if ('align' not in node.attributes or node.attributes['align'] == 'center'): # centering does not add vertical space like center. align = '\n\\centering' @@ -1547,9 +1547,9 @@ self.body.append("\\footnotemark["+self.encode(node.astext())+"]") raise nodes.SkipNode href = '' - if node.has_key('refid'): + if 'refid' in node: href = node['refid'] - elif node.has_key('refname'): + elif 'refname' in node: href = self.document.nameids[node['refname']] format = self.settings.footnote_references if format == 'brackets': @@ -1633,18 +1633,18 @@ post = [] include_graphics_options = [] inline = isinstance(node.parent, nodes.TextElement) - if attrs.has_key('scale'): + if 'scale' in attrs: # Could also be done with ``scale`` option to # ``\includegraphics``; doing it this way for consistency. pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,)) post.append('}') - if attrs.has_key('width'): + if 'width' in attrs: include_graphics_options.append('width=%s' % ( self.latex_image_length(attrs['width']), )) - if attrs.has_key('height'): + if 'height' in attrs: include_graphics_options.append('height=%s' % ( self.latex_image_length(attrs['height']), )) - if attrs.has_key('align'): + if 'align' in attrs: align_prepost = { # By default latex aligns the top of an image. (1, 'top'): ('', ''), @@ -1870,16 +1870,16 @@ # BUG: hash_char "#" is trouble some in LaTeX. # mbox and other environment do not like the '#'. hash_char = '\\#' - if node.has_key('refuri'): + if 'refuri' in node: href = node['refuri'].replace('#',hash_char) - elif node.has_key('refid'): + elif 'refid' in node: href = hash_char + node['refid'] - elif node.has_key('refname'): + elif 'refname' in node: href = hash_char + self.document.nameids[node['refname']] else: raise AssertionError('Unknown reference.') self.body.append('\\href{%s}{' % href.replace("%", "\\%")) - if self._reference_label and not node.has_key('refuri'): + if self._reference_label and 'refuri' not in node: self.body.append('\\%s{%s}}' % (self._reference_label, href.replace(hash_char, ''))) raise nodes.SkipNode @@ -1993,8 +1993,8 @@ def visit_target(self, node): # BUG: why not (refuri or refid or refname) means not footnote ? - if not (node.has_key('refuri') or node.has_key('refid') - or node.has_key('refname')): + if not ('refuri' in node or 'refid' in node + or 'refname' in node): for id in node['ids']: self.body.append('\\hypertarget{%s}{' % id) self.context.append('}' * len(node['ids'])) Modified: branches/abolish-userstring/writers/newlatex2e/__init__.py =================================================================== --- branches/abolish-userstring/writers/newlatex2e/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/writers/newlatex2e/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -676,7 +676,7 @@ # Move IDs into TextElements. This won't work for images. # Need to review this. for node in document.traverse(nodes.Element): - if node.has_key('ids') and not isinstance(node, + if 'ids' in node and not isinstance(node, nodes.TextElement): next_text_element = node.next_node(nodes.TextElement) if next_text_element: Modified: branches/abolish-userstring/writers/s5_html/__init__.py =================================================================== --- branches/abolish-userstring/writers/s5_html/__init__.py 2008-07-23 16:03:32 UTC (rev 5606) +++ branches/abolish-userstring/writers/s5_html/__init__.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -251,7 +251,7 @@ """ source = os.path.join(source_dir, name) dest = os.path.join(dest_dir, name) - if self.theme_files_copied.has_key(dest): + if dest in self.theme_files_copied: return 1 else: self.theme_files_copied[dest] = 1 Modified: trunk/docutils/extras/optparse.py =================================================================== --- trunk/docutils/extras/optparse.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/extras/optparse.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -472,7 +472,7 @@ def _set_attrs (self, attrs): for attr in self.ATTRS: - if attrs.has_key(attr): + if attr in attrs: setattr(self, attr, attrs[attr]) del attrs[attr] else: @@ -676,7 +676,7 @@ are silently ignored. """ for attr in dir(self): - if dict.has_key(attr): + if attr in dict: dval = dict[attr] if dval is not None: setattr(self, attr, dval) @@ -786,10 +786,10 @@ def _check_conflict (self, option): conflict_opts = [] for opt in option._short_opts: - if self._short_opt.has_key(opt): + if opt in self._short_opt: conflict_opts.append((opt, self._short_opt[opt])) for opt in option._long_opts: - if self._long_opt.has_key(opt): + if opt in self._long_opt: conflict_opts.append((opt, self._long_opt[opt])) if conflict_opts: @@ -837,7 +837,7 @@ if option.dest is not None: # option has a dest, we need a default if option.default is not NO_DEFAULT: self.defaults[option.dest] = option.default - elif not self.defaults.has_key(option.dest): + elif option.dest not in self.defaults: self.defaults[option.dest] = None return option @@ -853,8 +853,8 @@ self._long_opt.get(opt_str)) def has_option (self, opt_str): - return (self._short_opt.has_key(opt_str) or - self._long_opt.has_key(opt_str)) + return (opt_str in self._short_opt or + opt_str in self._long_opt) def remove_option (self, opt_str): option = self._short_opt.get(opt_str) @@ -1393,7 +1393,7 @@ 'words', raise BadOptionError. """ # Is there an exact match? - if wordmap.has_key(s): + if s in wordmap: return s else: # Isolate all words with s as a prefix. Modified: trunk/docutils/test/DocutilsTestSupport.py =================================================================== --- trunk/docutils/test/DocutilsTestSupport.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/DocutilsTestSupport.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -668,7 +668,7 @@ writer_name = '' # set in subclasses or constructor def __init__(self, *args, **kwargs): - if kwargs.has_key('writer_name'): + if 'writer_name' in kwargs: self.writer_name = kwargs['writer_name'] del kwargs['writer_name'] CustomTestCase.__init__(self, *args, **kwargs) Modified: trunk/docutils/test/docutils_difflib.py =================================================================== --- trunk/docutils/test/docutils_difflib.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/docutils_difflib.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -163,8 +163,6 @@ # b2j # for x in b, b2j[x] is a list of the indices (into b) # at which x appears; junk elements do not appear - # b2jhas - # b2j.has_key # fullbcount # for x in b, fullbcount[x] == the number of times x # appears in b; only materialized if really needed (used @@ -188,7 +186,7 @@ # DON'T USE! Only __chain_b uses this. Use isbjunk. # isbjunk # for x in b, isbjunk(x) == isjunk(x) but much faster; - # it's really the has_key method of a hidden dict. + # it's really the in operator of a hidden dict. # DOES NOT WORK for x in a! self.isjunk = isjunk @@ -285,10 +283,9 @@ # from the start. b = self.b self.b2j = b2j = {} - self.b2jhas = b2jhas = b2j.has_key for i in xrange(len(b)): elt = b[i] - if b2jhas(elt): + if elt in b2j: b2j[elt].append(i) else: b2j[elt] = [i] @@ -304,12 +301,12 @@ junkdict[elt] = 1 # value irrelevant; it's a set del b2j[elt] - # Now for x in b, isjunk(x) == junkdict.has_key(x), but the + # Now for x in b, isjunk(x) == x in junkdict, but the # latter is much faster. Note too that while there may be a # lot of junk in the sequence, the number of *unique* junk # elements is probably small. So the memory burden of keeping # this dict alive is likely trivial compared to the size of b2j. - self.isbjunk = junkdict.has_key + self.isbjunk = lambda elt: elt in junkdict def find_longest_match(self, alo, ahi, blo, bhi): """Find longest matching block in a[alo:ahi] and b[blo:bhi]. @@ -550,9 +547,9 @@ # avail[x] is the number of times x appears in 'b' less the # number of times we've seen it in 'a' so far ... kinda avail = {} - availhas, matches = avail.has_key, 0 + matches = 0 for elt in self.a: - if availhas(elt): + if elt in avail: numb = avail[elt] else: numb = fullbcount.get(elt, 0) Modified: trunk/docutils/test/test_dependencies.py =================================================================== --- trunk/docutils/test/test_dependencies.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/test_dependencies.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -28,7 +28,7 @@ settings.setdefault('settings_overrides', {}) settings['settings_overrides'] = settings['settings_overrides'].copy() settings['settings_overrides']['_disable_config'] = 1 - if not settings['settings_overrides'].has_key('record_dependencies'): + if 'record_dependencies' not in settings['settings_overrides']: settings['settings_overrides']['record_dependencies'] = \ docutils.utils.DependencyList(recordfile) docutils.core.publish_file(destination=DocutilsTestSupport.DevNull(), Modified: trunk/docutils/test/test_functional.py =================================================================== --- trunk/docutils/test/test_functional.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/test_functional.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -95,9 +95,9 @@ execfile(join_path(datadir, 'tests', '_default.py'), namespace) execfile(self.configfile, namespace) # Check for required settings: - assert namespace.has_key('test_source'),\ + assert 'test_source' in namespace,\ "No 'test_source' supplied in " + self.configfile - assert namespace.has_key('test_destination'),\ + assert 'test_destination' in namespace,\ "No 'test_destination' supplied in " + self.configfile # Set source_path and destination_path if not given: namespace.setdefault('source_path', @@ -151,7 +151,7 @@ print >>sys.stderr, diff raise # Execute optional function containing extra tests: - if namespace.has_key('_test_more'): + if '_test_more' in namespace: namespace['_test_more'](join_path(datadir, 'expected'), join_path(datadir, 'output'), self, namespace) Modified: trunk/docutils/test/test_language.py =================================================================== --- trunk/docutils/test/test_language.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/test_language.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -76,10 +76,10 @@ missing = [] # in ref but not in l. too_much = [] # in l but not in ref. for label in ref_dict.keys(): - if not l_dict.has_key(label): + if label not in l_dict: missing.append(label) for label in l_dict.keys(): - if not ref_dict.has_key(label): + if label not in ref_dict: too_much.append(label) return (missing, too_much) @@ -140,7 +140,7 @@ canonical.sort() canonical.remove('restructuredtext-test-directive') for name in canonical: - if not inverted.has_key(name): + if name not in inverted: failures.append('"%s": translation missing' % name) if failures: text = ('Module docutils.parsers.rst.languages.%s:\n %s' @@ -175,7 +175,7 @@ canonical.sort() canonical.remove('restructuredtext-unimplemented-role') for name in canonical: - if not inverted.has_key(name): + if name not in inverted: failures.append('"%s": translation missing' % name) if failures: text = ('Module docutils.parsers.rst.languages.%s:\n %s' Modified: trunk/docutils/test/test_nodes.py =================================================================== --- trunk/docutils/test/test_nodes.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/test_nodes.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -91,7 +91,7 @@ def test_normal_attributes(self): element = nodes.Element() - self.assert_(not element.has_key('foo')) + self.assert_('foo' not in element) self.assertRaises(KeyError, element.__getitem__, 'foo') element['foo'] = 'sometext' self.assertEquals(element['foo'], 'sometext') Modified: trunk/docutils/test/test_settings.py =================================================================== --- trunk/docutils/test/test_settings.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/test/test_settings.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -92,8 +92,8 @@ def compare_output(self, result, expected): """`result` and `expected` should both be dicts.""" - self.assert_(result.has_key('record_dependencies')) - if not expected.has_key('record_dependencies'): + self.assert_('record_dependencies' in result) + if 'record_dependencies' not in expected: # Delete it if we don't want to test it. del result['record_dependencies'] result = pprint.pformat(result) + '\n' Modified: trunk/docutils/tools/dev/unicode2rstsubs.py =================================================================== --- trunk/docutils/tools/dev/unicode2rstsubs.py 2008-07-23 16:03:32 UTC (rev 5606) +++ trunk/docutils/tools/dev/unicode2rstsubs.py 2008-07-23 19:18:19 UTC (rev 5607) @@ -129,11 +129,11 @@ set = self.entity_set_name(attributes['set']) if not set: return - if not self.sets.has_key(set): + if set not in self.sets: print 'bad set: %r' % set return entity = attributes['id'] - assert (not self.sets[set].has_key(entity) + assert (entity not in self.sets[set] or self.sets[set][entity] == self.charid), \ ('sets[%r][%r] == %r (!= %r)' % (set, entity, self.sets[set][entity], self.charid)) |