コード例 #1
0
ファイル: tests.py プロジェクト: aglenis/python-rex
 def test_m_value_orthodox(self):
     self.assertEqual('88',
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[
                          't'])
     self.assertEqual('88',
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[2])
     self.assertEqual(None,
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[
                          'tttt'])
コード例 #2
0
ファイル: tests.py プロジェクト: aglenis/python-rex
 def test_m_value(self):
     self.assertEqual('88',
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          't'])
     self.assertEqual('88',
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          2])
     self.assertEqual(None,
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          'tttt'])
コード例 #3
0
ファイル: arpa.py プロジェクト: chenkovsky/pyngram
def arpa(fp, gram=None, header_start = None, header_end = None, section_start = None, section_end = None, file_end = None):
    section = None
    lm_info = {}
    max_gram = 0
    for l in fp:
        #print(l)
        if l.startswith("\\"):
            if l == "\\data\\\n":
                section = 0
                print("loading header", file=sys.stderr)
                if header_start and header_start() == False:
                    break
            elif l=="\\end\\\n":
                if file_end:
                    file_end(lm_info)
                break
            else:
                res = (l == rex("/^\\\\(\\d+)-grams/"))
                if res is not None:
                    section = int(res[1])
                    print("loading %d-grams" % section, file=sys.stderr)
                    if section_start and section_start(lm_info,section) == False:
                        break
            continue
        if l == "\n":
            if section == 0 and header_end and header_end(lm_info)== False:
                break
            elif section is not None and section > 0 and section_end and section_end(lm_info,section) == False:
                break
            section = None
            continue
        if section == 0:
            res = (l == rex("/^ngram (\d+)=(\d+)/"))
            lm_info[int(res[1])] = int(res[2])
            print("ngram %d=%d"%(int(res[1]), int(res[2])), file=sys.stderr)
            max_gram = max(max_gram, int(res[1]))
        else:
            larr = l.strip("\n").split("\t")
            bow = None
            if len(larr) == 3:
                bow = float(larr[-1])
            elif len(larr) < 2:
                continue
            if bow is None:
                bow = 0
            prob = float(larr[0])
            words = larr[1].split(" ")
            if gram and gram(lm_info, section, words, prob, bow) == False:
                break
コード例 #4
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_not_cache(self):
     rex("s/cache/test1/", cache=False)
     self.assertNotIn("s/cache/test1/", rex_module.REX_CACHE)
コード例 #5
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_empty_unicode():
    m = "This is dog!" == rex('/[0-9]+!/')
    assert m.__unicode__() == u''
