source: tracformsplugin/tags/tracforms-0.4.1/0.11/tracforms/compat.py

Last change on this file was 10490, checked in by Steffen Hoffmann, 12 years ago

TracFormsPlugin: Release maintenance version 0.4.1 for compatibility with Trac 0.11, closes #9000.

These are changes cherry-picked from trunk and merged into tracforms-0.4 to
establish full compatibility with Trac 0.11 on level with plugin's own claims.

File size: 1.3 KB
Line 
1# -*- coding: utf-8 -*-
2
3# 2011 Steffen Hoffmann
4
5"""Various classes and functions to provide backwards-compatibility with
6previous versions of Python from 2.4 onward.
7"""
8
9# json was introduced in 2.6, use simplejson for older versions
10# parse_qs was copied to urlparse and deprecated in cgi in 2.6
11import sys
12if sys.version_info[0] == 2 and sys.version_info[1] > 5:
13    import json
14    from urlparse import parse_qs
15else:
16    import simplejson as json
17    from cgi import parse_qs
18
19# A Trac issue rather than a Python one:
20# Provide `resource_exists`, that has been backported to Trac 0.11.8 only.
21try:
22    from trac.resource import resource_exists
23except ImportError:
24    from trac.resource import ResourceSystem
25    def resource_exists(env, resource):
26        """Checks for resource existence without actually instantiating a
27        model.
28
29        :return: `True` if the resource exists, `False` if it doesn't
30        and `None` in case no conclusion could be made (i.e. when
31        `IResourceManager.resource_exists` is not implemented).
32        """
33        manager = ResourceSystem(env).get_resource_manager(resource.realm)
34        if manager and hasattr(manager, 'resource_exists'):
35            return manager.resource_exists(resource)
36        elif resource.id is None:
37            return False
38
Note: See TracBrowser for help on using the repository browser.