Modify

Opened 6 months ago

Closed 6 months ago

#13738 closed defect (fixed)

Python3: AttributeError: 'dict' object has no attribute 'itervalues'

Reported by: Peter Suter Owned by: Peter Suter
Priority: normal Component: WikiAutoCompletePlugin
Severity: normal Keywords: python3
Cc: Trac Release:

Description

Plugin fails in Python3:

	Traceback (most recent call last):
	  File "trac\web\main.py", line 617, in dispatch_request
		dispatcher.dispatch(req)
	  File "trac\web\main.py", line 303, in dispatch
		raise e
	  File "trac\web\main.py", line 250, in dispatch
		resp = chosen_handler.process_request(req)
	  File "wikiautocomplete\wikiautocomplete\web_ui.py", line 82, in process_request
		completions = self._suggest_linkresolvers(req)
	  File "wikiautocomplete\wikiautocomplete\web_ui.py", line 207, in _suggest_linkresolvers
		in InterWikiMap(self.env).interwiki_map.itervalues())
	AttributeError: 'dict' object has no attribute 'itervalues'

Attachments (0)

Change History (2)

comment:1 Changed 6 months ago by Peter Suter

  • wikiautocomplete/web_ui.py

    diff -r f5d590d59135 -r 849a747ed6c6 wikiautocomplete/web_ui.py
    a b  
    11# -*- coding: utf-8 -*-
    22
    3 from __future__ import with_statement
     3from __future__ import with_statement, division
    44
    55import pkg_resources
    66import re
     7import sys
    78
    89from trac.core import Component, TracError, implements
    910from trac.attachment import Attachment
     
    3031        json = None
    3132if json:
    3233    def to_json(data):
    33         return json.dumps(data)
     34        text = json.dumps(data)
     35        if sys.version_info[0] > 2 and not isinstance(text, bytes):
     36            text = text.encode('utf-8')
     37        return text
    3438else:
    3539    def to_json(data):
    3640        from trac.util.presentation import to_json
     
    204208        links = {}
    205209        links.update((name, (2, name, url, title))
    206210                     for name, url, title
    207                      in InterWikiMap(self.env).interwiki_map.itervalues())
     211                     in InterWikiMap(self.env).interwiki_map.values())
    208212        links.update((name, (1, name, url, title))
    209213                     for name, url, title in self._get_intertracs())
    210214        links.update((name, (0, name, None, None))
     
    212216                     for name, resolver in provider.get_link_resolvers())
    213217        return [{'value': name, 'title': title if name != title else url}
    214218                for order, name, url, title
    215                 in sorted(links.itervalues(),
     219                in sorted(links.values(),
    216220                          key=lambda item: (item[0], item[1]))]
    217221
    218222    def _suggest_ticket(self, req, term):
    219223        args = self._get_num_ranges(term, Ticket.id_is_valid)
    220224        if args:
    221             expr = ' OR '.join(['id>=%s AND id<%s'] * (len(args) / 2))
     225            expr = ' OR '.join(['id>=%s AND id<%s'] * (len(args) // 2))
    222226            rows = self.env.db_query("""
    223227                SELECT id, summary FROM ticket
    224228                WHERE %(expr)s
     
    278282        resource = Resource(req.args.get('realm'), req.args.get('id'))
    279283        context = web_context(req, resource)
    280284        completions = []
    281         for name, descr in self._get_macros().iteritems():
     285        for name, descr in self._get_macros().items():
    282286            details_html = self._format_to_html(context, descr)
    283287            title_html = self._format_to_oneliner(context, descr, shorten=True)
    284288            completions.append({'value': name,
     
    291295        context = web_context(req, resource)
    292296        macros = self._get_macros()
    293297        mimetypes = set()
    294         for name, mimetype in Mimeview(self.env).mime_map.iteritems():
     298        for name, mimetype in Mimeview(self.env).mime_map.items():
    295299            if name not in macros:
    296300                mimetypes.add(name)
    297301            mimetypes.add(mimetype)
    298302
    299303        completions = []
    300         for name, descr in macros.iteritems():
     304        for name, descr in macros.items():
    301305            details_html = self._format_to_html(context, descr)
    302306            title_html = self._format_to_oneliner(context, descr, shorten=True)
    303307            completions.append({'value': name,
     
    414418
    415419    def _get_macros(self):
    416420        macros = {}
    417         for name, descr in self._known_macros.iteritems():
     421        for name, descr in self._known_macros.items():
    418422            if isinstance(descr, (tuple, list)):
    419423                descr = dgettext(descr[0], to_unicode(descr[1]))
    420424            macros[name] = descr

comment:2 Changed 6 months ago by Peter Suter

Resolution: fixed
Status: newclosed

In 17668:

WikiAutoCompletePlugin: Python3 compatibility.
(fix #13738)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Suter.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.