source: tagsplugin/tags/0.9/tractags/util.py

Last change on this file was 15559, checked in by Ryan J Ollos, 7 years ago

0.9dev: Adapt to Trac 1.0 database API

All tests are passing with SQLite, PostgreSQL and MySQL.

Fixes #12137.

File size: 1014 bytes
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2006 Alec Thomas <alec@swapoff.org>
4# Copyright (C) 2013,2014 Steffen Hoffmann <hoff.st@web.de>
5# Copyright (C) 2014 Ryan J Ollos <ryan.j.ollos@gmail.com>
6#
7# This software is licensed as described in the file COPYING, which
8# you should have received as part of this distribution.
9#
10
11import re
12from functools import partial
13
14from trac.test import Mock, MockPerm
15from trac.web.api import _RequestArgs
16
17_TAG_SPLIT = re.compile('[,\s]+')
18
19
20# DEVEL: This needs monitoring for possibly varying endpoint requirements.
21MockReq = partial(Mock, args=_RequestArgs(), authname='anonymous',
22                  perm=MockPerm(), session=dict())
23
24
25def query_realms(query, all_realms):
26    realms = []
27    for realm in all_realms:
28        if re.search('(^|\W)realm:%s(\W|$)' % realm, query):
29            realms.append(realm)
30    return realms
31
32
33def split_into_tags(text):
34    """Split plain text into tags."""
35    return set(filter(None, [tag.strip() for tag in _TAG_SPLIT.split(text)]))
Note: See TracBrowser for help on using the repository browser.