コード例 #6
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_m_true(self):
     self.assertTrue("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))
コード例 #7
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_s_multi(self):
     self.assertEqual("This is a dog dog dog dog", "This is a cat cat cat cat" == rex("s/cat/dog/"))
コード例 #8
0
ファイル: main.py プロジェクト: tjguk/pyformat.info
import importlib
import inspect
from textwrap import dedent, indent
from collections import namedtuple
from pathlib import Path

import jinja2
import sass
import click
import markdown
from rex import rex


CONTENT_MODULE_PATH = "tests.test_content"

OUTPUT_RE = rex(r"""s/^.*?assert .*? == ['"](.*)['"].*?# output$\n/\1/""")

Example = namedtuple("Example", ('name', 'title', 'details', 'setup', 'old', 'new', 'output'))


def compile_sass(source_path, target_path_pattern):
    # First generate the content from which we can generate the hashname
    output = sass.compile(
        filename=str(source_path),
        output_style='compressed')
    hash = hashlib.sha512(output.encode('utf-8')).hexdigest()[:8]
    target_path = str(target_path_pattern).format(hash)
    source_map_target_path = target_path + '.map'
    output = sass.compile(
        filename=str(source_path),
        output_style='compressed',
コード例 #9
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_m_action(self):
     r = rex("m/test/")
     self.assertEqual(r.action, "m")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.flags, 0)
コード例 #10
0
def test_m_false_noncache():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx", cache=False)
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa bb cc xx", cache=False)
コード例 #11
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_true_orthodox():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")
コード例 #12
0
def test_m_true():
    assert ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
コード例 #13
0
def test_m_true_orthodox():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")
コード例 #14
0
def test_s_action_flags():
    r = rex('/test/im')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == re.I | re.M
コード例 #15
0
def test_s_action():
    r = rex('s/test/ohh/')
    assert r.action == 's'
    assert r.pattern == 'test'
    assert r.replacement == 'ohh'
    assert r.flags == 0
コード例 #16
0
def test_m_action_ex():
    r = rex('m!test!')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == 0
コード例 #17
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_action_ex():
    r = rex('m!test!')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == 0
コード例 #18
0
def test_m_false():
    assert not ("Aa 9-9  xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
コード例 #19
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_s_action_flags():
    r = rex('/test/im')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == re.I | re.M
コード例 #20
0
def test_m_false_orthodox():
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9  xx")
コード例 #21
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_false():
    assert not ("Aa 9-9  xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
コード例 #22
0
def test_s_i_orthodox():
    assert rex('s/CAT/dog/i', "This is a cat") == 'This is a dog'
コード例 #23
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_str(self):
     m = "This is dog!" == rex("/[a-z]+!/")
     self.assertEqual(str(m), "dog!")
コード例 #24
0
def test_s_multi_orthodox():
    assert rex('s/cat/dog/',
               "This is a cat cat cat cat") == 'This is a dog dog dog dog'
コード例 #25
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_s_action(self):
     r = rex("s/test/ohh/")
     self.assertEqual(r.action, "s")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.replacement, "ohh")
     self.assertEqual(r.flags, 0)
コード例 #26
0
def test_cache():
    rex('s/cache/test/')
    assert 's/cache/test/' in rex_module.REX_CACHE
コード例 #27
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_m_value(self):
     self.assertEqual("88", ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))["t"])
     self.assertEqual("88", ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))[2])
     self.assertEqual(None, ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))["tttt"])
コード例 #28
0
def test_cache_2():
    a = rex('s/cache/test/')
    b = rex('s/cache/test/')
    assert a is b
コード例 #29
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_cache_2(self):
     a = rex("s/cache/test/")
     b = rex("s/cache/test/")
     self.assertEqual(a is b, True)
コード例 #30
0
def test_no_cache_2():
    a = rex('s/cache/test/', cache=False)
    b = rex('s/cache/test/', cache=False)
    assert not (a is b)
コード例 #31
0
def test_empty_unicode():
    m = "This is dog!" == rex('/[0-9]+!/')
    assert m.__unicode__() == u''
コード例 #32
0
def test_not_cache():
    rex('s/cache/test1/', cache=False)
    assert not 's/cache/test1/' in rex_module.REX_CACHE
コード例 #33
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_action():
    r = rex('m/test/')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == 0
コード例 #34
0
def test_clear_cache():
    rex('s/cache/test/')
    rex_clear_cache()
    assert not 's/cache/test/' in rex_module.REX_CACHE
コード例 #35
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_s_action():
    r = rex('s/test/ohh/')
    assert r.action == 's'
    assert r.pattern == 'test'
    assert r.replacement == 'ohh'
    assert r.flags == 0
コード例 #36
0
def test_rex_group():
    m = "This is cat! A kitten is a cat but not a dog." == rex(
        '/[a-z]+!.*(kitten\s\S{2}).*but.*(dog)\./')
    assert m == rex.group
コード例 #37
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_true():
    assert ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
コード例 #38
0
def test_m_value():
    assert ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))['t'] == '88'
    assert ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[2] == '88'
    assert ("Aa 9-9 88 xx"
            == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))['tttt'] is None
