Convert intervals to regular expression pattern.

    :param intervals: Unicode codepoint intervals.
970919
def build_re_pattern_from_intervals(intervals: IntervalListType) -> BuiltInReType:
    

    inner = [f'{chr(lb)}-{chr(ub)}' for lb, ub in intervals]
    joined_inner = ''.join(inner)
    pattern = f'[{joined_inner}]+'

    return re.compile(pattern, re.UNICODE)
382605
def validate_regexp(ctx, param, value):
    
    if value:
        try:
            value = re.compile(value)
        except ValueError:
            raise click.BadParameter('invalid regular expression.')
    return value
1298560
def get_elementary_intervals(self, features):
        """"""
        coords = []
        try:
            for interval in features:
                if len(interval) != 3:
                    raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
                coords.extend([interval[0],interval[1]])    
        except IndexError:
            raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
        coords = list(set(coords))
        coords.sort()
        return coords
175476
def _compose_range(pattern, rule, fill=2):
    
    keys = []
    mask = len(pattern)
    for rule in str.split(rule, ","):
        if not '-' in rule:
            if rule[:mask] == pattern:
                keys.append(rule[mask:])
            else:
                keys.append(rule)
        else:
            (start, end) = str.split(rule, '-')
            if rule[:mask] == pattern:
                start = int(start[mask:])
            else:
                start = int(start)
            # Since I allow both "Week00-15" and "Week00-Week15", I need
            # to check for the second week.
            if end[0:mask] == pattern:
                end = int(end[mask:])
            else:
                end = int(end)

            key = "%%0%ii" % fill
            for i in range(start, end + 1):
                keys.append(key % i)

    #print keys
    return keys
1326535
def verify_pattern(pattern):
    

    regex = re.compile("^!?[a-zA-Z]+$|[*]{1,2}$")

    def __verify_pattern__(__pattern__):
        if not __pattern__:
            return False
        elif __pattern__[0] == "!":
            return __verify_pattern__(__pattern__[1:])
        elif __pattern__[0] == "[" and __pattern__[-1] == "]":
            return all(__verify_pattern__(p) for p in __pattern__[1:-1].split(","))
        else:
            return regex.match(__pattern__)
    return all(__verify_pattern__(p) for p in pattern.split("/"))
1334479
def tone_marks():
    
    return RegexBuilder(
        pattern_args=symbols.TONE_MARKS,
        pattern_func=lambda x: u"(?<={}).".format(x)).regex
928625
def check(line, queries):
    
    line = line.strip()
    spLine = line.replace('.', ' ').split()
    matches = set(spLine).intersection(queries)
    if len(matches) > 0:
        return matches, line.split('\t')
    return matches, False
1119825
def from_tuples(cls, tups):
        
        ivs = [Interval(*t) for t in tups]
        return IntervalTree(ivs)
987800
def _line_format(line):
    
    for pat in (FOUR_COL_REGEX, THREE_COL_REGEX, TWO_COL_REGEX):
        if pat.match(line):
            return pat
    raise ValueError("unable to parse segment from line {!r}".format(line))
967386
def match_reg(self, reg):
        

        mp = self.match_position

        match = reg.match(self.text, self.match_position)
        if match:
            (start, end) = match.span()
            if end == start:
                self.match_position = end + 1
            else:
                self.match_position = end
            self.matched_lineno = self.lineno
            lines = re.findall(r"\n", self.text[mp:self.match_position])
            cp = mp - 1
            while (cp >= 0 and cp < self.textlength and self.text[cp] != '\n'):
                cp -= 1
            self.matched_charpos = mp - cp
            self.lineno += len(lines)
            #print "MATCHED:", match.group(0), "LINE START:",
            # self.matched_lineno, "LINE END:", self.lineno
        #print "MATCH:", regexp, "\n", self.text[mp : mp + 15], \
        #          (match and "TRUE" or "FALSE")
        return match
1202298
def calculated_intervals(self, intervals):
        
        if len(intervals) > 1:
            raise ValueError("Only single calculated interval valid for AssetStream")
        super(AssetStream, self.__class__).calculated_intervals.fset(self, intervals)
1024172
def gaps(self) -> "IntervalList":
        
        if len(self.intervals) < 2:
            return IntervalList(None)
        gaps = []
        for i in range(len(self.intervals) - 1):
            gap = Interval(
                self.intervals[i].end,
                self.intervals[i + 1].start
            )
            gaps.append(gap)
        return IntervalList(gaps)
