Create a sedes for text data with exactly `l` encoded characters.
960188
def fixed_length(cls, l, allow_empty=False):
        """"""
        return cls(l, l, allow_empty=allow_empty)
767665
def idf2txt(txt):
    """"""
    astr = nocomment(txt)
    objs = astr.split(';')
    objs = [obj.split(',') for obj in objs]
    objs = [[line.strip() for line in obj] for obj in objs]
    objs = [[_tofloat(line) for line in obj] for obj in objs]
    objs = [tuple(obj) for obj in objs]
    objs.sort()

    lst = []
    for obj in objs:
        for field in obj[:-1]:
            lst.append('%s,' % (field, ))
        lst.append('%s;\n' % (obj[-1], ))

    return '\n'.join(lst)
831009
def write_ln(self, *text, sep=' '):
        
        if self.text and self.text[-1] != '\n':
            self.text += '\n'
        self.text += markdown.text(*text, sep) + '\n'
        return self
150570
def encode(data, checksum=True):
    """"""

    if checksum:
        data = data + utils.hash256(data)[:4]
    v, prefix = to_long(256, lambda x: x, iter(data))
    data = from_long(v, prefix, BASE58_BASE, lambda v: BASE58_ALPHABET[v])
    return data.decode("utf8")
539511
def iter_text_fixups(data, encoding):
    """"""

    yield data
    if encoding == Encoding.UTF16BE:
        # wrong termination
        yield data + b"\x00"
    elif encoding == Encoding.UTF16:
        # wrong termination
        yield data + b"\x00"
        # utf-16 is missing BOM, content is usually utf-16-le
        yield codecs.BOM_UTF16_LE + data
        # both cases combined
        yield codecs.BOM_UTF16_LE + data + b"\x00"
