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

Last change on this file was 16943, checked in by Ryan J Ollos, 6 years ago

TracTags 0.10dev: Make compatible with Trac 1.3.3dev

Fixes #13316.

File size: 1.1 KB
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                  is_authenticated=lambda a: a != 'anonymous')
24
25
26def query_realms(query, all_realms):
27    realms = []
28    for realm in all_realms:
29        if re.search('(^|\W)realm:%s(\W|$)' % realm, query):
30            realms.append(realm)
31    return realms
32
33
34def split_into_tags(text):
35    """Split plain text into tags."""
36    return set(filter(None, [tag.strip() for tag in _TAG_SPLIT.split(text)]))
Note: See TracBrowser for help on using the repository browser.