def gen_age(output, ascii_props=False, append=False, prefix=""):
    """Generate `age` property."""

    obj = {}
    all_chars = ALL_ASCII if ascii_props else ALL_CHARS
    with codecs.open(os.path.join(HOME, 'unicodedata', UNIVERSION, 'DerivedAge.txt'), 'r', 'utf-8') as uf:
        for line in uf:
            if not line.startswith('#'):
                data = line.split('#')[0].split(';')
                if len(data) < 2:
                    continue
                span = create_span([int(i, 16) for i in data[0].strip().split('..')], is_bytes=ascii_props)
                name = format_name(data[1])

                if name not in obj:
                    obj[name] = []

                if span is None:
                    continue

                obj[name].extend(span)

    unassigned = set()
    for x in obj.values():
        unassigned |= set(x)
    obj['na'] = list(all_chars - unassigned)

    for name in list(obj.keys()):
        s = set(obj[name])
        obj[name] = sorted(s)

    # Convert characters values to ranges
    char2range(obj, is_bytes=ascii_props)

    with codecs.open(output, 'a' if append else 'w', 'utf-8') as f:
        if not append:
            f.write(HEADER)
        # Write out the Unicode properties
        f.write('%s_age = {\n' % prefix)
        count = len(obj) - 1
        i = 0
        for k1, v1 in sorted(obj.items()):
            f.write('    "%s": "%s"' % (k1, v1))
            if i == count:
                f.write('\n}\n')
            else:
                f.write(',\n')
            i += 1
def gen_age ( output , ascii_props = False , append = False , prefix = "" ) : obj = { } all_chars = ALL_ASCII if ascii_props else ALL_CHARS with codecs . open ( os . path . join ( HOME , 'unicodedata' , UNIVERSION , 'DerivedAge.txt' ) , 'r' , 'utf-8' ) as uf : for line in uf : if not line . startswith ( '#' ) : data = line . split ( '#' ) [ 0 ] . split ( ';' ) if len ( data ) < 2 : continue span = create_span ( [ int ( i , 16 ) for i in data [ 0 ] . strip ( ) . split ( '..' ) ] , is_bytes = ascii_props ) name = format_name ( data [ 1 ] ) if name not in obj : obj [ name ] = [ ] if span is None : continue obj [ name ] . extend ( span ) unassigned = set ( ) for x in obj . values ( ) : unassigned |= set ( x ) obj [ 'na' ] = list ( all_chars - unassigned ) for name in list ( obj . keys ( ) ) : s = set ( obj [ name ] ) obj [ name ] = sorted ( s ) char2range ( obj , is_bytes = ascii_props ) with codecs . open ( output , 'a' if append else 'w' , 'utf-8' ) as f : if not append : f . write ( HEADER ) f . write ( '%s_age = {\n' % prefix ) count = len ( obj ) - 1 i = 0 for k1 , v1 in sorted ( obj . items ( ) ) : f . write ( '    "%s": "%s"' % ( k1 , v1 ) ) if i == count : f . write ( '\n}\n' ) else : f . write ( ',\n' ) i += 1
Generate `age` property.