diff options
-rw-r--r-- | languages/__init__.py | 2 | ||||
-rw-r--r-- | parsers/__init__.py | 2 | ||||
-rw-r--r-- | parsers/rst/directives/__init__.py | 2 | ||||
-rw-r--r-- | parsers/rst/directives/admonitions.py | 2 | ||||
-rw-r--r-- | parsers/rst/directives/body.py | 2 | ||||
-rw-r--r-- | parsers/rst/directives/images.py | 4 | ||||
-rw-r--r-- | parsers/rst/directives/misc.py | 24 | ||||
-rw-r--r-- | parsers/rst/directives/parts.py | 4 | ||||
-rw-r--r-- | parsers/rst/directives/tables.py | 24 | ||||
-rw-r--r-- | parsers/rst/languages/__init__.py | 2 | ||||
-rw-r--r-- | parsers/rst/roles.py | 12 | ||||
-rw-r--r-- | parsers/rst/states.py | 4 | ||||
-rw-r--r-- | readers/__init__.py | 2 | ||||
-rw-r--r-- | readers/python/__init__.py | 2 | ||||
-rw-r--r-- | readers/python/moduleparser.py | 10 | ||||
-rw-r--r-- | transforms/frontmatter.py | 2 | ||||
-rw-r--r-- | transforms/parts.py | 4 | ||||
-rw-r--r-- | transforms/references.py | 30 | ||||
-rw-r--r-- | writers/__init__.py | 2 | ||||
-rw-r--r-- | writers/html4css1/__init__.py | 42 | ||||
-rw-r--r-- | writers/latex2e/__init__.py | 44 | ||||
-rw-r--r-- | writers/newlatex2e/__init__.py | 2 | ||||
-rw-r--r-- | writers/s5_html/__init__.py | 2 |
23 files changed, 113 insertions, 113 deletions
diff --git a/languages/__init__.py b/languages/__init__.py index c721c0210..7d6521fc1 100644 --- a/languages/__init__.py +++ b/languages/__init__.py @@ -14,7 +14,7 @@ __docformat__ = 'reStructuredText' _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 diff --git a/parsers/__init__.py b/parsers/__init__.py index 125ab7674..2683376f9 100644 --- a/parsers/__init__.py +++ b/parsers/__init__.py @@ -41,7 +41,7 @@ _parser_aliases = { 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 diff --git a/parsers/rst/directives/__init__.py b/parsers/rst/directives/__init__.py index 14ac03a99..30da65ecd 100644 --- a/parsers/rst/directives/__init__.py +++ b/parsers/rst/directives/__init__.py @@ -76,7 +76,7 @@ def directive(directive_name, language_module, document): normname = directive_name.lower() messages = [] msg_text = [] - if _directives.has_key(normname): + if normname in _directives: return _directives[normname], messages canonicalname = None try: diff --git a/parsers/rst/directives/admonitions.py b/parsers/rst/directives/admonitions.py index bed3381b8..870b6659e 100644 --- a/parsers/rst/directives/admonitions.py +++ b/parsers/rst/directives/admonitions.py @@ -35,7 +35,7 @@ class BaseAdmonition(Directive): 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)] diff --git a/parsers/rst/directives/body.py b/parsers/rst/directives/body.py index 03c9c3fa6..0cc695726 100644 --- a/parsers/rst/directives/body.py +++ b/parsers/rst/directives/body.py @@ -39,7 +39,7 @@ class BasePseudoSection(Directive): 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'], '', diff --git a/parsers/rst/directives/images.py b/parsers/rst/directives/images.py index 96bdb3353..59323bba0 100644 --- a/parsers/rst/directives/images.py +++ b/parsers/rst/directives/images.py @@ -46,7 +46,7 @@ class Image(Directive): '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 @@ class Image(Directive): 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] diff --git a/parsers/rst/directives/misc.py b/parsers/rst/directives/misc.py index 5d5d34729..89c8364c7 100644 --- a/parsers/rst/directives/misc.py +++ b/parsers/rst/directives/misc.py @@ -86,7 +86,7 @@ class Include(Directive): 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 @@ class Raw(Directive): 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 @@ class Raw(Directive): '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 @@ class Unicode(Directive): '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 @@ class Role(Directive): 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 @@ class DefaultRole(Directive): 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 [] diff --git a/parsers/rst/directives/parts.py b/parsers/rst/directives/parts.py index da1586275..6ef8c905c 100644 --- a/parsers/rst/directives/parts.py +++ b/parsers/rst/directives/parts.py @@ -57,13 +57,13 @@ class Contents(Directive): 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() diff --git a/parsers/rst/directives/tables.py b/parsers/rst/directives/tables.py index 639ce8d1f..5527c9f0b 100644 --- a/parsers/rst/directives/tables.py +++ b/parsers/rst/directives/tables.py @@ -49,7 +49,7 @@ class Table(Directive): 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 @@ class Table(Directive): 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 @@ class CSVTable(Table): 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 @@ class CSVTable(Table): 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 @@ class CSVTable(Table): '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 @@ class CSVTable(Table): 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 @@ class CSVTable(Table): % (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 diff --git a/parsers/rst/languages/__init__.py b/parsers/rst/languages/__init__.py index 18c884748..962802245 100644 --- a/parsers/rst/languages/__init__.py +++ b/parsers/rst/languages/__init__.py @@ -15,7 +15,7 @@ __docformat__ = 'reStructuredText' _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()) diff --git a/parsers/rst/roles.py b/parsers/rst/roles.py index 1da1395e9..062d53e50 100644 --- a/parsers/rst/roles.py +++ b/parsers/rst/roles.py @@ -101,7 +101,7 @@ def role(role_name, language_module, lineno, reporter): messages = [] msg_text = [] - if _roles.has_key(normname): + if normname in _roles: return _roles[normname], messages if role_name: @@ -135,7 +135,7 @@ def role(role_name, language_module, lineno, reporter): 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 @@ def set_implicit_options(role_fn): """ 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 @@ def rfc_reference_role(role, rawtext, text, lineno, inliner, 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 @@ def set_classes(options): 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'] diff --git a/parsers/rst/states.py b/parsers/rst/states.py index eabc179ef..b20c9f4d9 100644 --- a/parsers/rst/states.py +++ b/parsers/rst/states.py @@ -901,8 +901,8 @@ class Inliner: 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: diff --git a/readers/__init__.py b/readers/__init__.py index 74db893f9..a28248f70 100644 --- a/readers/__init__.py +++ b/readers/__init__.py @@ -101,7 +101,7 @@ _reader_aliases = {} 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 diff --git a/readers/python/__init__.py b/readers/python/__init__.py index da8fb22d2..eac284a7e 100644 --- a/readers/python/__init__.py +++ b/readers/python/__init__.py @@ -94,7 +94,7 @@ class DocstringFormattingVisitor(nodes.SparseNodeVisitor): 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] diff --git a/readers/python/moduleparser.py b/readers/python/moduleparser.py index e874ee204..fadb3586b 100644 --- a/readers/python/moduleparser.py +++ b/readers/python/moduleparser.py @@ -525,14 +525,14 @@ class TokenParser: 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 == '`': diff --git a/transforms/frontmatter.py b/transforms/frontmatter.py index eae149a44..cd537f910 100644 --- a/transforms/frontmatter.py +++ b/transforms/frontmatter.py @@ -388,7 +388,7 @@ class DocInfo(Transform): 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] diff --git a/transforms/parts.py b/transforms/parts.py index 39cb74f75..26fcdb684 100644 --- a/transforms/parts.py +++ b/transforms/parts.py @@ -80,7 +80,7 @@ class Contents(Transform): 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 @@ class Contents(Transform): 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 diff --git a/transforms/references.py b/transforms/references.py index 097877ee9..c45fdb0da 100644 --- a/transforms/references.py +++ b/transforms/references.py @@ -240,7 +240,7 @@ class IndirectHyperlinks(Transform): 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 @@ class IndirectHyperlinks(Transform): 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 @@ class Footnotes(Transform): 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 @@ class Footnotes(Transform): """ 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 @@ class Substitutions(Transform): 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 @@ class Substitutions(Transform): 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 @@ class TargetNotes(Transform): 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 @@ class TargetNotes(Transform): 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 @@ class DanglingReferencesVisitor(nodes.SparseNodeVisitor): 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) diff --git a/writers/__init__.py b/writers/__init__.py index 39e1ecd5b..8e3bd1aaa 100644 --- a/writers/__init__.py +++ b/writers/__init__.py @@ -127,7 +127,7 @@ _writer_aliases = { 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 diff --git a/writers/html4css1/__init__.py b/writers/html4css1/__init__.py index 634a74d1d..57d2c6ef0 100644 --- a/writers/html4css1/__init__.py +++ b/writers/html4css1/__init__.py @@ -353,13 +353,13 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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 @@ class HTMLTranslator(nodes.NodeVisitor): 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: diff --git a/writers/latex2e/__init__.py b/writers/latex2e/__init__.py index a4245a173..70a158b64 100644 --- a/writers/latex2e/__init__.py +++ b/writers/latex2e/__init__.py @@ -1124,9 +1124,9 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): # 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 @@ class LaTeXTranslator(nodes.NodeVisitor): '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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): # 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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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'])) diff --git a/writers/newlatex2e/__init__.py b/writers/newlatex2e/__init__.py index 8c360876e..2830fd556 100644 --- a/writers/newlatex2e/__init__.py +++ b/writers/newlatex2e/__init__.py @@ -676,7 +676,7 @@ class LaTeXTranslator(nodes.SparseNodeVisitor): # 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: diff --git a/writers/s5_html/__init__.py b/writers/s5_html/__init__.py index 486c03f4a..73a1ec66f 100644 --- a/writers/s5_html/__init__.py +++ b/writers/s5_html/__init__.py @@ -251,7 +251,7 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): """ 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 |