def _main(cmd): import sys dirs = cmd.argv or (".", ) if cmd.newlines: sep = "\n" else: sep = cmd.separator if cmd.transitive: fct = subdirs_transitive elif cmd.basenames: fct = subdir_names else: fct = subdirs result = [] for d in dirs: result.extend(fct(d)) for exc in cmd.exclude: result = [r for r in result if r != exc] if cmd.re_exclude: from _TFL.Regexp import Regexp exc = Regexp(cmd.re_exclude) result = [r for r in result if not exc.search(r)] if cmd.lstrip: result = [r.lstrip(cmd.lstrip) for r in result] if result: result.sort() sys.stdout.write(sep.join(result) + "\n")
def _main (cmd) : import sys dirs = cmd.argv or (".", ) if cmd.newlines : sep = "\n" else : sep = cmd.separator if cmd.transitive : fct = subdirs_transitive elif cmd.basenames : fct = subdir_names else : fct = subdirs result = [] for d in dirs : result.extend (fct (d)) for exc in cmd.exclude : result = [r for r in result if r != exc] if cmd.re_exclude : from _TFL.Regexp import Regexp exc = Regexp (cmd.re_exclude) result = [r for r in result if not exc.search (r)] if cmd.lstrip : result = [r.lstrip (cmd.lstrip) for r in result] if result : result.sort () sys.stdout.write (sep.join (result) + "\n")
def _gen(): for p in patterns: if p == "*": yield self._rules elif p.startswith(":"): for scope in (CAL.Day_Rule, CAL): cls = getattr(scope, p[1:], None) if cls is not None: break else: raise NameError(p) yield (r for r in self._rules if isinstance(r, cls)) elif p.startswith("~"): from _TFL.Regexp import Regexp re = Regexp(p[1:]) yield (r for r in self._rules if re.search(r.name)) else: rbn = self.rules_by_name yield \ ( rbn [n] for n in self.rule_name_trie.completions (p) [0] )
def create_map \ ( self , ignore_categories = {"Cc", "Cs", "Co", "Cn", "Zl"} , ignore_prefixes = _ignore_prefixes ) : """Create a map char-id -> char-code. `char-id` is a valid Python identifier derived from `unidoce.name`. """ from _TFL.Ascii import sanitized_filename from _TFL.formatted_repr import formatted_repr from _TFL.Regexp import Regexp, re import unicodedata ignore_categories = Regexp ("|".join (sorted (ignore_categories))) ignore_prefixes = Regexp ("|".join (sorted (ignore_prefixes))) result = {} for i in range (0x1, 0xf000) : c = chr (i) cat = unicodedata.category (c) if ignore_categories.match (cat) : continue try : ucd_name = unicodedata.name (c) except ValueError : continue id = sanitized_filename (ucd_name.lower ()).replace ("-", "_") if not ignore_prefixes.search (id) : result [id] = r"u%04x" % i result = "\n".join \ ( ( "# -*- coding: utf-8 -*-" , "# Copyright (C) 2020 Mag. Christian Tanzer All rights reserved" , "# Generated automatically, do not change manually!" , "" , "id_to_chr_map = \\" , formatted_repr (result).replace (": 'u", r": '\u") ) ) return result