1225619
def text(self, encoding=None, errors='strict'):
        
        """
        with self.open(mode='r', encoding=encoding, errors=errors) as f:
            return U_NEWLINE.sub('\n', f.read())
1088220
def encode(self, s):
    """"""
    s = tf.compat.as_text(s)
    tokens = self._tokenizer.tokenize(s)
    tokens = _prepare_tokens_for_encode(tokens)
    ids = []
    for token in tokens:
      ids.extend(self._token_to_ids(token))
    return text_encoder.pad_incr(ids)
751742
def text_to_data(self, text, elt, ps):
        '''
        '''
        if text is None:
            return None
        
        m = self.lex_pattern.match(text)
        if not m:
            raise EvaluateException('Bad Gregorian: %s' %text, ps.Backtrace(elt))
        try:
            retval = _dict_to_tuple(m.groupdict())
        except ValueError, e:
            #raise EvaluateException(str(e))
            raise
        
        if self.pyclass is not None:
            return self.pyclass(retval)
        return retval
422820
def decode_text(s):
    """"""
    if s.startswith(b'\xfe\xff'):
        return unicode(s[2:], 'utf-16be', 'ignore')
    else:
        return ''.join(PDFDocEncoding[ord(c)] for c in s)
968088
def any2unicode(text, encoding='utf8', errors='strict'):
    """"""
    if isinstance(text, unicode):
        return text
    return unicode(text, encoding, errors=errors)
1322406
def normalize(self, text):
        
        # Normalize to canonical unicode (using NFKC by default)
        if self.form is not None:
            text = unicodedata.normalize(self.form, text)

        # Strip out any control characters (they occasionally creep in somehow)
        for control in CONTROLS:
            text = text.replace(control, '')

        # Normalize unusual whitespace not caught by unicodedata
        text = text.replace('\u000b', ' ').replace('\u000c', ' ').replace(u'\u0085', ' ')
        text = text.replace('\u2028', '\n').replace('\u2029', '\n').replace('\r\n', '\n').replace('\r', '\n')

        # Normalize all hyphens, minuses and dashes to ascii hyphen-minus and remove soft hyphen entirely
        if self.hyphens:
            # TODO: Better normalization of em/en dashes to '--' if surrounded by spaces or start/end?
            for hyphen in HYPHENS | MINUSES:
                text = text.replace(hyphen, '-')
            text = text.replace('\u00ad', '')

        # Normalize all quotes and primes to ascii apostrophe and quotation mark
        if self.quotes:
            for double_quote in DOUBLE_QUOTES:
                text = text.replace(double_quote, '"')  # \u0022
            for single_quote in (SINGLE_QUOTES | APOSTROPHES | ACCENTS):
                text = text.replace(single_quote, "'")  # \u0027
            text = text.replace('′', "'")     # \u2032 prime
            text = text.replace('‵', "'")     # \u2035 reversed prime
            text = text.replace('″', "''")    # \u2033 double prime
            text = text.replace('‶', "''")    # \u2036 reversed double prime
            text = text.replace('‴', "'''")   # \u2034 triple prime
            text = text.replace('‷', "'''")   # \u2037 reversed triple prime
            text = text.replace('⁗', "''''")  # \u2057 quadruple prime

        if self.ellipsis:
            text = text.replace('…', '...').replace(' . . . ', ' ... ')  # \u2026

        if self.slashes:
            for slash in SLASHES:
                text = text.replace(slash, '/')

        if self.tildes:
            for tilde in TILDES:
                text = text.replace(tilde, '~')

        if self.strip:
            text = text.strip()

        # Collapse all whitespace down to a single space
        if self.collapse:
            text = ' '.join(text.split())
        return text
704658
def _regex_from_encoded_pattern(s):
    """'
    """
    if s.startswith('/') and s.rfind('/') != 0:
        # Parse it: /PATTERN/FLAGS
        idx = s.rfind('/')
        pattern, flags_str = s[1:idx], s[idx+1:]
        flag_from_char = {
            "i": re.IGNORECASE,
            "l": re.LOCALE,
            "s": re.DOTALL,
            "m": re.MULTILINE,
            "u": re.UNICODE,
        }
        flags = 0
        for char in flags_str:
            try:
                flags |= flag_from_char[char]
            except KeyError:
                raise ValueError("unsupported regex flag: '%s' in '%s' "
                                 "(must be one of '%s')"
                                 % (char, s, ''.join(list(flag_from_char.keys()))))
        return re.compile(s[1:idx], flags)
    else: # not an encoded regex
        return re.compile(re.escape(s))
537887
def _raw(s):
    """"""

    if isinstance(s, list):
        s = "\n".join(_raw(item) for item in s)

    if s == EOF:
        return "EOF"

    s = repr(s)  # Get raw representation of string
    s = s[1:-1]  # Strip away quotation marks
    if len(s) > 15:
        s = s[:15] + "..."  # Truncate if too long
    return s
903221
def convert_nonascii(self, lst):
        """"""
        for item in lst:
            if item.startswith('"') and item.endswith('"'):
                item = item[1:-1]
                yield item.encode('utf-8').decode('unicode-escape')
            else:
                yield item.encode('utf-8').decode('unicode-escape')
448294
def unicode_safe(text, encoding=UrlEncoding, errors='ignore'):
    """"""
    try:
        text_type = unicode
    except NameError:
        text_type = str
    if isinstance(text, text_type):
        return text
    return text.decode(encoding, errors)
1282193
def _sed_esc(string, escape_all=False):
    '''
    
    '''
    special_chars = "^.[$()|*+?{"
    string = string.replace("'", "'\"'\"'").replace("/", "\\/")
    if escape_all is True:
        for char in special_chars:
            string = string.replace(char, "\\" + char)
    return string
209407
def encode(self, text: str) -> str:
        """"""

        def callback(match: Match) -> str:
            name = match.group("name").lower()
            if name in ["here", "everyone", "channel"]:
                return f"<!{name}>"
            else:
                for user in self.users.values():
                    if user.name == name:
                        return f"<@{user.id}>"
            return match.group(0)

        return self.encode_re.sub(callback, text)