-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsrl.py
46 lines (34 loc) · 1.25 KB
/
srl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
srl
~~~
This module implements Simple Regex Language object.
:copyright: (c) 2016 by Simple Regex Language.
:license: MIT, see LICENSE for more details.
"""
from .builder import Builder
class SRL(object):
"""The SRL object implements Simple Regex Language and acts as
central object. It is passed the string represented for
Simple Regex Language. Once it is created it will act almost
exactly same behavior as `re.RegexObject`.
Usually you create a :class:`SRL` instance like this::
from srl import SRL
srl = SRL('letter from a to f')
:param srl: the string of Simple Regex Language
"""
def __init__(self, srl=None):
self.srl = srl
self.compiled = Builder.parse(srl)
def __str__(self):
"""str(srl): regex pattern of compiled Simple Regex Language.::
>>> srl = SRL('digit exactly 3 times')
>>> assert str(srl) == '[0-9]{3}'
"""
return self.compiled.pattern
def __getattr__(self, method):
"""SRL shares the same API with :class:`re.RegexObject`.::
>>> srl = SRL('digit exactly 3 times')
>>> assert srl.match('012').group(0) == '012'
"""
return getattr(self.compiled, method)