class Template(object): """A simple template engine. >>> t = Template() >>> t.add('test', 'xxx') >>> print(list(t.process('{test}'))) ['xxx'] >>> print(list(t.process('{test} test'))) ['xxx', ' test'] >>> print(list(t.process('test {test}'))) ['test ', 'xxx'] >>> print(list(t.process('test {test} test'))) ['test ', 'xxx', ' test'] >>> print(list(t.process('{test}\\\\n'))) ['xxx', '\\n'] >>> print(list(t.process('{test}\\n'))) ['xxx', '\\n'] """ _tag_re = lazy_compile('{(\\w+)}') def __init__(self): self._data = {} def add(self, name, value): self._data[name] = value def process(self, tpl): unicode_escape = codecs.getdecoder("unicode_escape") tpl = unicode_escape(tpl)[0] if not PY3: tpl = tpl.encode('utf-8') pos = 0 while True: match = self._tag_re.search(tpl, pos) if not match: if pos < len(tpl): yield tpl[pos:] break start, end = match.span() if start > 0: yield tpl[pos:start] pos = end name = match.group(1) try: data = self._data[name] except KeyError: raise MissingTemplateVariable(name) if not isinstance(data, str): data = str(data) yield data
from breezy.plugins.qbrz.lib.lazycachedrevloader import ( load_revisions, cached_revisions) from breezy.plugins.qbrz.lib.util import ( runs_in_loading_queue, format_timestamp, get_message, get_summary, open_browser, ) from breezy import foreign from breezy.plugins.qbrz.lib.uifactory import ui_current_widget from breezy.plugins.qbrz.lib import logmodel _email_re = lazy_regex.lazy_compile(r'([a-z0-9_\-.+]+@[a-z0-9_\-.+]+)', re.IGNORECASE) _link1_re = lazy_regex.lazy_compile(r'([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])', re.IGNORECASE) _link2_re = lazy_regex.lazy_compile(r'(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)', re.IGNORECASE) _tag_re = lazy_regex.lazy_compile(r'[, ]') _start_of_line_whitespace_re = lazy_regex.lazy_compile(r'(?m)^ +') def _dummy_gpg_verify(): return False gpg_verify_available_func = getattr(gpg.GPGStrategy, "verify_signatures_available", _dummy_gpg_verify) def htmlencode(s): """Convert single line to html snippet suitable to show in Qt widgets.""" return (s.replace("&", "&")
@classmethod def from_changelog(cls, branch_name, changelog): if len(changelog._blocks) > 0: return cls(branch_name, changelog._blocks[0].version) else: return cls(branch_name, None) def get(self): if self._version is None: raise SubstitutionUnavailable( self.name, "No previous changelog to take the version from") return str(self._version) dfsg_regex = lazy_regex.lazy_compile(r'[+.]*dfsg[.]*[0-9]+') version_regex = lazy_regex.lazy_compile( r'([~+])(svn[0-9]+|bzr[0-9]+|git[0-9a-f]+)') def version_extract_base(version): version = dfsg_regex.sub("", version) return version_regex.sub("\\1", version) class DebUpstreamBaseVariable(DebUpstreamVariable): basename = "debupstream-base" minimum_format = 0.3
def get_old_recipe(if_changed_from, possible_transports=None): try: (basename, f) = get_recipe_from_location(if_changed_from, possible_transports) except errors.NoSuchFile: return None try: old_recipe = RecipeParser(f, filename=if_changed_from).parse() finally: f.close() return old_recipe launchpad_recipe_re = lazy_regex.lazy_compile( r'^https://code.launchpad.net/~(.*)/\+recipe/(.*)$') def get_recipe_from_launchpad(username, recipe_name, location): """Load a recipe from Launchpad. :param username: The launchpad user name :param recipe_name: Recipe name :param location: Original location (used for error reporting) :return: Text of the recipe """ from launchpadlib.launchpad import Launchpad lp = Launchpad.login_with("bzr-builder", "production") try: person = lp.people[username] except KeyError:
chooser.clicked.connect(click_handler) def open_browser(url): try: import webbrowser open_func = webbrowser.open except ImportError: try: open_func = os.startfile except AttributeError: open_func = lambda x: None open_func(url) _extract_name_re = lazy_regex.lazy_compile('(.*?) <.*?@.*?>') _extract_email_re = lazy_regex.lazy_compile('<(.*?@.*?)>') def extract_name(author, strict=False): m = _extract_name_re.match(author) if m: name = m.group(1) else: if strict: name = author else: m = _extract_email_re.match(author) if m: name = m.group(1) else:
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from breezy import ( bugtracker, config, lazy_regex, ) # XXX use just (\d+) at the end of URL as simpler regexp? _bug_id_re = lazy_regex.lazy_compile( r'(?:' r'bugs/' # Launchpad bugs URL r'|ticket/' # Trac bugs URL r'|show_bug\.cgi\?id=' # Bugzilla bugs URL r'|issues/(?:show/)?' # Redmine bugs URL r'|DispForm.aspx\?ID=' # Microsoft SharePoint URL r'|default.asp\?' # Fogbugz URL r'|issue' # Roundup issue tracker URL r'|view.php\?id=' # Mantis bug tracker URL r'|aid=' # FusionForge bug tracker URL r'|task_id=' # Flyspray bug tracker URL (http://flyspray.org) - old style URLs(?) r'|task/' # Flyspray itself bugtracker (https://bugs.flyspray.org) r')(\d+)(?:\b|$)') _jira_bug_id_re = lazy_regex.lazy_compile( r'(?:.*/browse/)([A-Z][A-Z0-9_]*-\d+)($)') _unique_bugtrackers = ('lp', 'deb', 'gnome') # bugtracker config settings _bugtracker_re = lazy_regex.lazy_compile('(bugtracker|trac|bugzilla)_(.+)_url')