435003
def _interval_split(interval, only=None, context=None, event_re=re.compile("[A-Z][0-9]+")):
    
    def split_event(event):
        "Helper to parse events."
        kind, val = event[:1], event[1:]
        try:
            return kind, float(val)
        except (TypeError, ValueError):
            return None, 0

    if hasattr(interval, "fetch"):
        interval = interval.fetch("custom_activations")
    ##import sys; print >>sys.stderr, "!!!!!isplit", interval, event_re.findall(interval)

    return list(reversed([split_event(i) for i in event_re.findall(interval) if not only or i.startswith(only)]))
687546
def prep_regex(patterns):
    """"""

    flags = 0 if Config.options.case_sensitive else re.I

    return [re.compile(pattern, flags) for pattern in patterns]
753617
def _interpret_regexp(self, string, flags):
        ''''''
        self.index = 0
        self.length = len(string)
        self.source = string
        self.lineNumber = 0
        self.lineStart = 0
        octal = False
        st = ''
        inside_square = 0
        while (self.index < self.length):
            template = '[%s]' if not inside_square else '%s'
            ch = self.source[self.index]
            self.index += 1
            if ch == '\\':
                ch = self.source[self.index]
                self.index += 1
                if (not isLineTerminator(ch)):
                    if ch == 'u':
                        digs = self.source[self.index:self.index + 4]
                        if len(digs) == 4 and all(isHexDigit(d) for d in digs):
                            st += template % unichr(int(digs, 16))
                            self.index += 4
                        else:
                            st += 'u'
                    elif ch == 'x':
                        digs = self.source[self.index:self.index + 2]
                        if len(digs) == 2 and all(isHexDigit(d) for d in digs):
                            st += template % unichr(int(digs, 16))
                            self.index += 2
                        else:
                            st += 'x'
                    # special meaning - single char.
                    elif ch == '0':
                        st += '\\0'
                    elif ch == 'n':
                        st += '\\n'
                    elif ch == 'r':
                        st += '\\r'
                    elif ch == 't':
                        st += '\\t'
                    elif ch == 'f':
                        st += '\\f'
                    elif ch == 'v':
                        st += '\\v'

                    # unescape special single characters like . so that they are interpreted literally
                    elif ch in REGEXP_SPECIAL_SINGLE:
                        st += '\\' + ch

                    # character groups
                    elif ch == 'b':
                        st += '\\b'
                    elif ch == 'B':
                        st += '\\B'
                    elif ch == 'w':
                        st += '\\w'
                    elif ch == 'W':
                        st += '\\W'
                    elif ch == 'd':
                        st += '\\d'
                    elif ch == 'D':
                        st += '\\D'
                    elif ch == 's':
                        st += template % u' \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff'
                    elif ch == 'S':
                        st += template % u'\u0000-\u0008\u000e-\u001f\u0021-\u009f\u00a1-\u167f\u1681-\u180d\u180f-\u1fff\u200b-\u2027\u202a-\u202e\u2030-\u205e\u2060-\u2fff\u3001-\ufefe\uff00-\uffff'
                    else:
                        if isDecimalDigit(ch):
                            num = ch
                            while self.index < self.length and isDecimalDigit(
                                    self.source[self.index]):
                                num += self.source[self.index]
                                self.index += 1
                            st += '\\' + num

                        else:
                            st += ch  # DONT ESCAPE!!!
                else:
                    self.lineNumber += 1
                    if (ch == '\r' and self.source[self.index] == '\n'):
                        self.index += 1
                    self.lineStart = self.index
            else:
                if ch == '[':
                    inside_square = True
                elif ch == ']':
                    inside_square = False
                st += ch
        # print string, 'was transformed to', st
        return st
921514
def parse_interval_records(interval_record, interval_date, interval, uom,
                           quality_method) -> List[Reading]:
    
    interval_delta = timedelta(minutes=interval)
    return [
        Reading(
            t_start=interval_date + (i * interval_delta),
            t_end=interval_date + (i * interval_delta) + interval_delta,
            read_value=parse_reading(val),
            uom=uom,
            quality_method=quality_method,
            event_code="",  # event is unknown at time of reading
            event_desc="",  # event is unknown at time of reading
            read_start=None,
            read_end=None  # No before and after readings for intervals
        ) for i, val in enumerate(interval_record)
    ]
762666
def intervals(_min, _max=None, size=1):
    
    if _max == None:
        _max = _min
        _min = 0
    _max = int(mo_math.ceiling(_max))
    _min = int(mo_math.floor(_min))

    output = ((x, min(x + size, _max)) for x in _range(_min, _max, size))
    return output