From 2d88d88f8c27b50f5d4d532ae54a8c643e6dc868 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 29 Apr 2012 12:05:38 +1200 Subject: Basic anchor adding. --- libpathod/utils.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'libpathod/utils.py') diff --git a/libpathod/utils.py b/libpathod/utils.py index 104ee148..daeccdea 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -1,4 +1,27 @@ -import copy, os +import copy, os, re +import rparse + +class AnchorError(Exception): pass + +def parse_anchor_spec(s, settings): + """ + For now, this is very simple, and you can't have an '=' in your regular + expression. + """ + if not "=" in s: + raise AnchorError("Invalid anchor definition: %s"%s) + rex, spec = s.split("=", 1) + try: + re.compile(rex) + except re.error: + raise AnchorError("Invalid regex in anchor: %s"%s) + try: + rparse.parse(settings, spec) + except rparse.ParseException, v: + raise AnchorError("Invalid page spec in anchor: '%s', %s"%(s, str(v))) + + return rex, spec + class Data: def __init__(self, name): -- cgit v1.2.3