Esempio n. 1
0
 def get_id_name(c):
     if c in ('_', '-', ' '):
         return '_'
     elif c.isalnum():
         return c
     elif PY3:
         return unicode_name(c).title().replace(' ', '')
     else:
         return unicode_name(unicode(c)).title().replace(' ', '')
Esempio n. 2
0
def symbol_to_identifier(symbol):
    """
    Converts a symbol string to an identifier (only alphanumeric and '_').
    """
    def get_id_name(c):
        if c.isalnum() or c == '_':
            return c
        else:
            return '%s_' % unicode_name(str(c)).title()

    if symbol.isalnum():
        return symbol
    elif symbol in SPECIAL_SYMBOLS:
        return symbol[1:-1]
    elif all(c in '-_' for c in symbol):
        value = '_'.join(unicode_name(str(c)).title() for c in symbol)
        return value.replace(' ', '').replace('-', '')

    value = symbol.replace('-', '_')
    if value.isidentifier():
        return value
    else:
        value = ''.join(get_id_name(c)
                        for c in symbol).replace(' ', '').replace('-', '')
        return value[:-1] if value.endswith('_') else value
def random_emoji(unicode_version=6):
    if unicode_version in EMOJI_RANGES_UNICODE:
        emoji_ranges = EMOJI_RANGES_UNICODE[unicode_version]
    else:
        emoji_ranges = EMOJI_RANGES_UNICODE[-1]

    # Weighted distribution
    count = [ord(r[-1]) - ord(r[0]) + 1 for r in emoji_ranges]
    weight_distr = list(accumulate(count))

    # Get one point in the multiple ranges
    point = randrange(weight_distr[-1])

    # Select the correct range
    emoji_range_idx = bisect(weight_distr, point)
    emoji_range = emoji_ranges[emoji_range_idx]

    # Calculate the index in the selected range
    point_in_range = point
    if emoji_range_idx is not 0:
        point_in_range = point - weight_distr[emoji_range_idx - 1]

    # Emoji 😄
    emoji = chr(ord(emoji_range[0]) + point_in_range)
    emoji_name = unicode_name(emoji, NO_NAME_ERROR).capitalize()
    emoji_codepoint = "U+{}".format(hex(ord(emoji))[2:].upper())

    return (emoji, emoji_codepoint, emoji_name)


# print(*random_emoji(UNICODE_VERSION), sep='\t')
Esempio n. 4
0
def random_emoji(unicode_version=6):
    if unicode_version in EMOJI_RANGES_UNICODE:
        emoji_ranges = EMOJI_RANGES_UNICODE[unicode_version]
    else:
        emoji_ranges = EMOJI_RANGES_UNICODE[-1]

    count = [ord(r[-1]) - ord(r[0]) + 1 for r in emoji_ranges]
    weight_distr = list(accumulate(count))

    point = randrange(weight_distr[-1])

    emoji_range_idx = bisect(weight_distr, point)
    emoji_range = emoji_ranges[emoji_range_idx]

    point_in_range = point
    if emoji_range_idx != 0:
        point_in_range = point - weight_distr[emoji_range_idx - 1]

    emoji = chr(ord(emoji_range[0]) + point_in_range)
    emoji_name = unicode_name(emoji, NO_NAME_ERROR).capitalize()
    emoji_codepoint = "U+{}".format(hex(ord(emoji))[2:].upper())

    return (emoji, emoji_codepoint, emoji_name)
Esempio n. 5
0
 def get_id_name(c):
     if c.isalnum() or c == '_':
         return c
     else:
         return '%s_' % unicode_name(str(c)).title()
Esempio n. 6
0
    def ausgabe(self,text):
        
        try:
            
            blocks_sortiert = sorted(int(a) for a in list(self.blocks))
                
            buchstaben_set = set(text)
            buchstaben_liste = list(text)
            
    
            codepoints = {}
            codepoints_b = {}
            for a in buchstaben_set:
                codepoints.update({ord(a):a})
                codepoints_b.update({a:ord(a)})
                 
            codepoints_sortiert = sorted(list(codepoints))
            
            verwendete_Buchstaben = []
            for s in codepoints_sortiert:
                x = bisect_right(blocks_sortiert,s)
                unr = blocks_sortiert[x-1]
                verwendete_Buchstaben.append((unr,self.blocks[str(unr)],unichr(s)))
            
            
            dict_gr_BS = {}
            dict_auszuschliessende = {}
             
            for z in verwendete_Buchstaben:
                if u'Greek' in z[1]:
                    dict_gr_BS.update({z[2]:(z[1],z[0])})
                elif z[0] > 256:
                    dict_auszuschliessende.update({z[2]:(z[1],z[0])})
                
            
            verwendete = [u'A searchable unicode table can be found at: http://unicode-table.com\n',
                          u'An editor which is able to view all unicode signs is for example: Notepad++ \n',
                          u'\n',
                          u'%-5s %-8s %-30s %-20s \n' %(u'Sign',u'Dec',u'Unicode Block',u'Name'),
                          u'\n',]
            
            zu_tauschende = {}
            zu_t = []
            for vw in verwendete_Buchstaben:
                v1 = vw[1]
                v2 = vw[2]
                v3 = codepoints_b[v2]
                v4 = unicode_name(v2,'not defined, search in unicode table')
                
                if v1 == 'Control Character':
                    v2 = ' '
                    
                if v1 in ["Spacing Modifier Letters","Combining Diacritical Marks"]:
                    zu_tauschende.update({v2:v3})
                    zu_t.append(v2)
                    
                ausg = '%-5s %-8s %-30s %-20s \n' %(v2,v3,v1,v4) 
                verwendete.append(ausg)
            
 
            
            neuer_text = []
            greek = False
    
            pu = Punctuation + ' '
            pu = pu.replace('{','').replace('}','').replace('\\','')
            
            for b in buchstaben_liste:
                if b in zu_t:
                    b = 'XXX'+str(zu_tauschende[b])+'XXX'
                if b in verbotene_Buchstaben:
                    b = verbotene_Buchstaben[b]
                elif b == '_':
                    b = ' '
                if b in pu:
                    neuer_text.append(b)
                    continue
                    
                elif b not in dict_gr_BS:
                    if greek == True:
                        neuer_text.append('}')
                        greek = False
                    neuer_text.append(b)
                else:
                    if greek == False:
                        greek = True
                        neuer_text.append('\\textgreek{')
                        neuer_text.append(b)
                    else:
                        neuer_text.append(b)
                        

            pfad1 = self.path+'.tex'
            pfad2 = self.path +'_used_letters.txt'
            
            
            text_ver = ''.join(verwendete)
            self.speicher(text_ver,'w',pfad2)
            
            
            self.speicher(neuer_text,'w',pfad1)
        except:
            log(inspect.stack,tb())