def _summarize_blocks(start, limit, defined_cps, cp_to_scripts, all_scripts): block = None block_count = 0 defined_count = 0 script_counts = None for cp in range(start, limit): cp_block = unicode_data.block(cp) if cp_block != block: if block: _summarize_block( block, block_count, defined_count, script_counts) block = cp_block block_count = 0 defined_count = 0 script_counts = collections.defaultdict(int) block_count += 1 is_defined = cp in defined_cps and cp not in _OMITTED if not is_defined: continue defined_count += 1 scripts = _get_scripts(cp, cp_to_scripts) for script in scripts: script_counts[script] += 1 _summarize_block(block, block_count, defined_count, script_counts)
def _list_blocks(start, limit, defined_cps, cp_to_scripts, all_scripts, only_scripts, details): start_cp = -1 defined_count = 0 block = None showed_block = False scripts = None skip_empty = bool(only_scripts) for cp in range(start, limit): is_defined = cp in defined_cps cp_block = unicode_data.block(cp) cp_scripts = _get_scripts(cp, cp_to_scripts) if is_defined else None if cp_block != block or (cp_scripts and scripts and cp_scripts != scripts): if block and block != 'No_Block': if not (skip_empty and _is_empty_scripts(scripts)): if not showed_block: print('...') if block == 'No_Block' else block showed_block = True _list_range(start_cp, cp, defined_cps, defined_count, scripts, all_scripts, only_scripts, details) start_cp = cp defined_count = 0 if cp_block != block: block = cp_block showed_block = False scripts = None if is_defined: scripts = cp_scripts defined_count += 1 if not (skip_empty and _is_empty_scripts(scripts)): if not showed_block: print('...') if block == 'No_Block' else block _list_range(start_cp, limit, defined_cps, defined_count, scripts, all_scripts, only_scripts, details)
def _print_detailed(cps, inverted_target=None): last_block = None for cp in sorted(cps): block = unicode_data.block(cp) if block != last_block: print ' %s' % block last_block = block script = unicode_data.script(cp) extensions = unicode_data.script_extensions(cp) - set([script]) if extensions: extensions = ' (%s)' % ','.join(sorted(extensions)) else: extensions = '' if not inverted_target: extra = '' elif cp not in inverted_target: extra = ' !missing' else: scripts = sorted(inverted_target[cp]) if len(scripts) > 3: script_text = ', '.join(scripts[:3]) + '... ' + scripts[-1] else: script_text = ', '.join(scripts) extra = ' (in %s)' % script_text print ' %6s %4s %2s %3s %s%s%s' % ( '%04x' % cp, script, unicode_data.category(cp), unicode_data.age(cp), unicode_data.name(cp, ''), extensions, extra)
def _print_detailed(cps, inverted_target=None): last_block = None undefined_start = -1 undefined_end = -1 def show_undefined(start, end): if start >= 0: if end > start: print(" %04x-%04x Zzzz <%d undefined>" % (start, end, end - start - 1)) else: print(" %04x Zzzz <1 undefined>" % start) for cp in sorted(cps): block = unicode_data.block(cp) if block != last_block or (undefined_end > -1 and cp > undefined_end + 1): show_undefined(undefined_start, undefined_end) undefined_start, undefined_end = -1, -1 if block != last_block: print(" %s" % block) last_block = block script = unicode_data.script(cp) if script == "Zzzz": if undefined_start >= 0: undefined_end = cp else: undefined_start, undefined_end = cp, cp continue show_undefined(undefined_start, undefined_end) undefined_start, undefined_end = -1, -1 extensions = unicode_data.script_extensions(cp) - {script} if extensions: extensions = " (script %s)" % ", ".join(sorted(extensions)) else: extensions = "" if not inverted_target: extra = "" elif cp not in inverted_target: extra = " !missing" else: scripts = sorted(inverted_target[cp]) if len(scripts) > 3: script_text = ", ".join(scripts[:3]) + "... " + scripts[-1] else: script_text = ", ".join(scripts) extra = " (font %s)" % script_text print(" %6s %4s %2s %3s %s%s%s" % ( "%04x" % cp, script, unicode_data.category(cp), unicode_data.age(cp), unicode_data.name(cp, ""), extensions, extra, )) show_undefined(undefined_start, undefined_end)
def show_cps_by_block(cps): print('%d missing codepoints' % len(cps)) block = None for cp in sorted(cps): new_block = unicode_data.block(cp) if new_block != block: print('# %s' % new_block) block = new_block print('%5s %s' % ('%04x' % cp, unicode_data.name(cp)))
def show_cps_by_block(cps): print("%d missing codepoints" % len(cps)) block = None for cp in sorted(cps): new_block = unicode_data.block(cp) if new_block != block: print("# %s" % new_block) block = new_block print("%5s %s" % ("%04x" % cp, unicode_data.name(cp)))
def show_cps_by_block(cps): print '%d missing codepoints' % len(cps) block = None for cp in sorted(cps): new_block = unicode_data.block(cp) if new_block != block: print '# %s' % new_block block = new_block print '%5s %s' % ('%04x' % cp, unicode_data.name(cp))
def _print_detailed(cps, inverted_target=None): last_block = None undefined_start = -1 undefined_end = -1 def show_undefined(start, end): if start >= 0: if end > start: print ' %04x-%04x Zzzz <%d undefined>' % ( start, end, end - start - 1) else: print ' %04x Zzzz <1 undefined>' % start for cp in sorted(cps): block = unicode_data.block(cp) if block != last_block or (undefined_end > -1 and cp > undefined_end + 1): show_undefined(undefined_start, undefined_end) undefined_start, undefined_end = -1, -1 if block != last_block: print ' %s' % block last_block = block script = unicode_data.script(cp) if script == 'Zzzz': if undefined_start >= 0: undefined_end = cp else: undefined_start, undefined_end = cp, cp continue show_undefined(undefined_start, undefined_end) undefined_start, undefined_end = -1, -1 extensions = unicode_data.script_extensions(cp) - set([script]) if extensions: extensions = ' (%s)' % ','.join(sorted(extensions)) else: extensions = '' if not inverted_target: extra = '' elif cp not in inverted_target: extra = ' !missing' else: scripts = sorted(inverted_target[cp]) if len(scripts) > 3: script_text = ', '.join(scripts[:3]) + '... ' + scripts[-1] else: script_text = ', '.join(scripts) extra = ' (in %s)' % script_text print ' %6s %4s %2s %3s %s%s%s' % ( '%04x' % cp, script, unicode_data.category(cp), unicode_data.age(cp), unicode_data.name(cp, ''), extensions, extra) show_undefined(undefined_start, undefined_end)
def _list_blocks( start, limit, defined_cps, cp_to_scripts, all_scripts, only_scripts, details): start_cp = -1 defined_count = 0 block = None showed_block = False scripts = None skip_empty = bool(only_scripts) for cp in range(start, limit): is_defined = cp in defined_cps cp_block = unicode_data.block(cp) cp_scripts = _get_scripts(cp, cp_to_scripts) if is_defined else None if cp_block != block or ( cp_scripts and scripts and cp_scripts != scripts): if block and block != 'No_Block': if not (skip_empty and _is_empty_scripts(scripts)): if not showed_block: print '...' if block == 'No_Block' else block showed_block = True _list_range( start_cp, cp, defined_cps, defined_count, scripts, all_scripts, only_scripts, details) start_cp = cp defined_count = 0 if cp_block != block: block = cp_block showed_block = False scripts = None if is_defined: scripts = cp_scripts defined_count += 1 if not (skip_empty and _is_empty_scripts(scripts)): if not showed_block: print '...' if block == 'No_Block' else block _list_range( start_cp, limit, defined_cps, defined_count, scripts, all_scripts, only_scripts, details)
def test_block(self): """Tests the block() method.""" self.assertEqual('Emoticons', unicode_data.block(0x1F600))