Esempio n. 1
0
def generate_invalid_sequence():
    while True:
        shuffle(regex_subitems)
        new_regex = ''.join(regex_subitems)
        sequence = str(xeger.xeger(new_regex))
        if not is_valid_sequence(sequence):
            break
    return sequence
Esempio n. 2
0
    def random_chinese_characters(i=1):
        """随机中文汉字"""
        s = ""
        if i < 11:
            s = xeger.xeger(u"[\\u4e00-\\u9fa5]{}".format("{" + str(i) + "}"))
        else:
            j = i // 10
            k = i % 10

            while j > 0:
                a = xeger.xeger(u"[\\u4e00-\\u9fa5]{10}")
                s = s + a
                j -= 1
                if j == 0:
                    a = xeger.xeger(
                        u"[\\u4e00-\\u9fa5]{}".format("{" + str(k) + "}"))
                    s = s + a
        return s
Esempio n. 3
0
def generate_valid_examples(size):
    sequences = []
    i = 0
    while i < size:
        xeger._limit = randint(1, UPPER_LIMIT)
        example = str(xeger.xeger(LANGUAGE_REG_EXPRESSION))
        if example not in sequences:
            sequences.append(example)
            i += 1
    return sequences
    def _pattern(self, current_string, pattern, min_length, max_length):
        """Generates a random string matching a given regex pattern, with min/max length constraints."""
        if re.match(pattern, current_string):
            return current_string

        random_string = ''
        attempts = 0

        while attempts < self._max_recalcs:
            random_string = xeger.xeger(pattern)

            if min_length < len(random_string) < max_length:
                return random_string

            attempts += 1

        logger.warning(
            "Unable to generate within length constraints ({} < len < {}) for pattern: '{}'"
            .format(min_length, max_length, pattern))

        return random_string
Esempio n. 5
0
# NOTE: Need Python 2 because compatibility is awful. :(

import clipboard
import xeger


if __name__ == '__main__':
   while True:
      try:
         _regex = raw_input()
         clipboard.copy(xeger.xeger(_regex))
         print("SUCCESS!")
      except Exception:
         print("FAILED!")
Esempio n. 6
0
 def match(self, pattern):
     for _ in range(100):
         assert re.match(pattern, xeger.xeger(pattern))
Esempio n. 7
0
 def test_lookbehind(self):
     pattern = r'(?<=foo)bar'
     assert re.search(pattern, xeger.xeger(pattern))
Esempio n. 8
0
def test_rawInput():
  for i in xrange(501):
    pattern = '[a-zA-Z0-9 ]' * i
    yield check_rawInput, xeger.xeger(pattern)
Esempio n. 9
0
def generate_invalid_sequence():
    while True:
        sequence = str(xeger.xeger(LANGUAGE_REG_EXPRESSION))
        if not is_valid_sequence(sequence):
            break
    return sequence
Esempio n. 10
0
 def example_path(self):
     return xeger.xeger(self.path) if self._regexp else self.path + self.querystring_string()
Esempio n. 11
0
 def match(self, pattern):
     for _ in range(100):
         assert re.match(pattern, xeger.xeger(pattern))
Esempio n. 12
0
 def test_lookbehind(self):
     pattern = r"(?<=foo)bar"
     assert re.search(pattern, xeger.xeger(pattern))