コード例 #39
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_false_noncache():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx", cache=False)
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa bb cc xx", cache=False)
コード例 #40
0
def test_m_value_orthodox():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")['t'] == '88'
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[2] == '88'
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")['tttt'] is None
コード例 #41
0
ファイル: test_rex.py プロジェクト: dex4er/python-rex
def test_m_false_orthodox():
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9  xx")
コード例 #42
0
def test_m_true_call():
    r = rex('/([0-9-]+) (?P<t>[0-9-]+)/')
    assert r("Aa 9-9 88 xx")
コード例 #43
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_clear_cache(self):
     rex("s/cache/test/")
     rex_clear_cache()
     self.assertNotIn("s/cache/test/", rex_module.REX_CACHE)
コード例 #44
0
def test_m_false_call():
    r = rex('/([0-9-]+) (?P<t>[0-9-]+)/')
    assert not r("Aa 9-9  xx")
コード例 #45
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_unicode(self):
     m = "This is dog!" == rex("/[a-z]+!/")
     self.assertEqual(unicode(m), u"dog!")
コード例 #46
0
def test_m_g():
    assert (("Aa 9-9 88 xx" == rex('/(\d)/g')) == ['9', '9', '8', '8'])
    assert (("Aa 9-9 88 xx" == rex('/([aA])/g')) == ['A', 'a'])
    assert (("Aa 9-9 88 xx" == rex('/(ttt)/g')) == [])
コード例 #47
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_m_action_ex(self):
     r = rex("m!test!")
     self.assertEqual(r.action, "m")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.flags, 0)
コード例 #48
0
def test_s():
    s = ("This is a cat" == rex('s/cat/dog/'))
    assert s == 'This is a dog'
コード例 #49
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_s_action_flags(self):
     r = rex("/test/im")
     self.assertEqual(r.action, "m")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.flags, re.I | re.M)
コード例 #50
0
def test_s_i():
    s = "This is a cat" == rex('s/CAT/dog/i')
    assert s == 'This is a dog'
コード例 #51
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_m_false(self):
     self.assertFalse("Aa 9-9  xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))
コード例 #52
0
def test_no_action():
    r = rex('/test/')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == 0
コード例 #53
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_s_i(self):
     self.assertEqual("This is a dog", "This is a cat" == rex("s/CAT/dog/i"))
コード例 #54
0
def test_s_multi():
    s = "This is a cat cat cat cat" == rex('s/cat/dog/')
    assert s == 'This is a dog dog dog dog'
コード例 #55
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
    def test_cache(self):
        rex("s/cache/test/")

        self.assertIn("s/cache/test/", rex_module.REX_CACHE)
コード例 #56
0
def test_str():
    m = "This is dog!" == rex('/[a-z]+!/')
    assert str(m) == 'dog!'
コード例 #57
0
ファイル: tests.py プロジェクト: BigData-Tools/python-rex
 def test_no_cache_2(self):
     a = rex("s/cache/test/", cache=False)
     b = rex("s/cache/test/", cache=False)
     self.assertEqual(a is b, False)
コード例 #58
0
def test_empty_str():
    m = "This is dog!" == rex('/[0-9]+!/')
    assert str(m) == ''
コード例 #59
0
from collections import defaultdict

from rex import rex

ALIAS_RE = rex(
    '/^(?P<alias>[a-zA-Z0-9_.@-]+)(?:[\s]+)(?P<target>[a-zA-Z0-9_.@-]+),?.*?$/'
)


def parse_virtual_file(virtual_file, target_domain=''):
    result = defaultdict(set)
    for line in virtual_file:
        line: str = line.strip()
        if line.startswith('#'):
            continue
        match = ALIAS_RE(line)
        if match:
            target = match['target']
            if "@" not in target:
                target = f"{target}@{target_domain}"
            result[target].add(match['alias'])

    return result
コード例 #60
0
def test_unicode():
    m = "This is dog!" == rex('/[a-z]+!/')
    assert m.__unicode__() == u'dog!'