Ejemplo n.º 1
0
def save_intersecting(output_dir, words, match_dict):
    """
     Save intersectnig matches into one single text file.

    :param output_dir: directory to save file in
    :param words: the word combinations which were searched for
    :param match_dict: a dictionary of matches
    """
    filename = join(output_dir, 'shared_' + '+'.join(
        sorted(words, key=str.lower)) + '.txt')

    file = open(filename, 'w')

    # use lambda for sorting the matches lowercased
    # (otherwise matches starting with a capital letter get sorted first)
    # ATTN not working!
    # strxfrm for umlaut sorting broken in several German locales on OS X?
    matches = dict(match_dict)
    for combo, results in sorted(matches.items(),
                                 key=lambda w: (
                                         strxfrm(''.join(w[0]).lower()),
                                         strxfrm(''.join(w[1]).lower()))):

        # separator
        combo_combined = '+'.join(combo)
        sep = '-' * len(combo_combined)
        file.write(combo_combined + '\n')
        file.write(sep + '\n')

        for res in results:
            file.write(res + '\n')
        file.write('\n')

    file.close()
Ejemplo n.º 2
0
def locale_convert(val, func, group):
    """\
    Attempt to convert a string to a number, first converting
    the decimal place character if needed. Then, if the conversion
    was not possible (i.e. it is not a number), run it through
    strxfrm to make the work sorting as requested, possibly grouping first.
    """

    # Format the number so that the conversion function can interpret it.
    radix = localeconv()['decimal_point']
    s = val.replace(radix, '.') if radix != '.' else val

    # Perform the conversion
    t = func[0](s)

    # Return the number or transformed string.
    # If the input is identical to the output, then no conversion happened.
    # In this case, we don't want to return the function output because it
    # may have had characters modified from the above 'replace' call,
    # so we return the input.
    if group:
        if use_pyicu:
            xfrm = get_pyicu_transform(getlocale())
            return xfrm(groupletters(val)) if not func[1](t) else t
        else:
            return strxfrm(groupletters(val)) if not func[1](t) else t
    else:
        if use_pyicu:
            xfrm = get_pyicu_transform(getlocale())
            return xfrm(val) if not func[1](t) else t
        else:
            return strxfrm(val) if not func[1](t) else t
Ejemplo n.º 3
0
    def render(self, name, value, *args, **kwargs):
        context = {'ins_courts': self.ins_courts, 'value': value}
        if self.ins_courts:
            context['courts'] = sorted(
                [{'id': x, 'name': L2N[x]} for x in Vec.objects.values_list('idOsobyPuvodce', flat=True).distinct()],
                key=lambda x: strxfrm(x['name']))
        else:
            sel = ['VSPHAAB', 'VSSEMOL']
            if self.supreme_court:
                sel.append('NSJIMBM')
            if self.supreme_administrative_court:
                sel.append('NSS')
            high_courts = Court.objects.filter(id__in=sel).order_by('name')
            high_label = (
                'Nejvyšší a vrchní soudy'
                if self.supreme_administrative_court or self.supreme_administrative_court
                else 'Vrchní soudy')
            high_group = {'label': high_label, 'courts': high_courts}
            context['optgroups'] = [high_group]
            reg_courts = (
                Court.objects.filter(id__startswith='KS').union(Court.objects.filter(id='MSPHAAB')).order_by('name'))
            reg_group = {'label': 'Krajské soudy', 'courts': reg_courts}
            context['optgroups'].append(reg_group)
            for reg_court in reg_courts:
                county_courts = sorted(
                    list(Court.objects.filter(reports=reg_court).order_by('name').values('id', 'name')),
                    key=lambda x: strxfrm('Z' if x['name'].endswith('10') else x['name']))
                county_group = {'label': reg_court.name, 'courts': county_courts}
                context['optgroups'].append(county_group)

        return mark_safe(get_template('widgets/select_court.xhtml').render(context))
Ejemplo n.º 4
0
def strxfrm(x):
    """Like locale.strxfrm but also supports Unicode.

    This works around a bug in Python 2 causing strxfrm to fail on unicode
    objects that cannot be encoded with sys.getdefaultencoding (ASCII in most
    cases): https://bugs.python.org/issue2481
    """
    import locale
    if isinstance(x, unicode):
        return locale.strxfrm(x.encode('utf-8', 'replace'))
    return locale.strxfrm(x)
Ejemplo n.º 5
0
    def __date_comp(self, task1, task2, para, order):
        '''This is a quite complex method to sort tasks by date,
        handling fuzzy date and complex situation.
        Return -1 if nid1 is before nid2, return 1 otherwise
        '''
        if task1 and task2:
            if para == 'start':
                t1 = task1.get_start_date()
                t2 = task2.get_start_date()
            elif para == 'due':
                t1 = task1.get_urgent_date()
                t2 = task2.get_urgent_date()
                if t1 == Date.no_date():
                    t1 = task1.get_due_date_constraint()
                if t2 == Date.no_date():
                    t2 = task2.get_due_date_constraint()
            elif para == 'closed':
                t1 = task1.get_closed_date()
                t2 = task2.get_closed_date()
            else:
                raise ValueError(
                    'invalid date comparison parameter: %s') % para
            sort = (t2 > t1) - (t2 < t1)
        else:
            sort = 0

        # local function
        def reverse_if_descending(s):
            """Make a cmpare result relative to the top instead of following
               user-specified sort direction"""
            if order == Gtk.SortType.ASCENDING:
                return s
            else:
                return -1 * s

        if sort == 0:
            # Group tasks with the same tag together for visual cleanness
            t1_tags = task1.get_tags_name()
            t1_tags.sort()
            t2_tags = task2.get_tags_name()
            t2_tags.sort()
            cmp_tags = (t1_tags > t2_tags) - (t1_tags < t2_tags)
            sort = reverse_if_descending(cmp_tags)

        if sort == 0:
            # Break ties by sorting by title
            t1_title = task1.get_title()
            t2_title = task2.get_title()
            t1_title = locale.strxfrm(t1_title)
            t2_title = locale.strxfrm(t2_title)
            cmp_title = (t1_title > t2_title) - (t1_title < t2_title)
            sort = reverse_if_descending(cmp_title)

        return sort
    def __date_comp(self,task1,task2,para,order):
        '''This is a quite complex method to sort tasks by date,
        handling fuzzy date and complex situation.
        Return -1 if nid1 is before nid2, return 1 otherwise
        '''
        if task1 and task2:
            if para == 'start':
                t1 = task1.get_start_date()
                t2 = task2.get_start_date()
            elif para == 'due':
                t1 = task1.get_due_date()
                t2 = task2.get_due_date()
            elif para == 'closed':
                t1 = task1.get_closed_date()
                t2 = task2.get_closed_date()
            else:
                raise ValueError('invalid date comparison parameter: %s')%para
            sort = cmp(t2,t1)
        else:
            sort = 0
        
        #local function
        def reverse_if_descending(s):
            """Make a cmp() result relative to the top instead of following 
               user-specified sort direction"""
            if order == gtk.SORT_ASCENDING:
                return s
            else:
                return -1*s

        if sort == 0:
            # Put fuzzy dates below real dates
            if isinstance(t1, dates.FuzzyDate) \
               and not isinstance(t2, dates.FuzzyDate):
                sort = reverse_if_descending(1)
            elif isinstance(t2, dates.FuzzyDate) \
                    and not isinstance(t1, dates.FuzzyDate):
                sort = reverse_if_descending(-1)
        
        if sort == 0: # Group tasks with the same tag together for visual cleanness 
            t1_tags = task1.get_tags_name()
            t1_tags.sort()
            t2_tags = task2.get_tags_name()
            t2_tags.sort()
            sort = reverse_if_descending(cmp(t1_tags, t2_tags))
            
        if sort == 0:  # Break ties by sorting by title
            t1_title = task1.get_title()
            t2_title = task2.get_title()
            t1_title = locale.strxfrm(t1_title)
            t2_title = locale.strxfrm(t2_title)
            sort = reverse_if_descending(cmp(t1_title, t2_title))
        
        return sort
Ejemplo n.º 7
0
    def sort_medias(self, medias_sort_attr):
        if self.medias:
            if medias_sort_attr == 'date':
                key = lambda s: s.date or datetime.now()
            elif medias_sort_attr.startswith('meta.'):
                meta_key = medias_sort_attr.split(".", 1)[1]
                key = lambda s: locale.strxfrm(s.meta.get(meta_key, [''])[0])
            else:
                key = lambda s: locale.strxfrm(getattr(s, medias_sort_attr))

            self.medias.sort(key=key,
                             reverse=self.settings['medias_sort_reverse'])

        signals.medias_sorted.send(self)
Ejemplo n.º 8
0
def mailbox_sort_key(mailbox):
    if mailbox is None:
        return None
    elif mailbox == 'INBOX':
        # INBOX always comes first.
        return 0, None, mailbox
    elif mailbox.startswith('[Gmail]'):
        # [Gmail] stuff goes last.
        return 2, locale.strxfrm(mailbox.casefold()), mailbox
    else:
        # Everything else is sorted alphabetically ignoring case and respecting
        # locale. Ties are broken lexicographically (this can happen if there
        # are two mailboxes which differ only in case; Gmail doesn't allow this
        # but other mail servers might).
        return 1, locale.strxfrm(mailbox.casefold()), mailbox
Ejemplo n.º 9
0
 def tag_sorting(self, t1, t2, order):
     t1_sp = t1.get_attribute("special")
     t2_sp = t2.get_attribute("special")
     t1_name = locale.strxfrm(t1.get_name())
     t2_name = locale.strxfrm(t2.get_name())
     if not t1_sp and not t2_sp:
         return (t1_name > t2_name) - (t1_name < t2_name)
     elif not t1_sp and t2_sp:
         return 1
     elif t1_sp and not t2_sp:
         return -1
     else:
         t1_order = t1.get_attribute("order")
         t2_order = t2.get_attribute("order")
         return (t1_order > t2_order) - (t1_order < t2_order)
Ejemplo n.º 10
0
Archivo: MyOLV.py Proyecto: kuhout/agi
 def _getSortValue(x):
   primary = sortColumn.GetValue(x)
   try:
     primary = locale.strxfrm(primary.lower().encode('utf-8'))
   except AttributeError:
     pass
   result = [primary]
   for col in secondarySortColumns:
     secondary = col.GetValue(x)
     try:
       secondary = locale.strxfrm(secondary.lower().encode('utf-8'))
     except AttributeError:
       pass
     result.append(secondary)
   return tuple(result)
Ejemplo n.º 11
0
def members_letter(request, letter):
    member_index = defaultdict(lambda: defaultdict(list))

    for fs in VerbNetFrameSet.objects.prefetch_related(
            'verbnet_class', 'verbnet_class__levin_class',
            Prefetch('verbtranslation_set',
                     queryset=VerbTranslation.objects.filter(verb__startswith=letter),
                     to_attr='filtered_verbs')):
        if fs.removed:
            continue

        for verbtranslation in VerbTranslation.all_valid(fs.filtered_verbs):
            member_index[verbtranslation.verb][fs.verbnet_class.levin_class.number].append(fs)

    for verb in member_index:
        for levin_group in member_index[verb]:
            member_index[verb][levin_group] = sorted(member_index[verb][levin_group], key=lambda fs: LooseVersion(fs.name))
        member_index[verb] = OrderedDict(sorted(member_index[verb].items(), key=lambda kv: LooseVersion(kv[0])))
    member_index = OrderedDict(sorted(member_index.items(), key=lambda kv: locale.strxfrm(kv[0])))

    return render(request, 'member_index.html', {
        'member_index': member_index,
        'active_letter': letter,
        'letter_list': [
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    })
Ejemplo n.º 12
0
def print_results(word, match_dict):
    """
    Print all matches found for a word to stdout.

    :param word: a word that was looked for
    :param match_dict: dictionary of matches for that word
    """
    # create 'headline'
    sep = '-' * len(word)
    print(sep)
    print(str(word))
    print(sep)

    # account for intersected word sets
    if isinstance(match_dict, set):
        matches = {str(match_dict): ''}
    else:
        matches = dict(match_dict)

    # use lambda for sorting the matches lowercased
    # (otherwise matches starting with a capital letter get sorted first)
    # ATTN not working!
    # strxfrm for umlaut sorting broken in several German locales on OS X
    for word, suppl in sorted(matches.items(),
                              key=lambda w: strxfrm(w[0].lower())):
        print(word, end=' ')
    print()
def sort_key(str):
 #  sort -k 1,1 -k 3,3 -k 2,2 -t ' '
  lemma, word, tag = str.split(' ')
  
  # дефіс та апостроф при сортуванні ігнорується, щоб леми, що різняться лише дефісом або апострофом
  # не змішувалися додаємо ще символи

  if "-" in lemma:
    lemma += "я"

  if "'" in lemma:
    lemma += "я"
  
  # коротка форма, напр. повен - це не лема, тож відсуваємо його після леми
  
  if word.endswith("ен") and "adj" in tag:
    word = word[:-2] + "яя"
    
  tag_key = key_for_tag(tag)
  
  # split lower and upper case
  if lemma[0].isupper():
    for c in lemma:
      if c.isupper():
        tag_key = "0" + tag_key
  # інфінітив на -сь має йти після -ся (леми)
  elif "verb:" in tag and ":inf" in tag and ":rev" in tag and word.endswith("сь"):
    tag_key += "z"
  
  srt_line = lemma + '0' + tag_key + '0' + word
  return locale.strxfrm(srt_line)
Ejemplo n.º 14
0
    def SetChoices(self, choices):
        '''
        Sets the choices available in the popup wx.ListBox.
        The items will be sorted case insensitively.
        '''
        self._choices = choices
        self._multiChoices = None
        flags = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER
        self.dropdownlistbox.SetWindowStyleFlag(flags)

        if not isinstance(choices, list):
            self._choices = [ x for x in choices]

        #prevent errors on "old" systems
        if sys.version.startswith("2.3"):
            self._choices.sort(lambda x, y: cmp(x.lower(), y.lower()))
        else:
            self._choices.sort(key=lambda x: locale.strxfrm(x).lower())

        self._updateDataList(self._choices)

        self.dropdownlistbox.InsertColumn(0, "")

        for num, colVal in enumerate(self._choices):
            index = self.dropdownlistbox.InsertImageStringItem(sys.maxint, colVal, -1)

            self.dropdownlistbox.SetStringItem(index, 0, colVal)
            self.dropdownlistbox.SetItemData(index, num)

        self._setListSize()

        # there is only one choice for both search and fetch if setting a single column:
        self._colSearch = 0
        self._colFetch = -1
Ejemplo n.º 15
0
def translations_for_class(verbs, ladl, lvf):
    ladl_verbs = verbs_for_class_mapping(parse.FrenchMapping('LADL', ladl))
    lvf_verbs = verbs_for_class_mapping(parse.FrenchMapping('LVF', lvf))

    candidates = defaultdict(set)
    for v in verbs:
        for c in verb_dict[v]:
            candidates[c].add(v)

    final = []
    for c in candidates:
        color = 'none'
        if c in ladl_verbs and c in lvf_verbs:
            color, id_color = 'both', 0
        elif c in lvf_verbs:
            color, id_color = 'lvf', 2
        elif c in ladl_verbs:
            color, id_color = 'ladl', 1
        elif c in dicovalence_verbs:
            color, id_color = 'dicovalence', 3
        else:
            color, id_color = 'unknown', 4
        final.append((c, color, id_color, ",".join(sorted(candidates[c]))))

    final = sorted(final, key=lambda c: (c[2], locale.strxfrm(c[0])))

    return final
Ejemplo n.º 16
0
def udelejRejstrik(vstup, vystup):
	with open(vstup, encoding='utf-8') as vs:
		zaznamy = []
		
		for line in vs:
			if line.strip()=="":
				break
		
			zaznam=["","",""]
			
			rozp = line.split("}{")
			strana = rozp[1].strip()
			strana = strana.replace("}","")
			zac = rozp[0] 
		
			zac = zac.replace("\\indexentry {","").replace("|hyperpage","")
			
			zac = zac.split("!")
			
			zaznam[0]=zac[0]
			
			try:
				zaznam[1]=zac[1]
			except IndexError:
				pass
		
			zaznam[2]=strana
			
			zaznamy.append(zaznam)
			
		zaznamy = sorted(zaznamy, key = lambda zaznam: locale.strxfrm(zaznam[0].ljust(100)+zaznam[1]))
	
	with open(vystup,"w+", encoding='utf-8') as vys:
		vys.write(zaznamy2tex(zaznamy))
Ejemplo n.º 17
0
def natural_sort_key(string, numeric_padding=5):
	'''Format string such that it gives 'natural' sorting on string
	compare. Will pad any numbers in the string with "0" such that "10"
	sorts after "9". Also includes C{locale.strxfrm()}.

	@note: sorting not 100% stable for case, so order between "foo" and
	"Foo" is not defined. For this reason when sort needs to be absolutely
	stable it is advised to sort based on tuples of
	C{(sort_key, original_string)}. Or use either L{natural_sort()} or
	L{natural_sorted()} instead.

	@param string: the string to format
	@param numeric_padding: number of digits to use for padding
	@returns: string transformed to sorting key
	'''
	templ = '%0' + str(numeric_padding) + 'i'
	string.strip()
	string = _num_re.sub(lambda m: templ % int(m.group()), string)
	if isinstance(string, unicode):
		string = unicodedata.normalize('NFKC', string)
		# may be done by strxfrm as well, but want to be sure
	string = string.lower() # sort case insensitive
	bytestring = locale.strxfrm(string)
		# 8-bit byte string - enode to hex -- in pyton3 check if byte data type is handled better by sqlite3 and others
	key = ''.join(["%02x" % ord(c) for c in bytestring])
	return key
Ejemplo n.º 18
0
 def sortkey(key):
     """Return something sortable for `entries[key]`."""
     return [
         locale.strxfrm(item)
         for item
         in entries[key]['sortingkey']
         ]
Ejemplo n.º 19
0
    def gnc_ui_update_commodity_picker (self, namespace, init_string):

        #pdb.set_trace()

        model = self.commodity_combo.get_model()
        model.clear()
        entry = self.commodity_combo.get_child()
        entry.delete_text(0,-1)

        self.commodity_combo.set_active(-1)

        table = sw_app_utils.get_current_book().get_table()
        commodities = table.get_commodities(namespace)
        commodity_items = []
        for commod in commodities:
            commodity_items.append(commod.get_printname())
        #commodity_items.sort(cmp=lambda x,y: locale.strcoll(x[0],y[0]))
        commodity_items.sort(key=lambda x: locale.strxfrm(x[0]))
        match = 0
        for current,commod in enumerate(commodity_items):
            model.append((commod,))
            if commod == init_string:
                match = current

        self.commodity_combo.set_active(match)
Ejemplo n.º 20
0
def _option_label_getter(item):
    result = force_text(item[0] if isinstance(item[1], (list, tuple)) else item[1])
    # In PY2, strxfrm does not support unicode encoded values, so we have to get creative.
    if six.PY3:
        return locale.strxfrm(result)
    else:
        return _compare_by_strcoll(result)
Ejemplo n.º 21
0
 def SetMultipleChoices(self, choices, colSearch=0, colFetch=-1):
     ''' Set multi-column choice
     '''
     self._multiChoices = choices
     self._choices = None
     if not isinstance(self._multiChoices, list):
         self._multiChoices = list(self._multiChoices)
     flags = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_SORT_ASCENDING
     if not self._showHead:
         flags |= wx.LC_NO_HEADER
     self.dropdownlistbox.SetWindowStyleFlag(flags)
     #prevent errors on "old" systems
     if sys.version.startswith("2.3"):
         self._multiChoices.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
     else:
         self._multiChoices.sort(key=lambda x: locale.strxfrm(x[0]).lower())
     self._updateDataList(self._multiChoices)
     if len(choices) < 2 or len(choices[0]) < 2:
         raise ValueError, "You have to pass me a multi-dimension list with at least two entries"
         # with only one entry, the dropdown artifacts
     for numCol, rowValues in enumerate(choices[0]):
         if self._colNames:
             colName = self._colNames[numCol]
         else:
             colName = "Select %i" % numCol
         self.dropdownlistbox.InsertColumn(numCol, colName)
     for numRow, valRow in enumerate(choices):
         for numCol, colVal in enumerate(valRow):
             if numCol == 0:
                 index = self.dropdownlistbox.InsertImageStringItem(sys.maxint, colVal, -1)
             self.dropdownlistbox.SetStringItem(index, numCol, colVal)
             self.dropdownlistbox.SetItemData(index, numRow)
     self._setListSize()
     self._colSearch = colSearch
     self._colFetch = colFetch
def main():
    columns_to_copy = [
        NAME,
        ASCIINAME,
        LATITUDE,
        LONGITUDE,
        ISO_CODE,
        TIMEZONE]

    ci = CountryInfo(countries_file)

    with open(cities_file, 'rb') as r:
        reader = csv.reader(r, delimiter='\t')
        for row in reader:
            if select_row(ci, row):
                newrow = []
                for index in columns_to_copy:
                    newrow.append(row[index])
                ci.add_city(newrow)
    with open(output_file, 'wb') as w:
        writer = csv.writer(w, delimiter='\t')
        # sort countries by name
        for country in sorted(ci.countries.values(), key=lambda c:c['name']):
            locale.setlocale(locale.LC_ALL, '')
            # sort cities by name (1st column)
            for city in sorted(country['cities'], key=lambda c:locale.strxfrm(c[0])):
                writer.writerow(city)
        # add GMT
        writer.writerow(['GMT', 'UTC Zulu', '0', '0', 'Greenwich Mean Time', 'GMT'])
Ejemplo n.º 23
0
 def __init__(self, parent=None):
     super(InterfaceOptionsPage, self).__init__(parent)
     self.ui = Ui_InterfaceOptionsPage()
     self.ui.setupUi(self)
     self.ui.ui_language.addItem(_('System default'), '')
     language_list = [(l[0], l[1], _(l[2])) for l in UI_LANGUAGES]
     fcmp = lambda x: locale.strxfrm(x[2])
     for lang_code, native, translation in sorted(language_list, key=fcmp):
         if native and native != translation:
             name = '%s (%s)' % (translation, native)
         else:
             name = translation
         self.ui.ui_language.addItem(name, lang_code)
     self.ui.starting_directory.stateChanged.connect(
         partial(
             enabledSlot,
             self.ui.starting_directory_path.setEnabled
         )
     )
     self.ui.starting_directory.stateChanged.connect(
         partial(
             enabledSlot,
             self.ui.starting_directory_browse.setEnabled
         )
     )
     self.ui.starting_directory_browse.clicked.connect(self.starting_directory_browse)
     self.ui.add_button.clicked.connect(self.add_to_toolbar)
     self.ui.insert_separator_button.clicked.connect(self.insert_separator)
     self.ui.remove_button.clicked.connect(self.remove_action)
     self.ui.up_button.clicked.connect(partial(self.move_item, 1))
     self.ui.down_button.clicked.connect(partial(self.move_item, -1))
     self.ui.toolbar_layout_list.currentRowChanged.connect(self.update_buttons)
     self.ui.toolbar_layout_list.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop)
     self.ui.toolbar_layout_list.setDefaultDropAction(QtCore.Qt.MoveAction)
Ejemplo n.º 24
0
def _strxfrm(s):
    """Wrapper around locale.strxfrm that accepts unicode strings on Python 2.
    
    See Python bug #2481.
    """
    if (not PY3) and isinstance(s, unicode):
        s = s.encode('utf-8')
    return locale.strxfrm(s)
def main(wordmapin, jointlex, wordmapout, reallex):
    jointlex = read_lex(jointlex)
    jointlex["UNK"] = []
    new_lex = {}

    for line in wordmapin:
        parts = line.strip().split()
        word = parts[0]

        new_parts = []

        for part in parts[1:]:
            base_word = part.strip("+").split("#")[0]
            indices = None
            if "#" in part:
                indices = [int(x) for x in part.strip("+").split("#")[1].split(",")]

            num_orig_trans = len(jointlex[base_word])
            if indices is not None and num_orig_trans == len(indices):
                indices = None

            prefix = "+" if part.startswith("+") else ""
            suffix = "+" if part.endswith("+") else ""

            index_string = "#{}".format(",".join(str(x) for x in indices)) if indices is not None else ""

            new_form = "{}{}{}{}".format(prefix, base_word, index_string, suffix)

            if new_form not in new_lex:
                new_lex[new_form] = set()

            if indices is None:
                for t in jointlex[base_word]:
                    new_lex[new_form].add(t)
            else:
                for i in indices:
                    new_lex[new_form].add(jointlex[base_word][i])

            new_parts.append(new_form)

        print("{}\t{}".format(word, " ".join(new_parts)), file=wordmapout)

    for k, v in sorted(new_lex.items(), key=lambda x: locale.strxfrm(x[0])):
        for trans in sorted(set(v), key=lambda x: tuple(locale.strxfrm(y) for y in x)):
            print("{}\t{}".format(k, " ".join(trans)), file=reallex)
Ejemplo n.º 26
0
def normalize_string(string):
    """Return a normalized string.

    Normalized means:
    - no surrounding spaces;
    - lower case;
    - passed through locale.strxfrm().
    """
    return locale.strxfrm(string.lower().strip())
Ejemplo n.º 27
0
    def gnc_ui_update_namespace_picker (self, init_string, mode):

        model = self.namespace_combo.get_model()
        model.clear()
        self.namespace_combo.set_active(-1)

        if mode == DialogCommodity.DIAG_COMM_ALL:
            # get_namespaces crashes
            # not clear what the difference is
            #namespaces = sw_app_utils.get_current_commodities().get_namespaces()
            namelst = sw_app_utils.get_current_commodities().get_namespaces_list()
            namespaces = [ (x.get_name(),x) for x in namelst ]
        elif mode == DialogCommodity.DIAG_COMM_NON_CURRENCY:
            #namespaces = sw_app_utils.get_current_commodities().get_namespaces()
            namelst = sw_app_utils.get_current_commodities().get_namespaces_list()
            #namespaces = [ (x.get_name(),x) for x in namelst ]
            namespaces = []
            #node = g_list_find_custom(namespaces, 'CURRENCY', collate)
            #if node:
            #    namespaces = g_list_remove_link(namespaces, node)
            for x in namelst:
                if x.get_name() == 'CURRENCY':
                    continue
                namespaces.append((x.get_name(),x))
            if gnc_commodity_namespace_is_iso(init_string):
                init_string = None
        #elif mode == DialogCommodity.DIAG_COMM_CURRENCY:
        else:
            #namespaces = g_list_prepend(None, 'CURRENCY')
            namespacecur = sw_app_utils.get_current_commodities().find_namespace('CURRENCY')
            namespaces = [ ('CURRENCY',namespacecur) ]

        pdb.set_trace()

        #namespaces = g_list_sort(namespaces, collate)
        #namespaces.sort(cmp=lambda x,y: locale.strcoll(x[0],y[0]))
        namespaces.sort(key=lambda x: locale.strxfrm(x[0]))
        current = 0
        match = 0
        #for node in namespaces:
        #    if g_utf8_collate(node.data, "GNC_LEGACY_CURRENCIES") == 0:
        #        continue
        #    if g_utf8_collate(node.data, "template") != 0:
        #        model.append((node.data,))
        #    if g_utf8_collate(node.data, init_string) == 0:
        #        match = current
        #    current += 1
        for current,node in enumerate(namespaces):
            if node[0] == "GNC_LEGACY_CURRENCIES":
                continue
            if node[0] != "template":
                model.append((node[0],))
            if node[0] == init_string:
                match = current
        #    current += 1

        self.namespace_combo.set_active(match)
Ejemplo n.º 28
0
 def SetChoices(self, choices):
     """
     Sets the choices available in the popup wx.ListBox.
     The items will be sorted case insensitively.
     """
     if not isinstance(choices, list):
         self._choices = [ x for x in choices]
     else:
         self._choices = choices
     self.dropdownlistbox.setChoices(self._choices)
     #prevent errors on "old" systems
     if sys.version.startswith("2.3"):
         self._choices.sort(lambda x, y: cmp(x.lower(), y.lower()))
     else:
         try:
             self._choices.sort(key=lambda x: locale.strxfrm(x).lower())
         except UnicodeEncodeError:
             self._choices.sort(key=lambda x: locale.strxfrm(x.encode("UTF-8")).lower())
     self._setListSize()
Ejemplo n.º 29
0
    def sort_subdirs(self, albums_sort_attr):
        if self.subdirs:
            if albums_sort_attr:
                root_path = self.path if self.path != '.' else ''
                if albums_sort_attr.startswith("meta."):
                    meta_key = albums_sort_attr.split(".", 1)[1]
                    key = lambda s: locale.strxfrm(
                        self.gallery.albums[join(root_path, s)].meta.get(meta_key, [''])[0])
                else:
                    key = lambda s: locale.strxfrm(
                        getattr(self.gallery.albums[join(root_path, s)],
                                albums_sort_attr))
            else:
                key = locale.strxfrm

            self.subdirs.sort(key=key,
                              reverse=self.settings['albums_sort_reverse'])

        signals.albums_sorted.send(self)
Ejemplo n.º 30
0
def sortkey(value):
    """From a title, return something usable for sorting.

    It handles locale (but
    don't forget to call locale.setlocale(locale.LC_ALL, '')). It also handles
    the sort with  latex escape sequences.
    """
    return locale.strxfrm(
            unidecode(simpleparse(value).replace(' ', 'A')).lower()
            )
Ejemplo n.º 31
0
source: http://www.securityfocus.com/bid/23887/info

Python applications that use the 'PyLocale_strxfrm' function are prone to an information leak.

Exploiting this issue allows remote attackers to read portions of memory.

Python 2.4.4-2 and 2.5 are confirmed vulnerable. 

#!/usr/bin/python

import locale

print locale.setlocale(locale.LC_COLLATE, 'pl_PL.UTF8')
print repr(locale.strxfrm('a'))
Ejemplo n.º 32
0
 def test_strxfrm(self):
     self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
     # embedded null character
     self.assertRaises(ValueError, locale.strxfrm, 'a\0')
Ejemplo n.º 33
0
def sorted_langs(langs):
    return sorted(set(langs),
                  key=lambda code: locale.strxfrm(
                      get_english_language_name(code).encode('UTF-8')))
Ejemplo n.º 34
0
def _tsmart(s):
    """ Smart (custom) transfrom; strxfrm() """
    # Ignoruojame komentaro simbolá ir rikiuojame pagal þodá uþ jo
    if s.startswith("#"): s = s[1:]
    return strxfrm(s)
Ejemplo n.º 35
0
def additional_streets_view_result(relations: areas.Relations,
                                   request_uri: str) -> yattag.doc.Doc:
    """Expected request_uri: e.g. /osm/additional-streets/budapest_11/view-result."""
    tokens = request_uri.split("/")
    relation_name = tokens[-2]
    relation = relations.get_relation(relation_name)

    doc = yattag.doc.Doc()
    prefix = config.Config.get_uri_prefix()
    if not os.path.exists(relation.get_files().get_osm_streets_path()):
        doc.asis(
            webframe.handle_no_osm_streets(prefix, relation_name).getvalue())
    elif not os.path.exists(relation.get_files().get_ref_streets_path()):
        doc.asis(
            webframe.handle_no_ref_streets(prefix, relation_name).getvalue())
    else:
        # Get "only in OSM" streets.
        streets = relation.write_additional_streets()
        count = len(streets)
        streets.sort(key=lambda street: locale.strxfrm(street.get_osm_name()))
        table = [[
            util.html_escape(_("Identifier")),
            util.html_escape(_("Type")),
            util.html_escape(_("Source")),
            util.html_escape(_("Street name"))
        ]]
        for street in streets:
            cell = yattag.doc.Doc()
            href = "https://www.openstreetmap.org/{}/{}".format(
                street.get_osm_type(), street.get_osm_id())
            with cell.tag("a", href=href, target="_blank"):
                cell.text(str(street.get_osm_id()))
            cells = [
                cell,
                util.html_escape(street.get_osm_type()),
                util.html_escape(street.get_source()),
                util.html_escape(street.get_osm_name()),
            ]
            table.append(cells)

        with doc.tag("p"):
            doc.text(
                _("OpenStreetMap additionally has the below {0} streets.").
                format(str(count)))
            doc.stag("br")
            with doc.tag("a",
                         href=prefix + "/additional-streets/" + relation_name +
                         "/view-result.txt"):
                doc.text(_("Plain text format"))
            doc.stag("br")
            with doc.tag("a",
                         href=prefix + "/additional-streets/" + relation_name +
                         "/view-result.chkl"):
                doc.text(_("Checklist format"))
            doc.stag("br")
            with doc.tag(
                    "a",
                    href=prefix +
                    "/additional-streets/{}/view-turbo".format(relation_name)):
                doc.text(_("Overpass turbo query for the below streets"))

        doc.asis(util.html_table_from_list(table).getvalue())
        doc.asis(
            util.invalid_refstreets_to_html(
                areas.get_invalid_refstreets(relation)).getvalue())
    return doc
Ejemplo n.º 36
0
 def sort_unicode(path):
     return [locale.strxfrm(str(c)) for c in old_sort_func(path)]
Ejemplo n.º 37
0
 def strxfrm(self, s):
     return locale.strxfrm(s)
Ejemplo n.º 38
0
 def categorykey(item):
     if item[0] == uncategorized:
         return '\xff' * 10
     return locale.strxfrm(item[0])
Ejemplo n.º 39
0
 def fcmp(x): return locale.strxfrm(x[2])
 for lang_code, native, translation in sorted(language_list, key=fcmp):
Ejemplo n.º 40
0
 def title_sort_func(ekey):
     return locale.strxfrm(repertoire_emissions[ekey].get_title())
Ejemplo n.º 41
0
                  , "Scala"
                  , "SQL"
                  , "TeX"
                  , "Text only"
                  , "VimL"
                  , "XML"
                  , "XQuery"
                  , "XSLT"
                  ]

UnfilteredLexers = pl.get_all_lexers()
Lexers = []
for l in UnfilteredLexers:
    if l[1] == ('basemake',): continue # Bugfix: we want unique keys (Makefile)
    if not l[0] in wantedLanguages: continue
    if l[0] == 'S' and l[2][0] == '*.S': # Prioritize R over S
        l[0] = 'R'
        l[2][0] = '*.R'
        l[2][1] = '*.S'
    Lexers.append(l)
sortLambda = lambda x: locale.strxfrm(x[0].lower())
sortedLexers = sorted(Lexers, key=sortLambda)
newLexers = []
for l in sortedLexers:
    newLexers.append(dict({'name':  l[0], 
                           'alias': l[1],
                           'ext':   l[2],
                           'mime':  l[3]}))
JSON = json.dumps(newLexers) # indent=2
print JSON
Ejemplo n.º 42
0
    template += f'- {get_member_info(m)}\n'

  return template


if __name__ == "__main__":
  locale.setlocale(locale.LC_ALL, '')
  
  parser = argparse.ArgumentParser(description='Update list of visible VERSEN members using Mailchimp.')
  parser.add_argument('-k', '--api-key', 
    default=os.environ.get('VERSEN_MC_KEY'),
    help='Mailchimp API key (e.g., a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9-us1).\nCan be set using the environment variable VERSEN_MC_KEY.')
  parser.add_argument('-o', '--output', 
    default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'content', 'members', 'list.md'), 
    help='Default: <root>/content/members/list.md')
  
  args = parser.parse_args()
  if not args.api_key:
    print('Error: api-key not set.\n')
    parser.print_help()
    exit(0)
  
  visible_members = get_members(token=args.api_key, list_id='5228435632', segment_id='3577467', count=999)
  invisible_members = get_members(token=args.api_key, list_id='5228435632', segment_id='3577471', count=1)
  total_members = visible_members['count'] + invisible_members['count']
  visible_members['members'].sort(key=lambda m: locale.strxfrm(m["merge_fields"]["FNAME"]))
  
  with open(args.output, 'w') as f:
    text = generate_list_md(total_members=total_members, visible_members=visible_members['members'])
    f.write(text)
    def __write_referenced_families(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        marrevt_handle_list =[]
        marr =[]
        fam_list=[]
        fam_index={}
        Paten_list =[]
        
        print(self.showgodparents)

        if self.showgodparents:
            pedic ={}
            pedic = defaultdict(list)
            for pe in self.database.get_person_handles():
                for eventref in self.database.get_person_from_handle(pe).event_ref_list:
                    if not eventref.get_role().is_primary():
                        pedic[eventref.ref].append((eventref.get_role(),pe))

        with self._user.progress(_("PlaceFamily Report"), 
                                  _("Generating report"), 
                                  len(self.place_handles)) as step:
                                  


    
    
    
            for handle in self.place_handles:        
    # first all events
                  
                event_handles = [event_handle for (object_type, event_handle) in
                                 self.database.find_backlink_handles(handle, ['Event'])]
                event_handles.sort(key=self.sort.by_date_key)
        
#                if event_handles:
#                    self.doc.start_paragraph("PLC-Section")
#                    self.doc.write_text(self.database.get_place_from_handle(handle).get_title())
#                    self.doc.end_paragraph()
#    #            print(len(event_handles))
    
    # only marriage            
                for evt_handle in event_handles:
                    if self.database.get_event_from_handle(evt_handle).get_type().is_marriage():
                        marrevt_handle_list.append(evt_handle)
    #            print(len(marrevt_handle_list))
    # no dups            
            marr = list(OrderedDict.fromkeys(marrevt_handle_list))
    #        print(len(marr))
            mi = 0    
            for evt_handle in marr:
                event = self.database.get_event_from_handle(evt_handle)
                date = self._get_date(event.get_date_object())
                date_sort = event.get_date_object().get_sort_value()
                descr = event.get_description()
                event_type = self._(self._get_type(event.get_type()))
                event_place = event.place 
                ref_handles = [x for x in
                               self.database.find_backlink_handles(evt_handle)]
    #            print(mi, evt_handle)
                mi += 1
                for (ref_type, ref_handle) in ref_handles:
                    if ref_type == 'Person':
                        continue
                    else:
                        family = self.database.get_family_from_handle(ref_handle)
                        ifam +=1
                        father_handle = family.get_father_handle()
        # now from the families only fathers
                        if father_handle:
                            fp = self.database.get_person_from_handle(father_handle)
                            father_name = \
                                self._name_display.display_name(fp.get_primary_name()).lower()
                        else:
                            father_name = _("unknown")
                        place_d = place_displayer.display_event(self.database, event)
                        event_details = [ father_handle, father_name, date, ref_handle, descr, place_d, family, date_sort]
                        fam_list.append(event_details)
    
                                                     
    #        print(sorted(fam_list, key=itemgetter(1,7)))
    #        print(len(fam_list))
            printsurname = "NOW"
            index=0
##########################            
            #for fn in sorted(fam_list, key=itemgetter(1,7)):

            #fam_list_name
# TEST FOR SORTING
#            lastnames = ["Bange", "Änger", "Amman", "Änger", "Zelch", "Ösbach"]
#            print(sorted(lastnames, key=locale.strxfrm))
#            print()
#
#            lastnames_firstnames_groups =[
#                ["Bange", "Michael", 2],
#                ["Änger", "Ämma", 2],
#                ["Amman", "Anton", 1],
#                ["Änger", "Chris", 2],
#                ["Zelch", "Sven", 1],
#                ["Ösbach", "Carl", 1]
#            ]
#            print(sorted(lastnames_firstnames_groups, key=operator.itemgetter(2,0,1)))
#            print(
#                sorted(
#                    lastnames_firstnames_groups,
#                    key=lambda t: (t[2], locale.strxfrm(t[0]), locale.strxfrm(t[1]))
#                )
#            )
#**************************            
            for fn in sorted(fam_list,  key=lambda t: (locale.strxfrm(t[1]), t[7])):
                index +=1
                fam_index[fn[6].get_gramps_id()]=index
    #            print(index)
    #        for ifn in fam_index.keys():
    #            print(ifn, fam_index[ifn])
            fam_index_keys = fam_index.keys()
    
    
            for fn in sorted(fam_list,  key=lambda t: (locale.strxfrm(t[1]), t[7])):
                if fn[0] is None:
                    surname = _("unknown")
                else:
                    surname = self.database.get_person_from_handle(fn[0]).get_primary_name().get_surname()
    #            print(fn[0], surname)
                if printsurname == surname:
                    pass
                else:
        #Family Surname
                    printsurname = surname
  #                  S_Name = ("%s " % surname)
#                    mark = IndexMark(S_Name, INDEX_TYPE_TOC, 1) 
                    self.doc.start_paragraph("PLC-PlaceTitle")
                   # self.doc.write_text("%s " % surname)
                    
                 #   mark = ReportUtils.get_person_mark(self.database,surname)
                    
                    mark = IndexMark( surname, INDEX_TYPE_ALP )
                    
                    self.doc.write_text(surname,mark)
                    self.doc.end_paragraph()                              
                i +=1
    # weddingdetails
                family = fn[6]
                iw += 1
                self.doc.start_paragraph("PLC-Details")
                self.doc.start_bold()
    #            self.doc.write_text("<%s> " % iw)
                self.doc.write_text(" <%s>" % fam_index[fn[6].gramps_id])
    #            self.doc.write_text("Heirat %s " % fn[1])
                self.doc.write_text("%s " % u'\u26AD')
                self.doc.write_text("%s " % fn[2])
                self.doc.end_bold()

                # increment progress bar
                step()
    
    #given Name
    # wedding place
                self.doc.write_text("in %s." % fn[5])
    # FamID            
                self.doc.write_text(" [%s]" % fn[6].gramps_id)        
                self.doc.end_paragraph()
    
    ##################################################
    # fatherdetails
                father = self.database.get_person_from_handle(fn[6].father_handle)
                if father:
                    self.doc.start_paragraph("PLC-PlaceDetails")
    #given Name
                    self.doc.start_bold()
                #    self.doc.write_text("%s " % father.get_primary_name().get_first_name())
                    mark = ReportUtils.get_person_mark(self.database,father)
                    text = father.get_primary_name().get_first_name()
                    self.doc.write_text(text,mark)
                    self.doc.write_text(" %s" % father.get_primary_name().get_surname())
                    
                    self.doc.end_bold()
                    self.doc.write_text("[%s] " % father.get_gramps_id())
    #ggf familyID
                    for fam in father.get_family_handle_list():
                        if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                            if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                self.doc.end_bold()
    
    #birth date
                    birth_ref = father.get_birth_ref()
                    if birth_ref:
        # erst event
                        birth_event = self.database.get_event_from_handle(birth_ref.ref)
                        self.doc.write_text(" * ")
                        self.doc.write_text(self.__format_date(birth_event.get_date_object()))
        #birth place
        # dann display place
                        place_string = place_displayer.display_event(self.database, birth_event)
#formatierung        # dann drucken
                        self.doc.write_text(self.__format_place(place_string, self.placeformat))
        #bapt date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
        # erst event
                                bapt_event = self.database.get_event_from_handle(eventref.ref)

                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(self.__format_date(bapt_event.get_date_object()))
        #bapt place
#        # erst event
#                                bapt_event = self.database.get_event_from_handle(eventref.ref)
        # dann display place
                                place_string = place_displayer.display_event(self.database, bapt_event) 
                                self.doc.write_text(self.__format_place(place_string, self.placeformat))

        #death date
                    death_ref = father.get_death_ref()
                    if death_ref:
        # erst event
                        death_event = self.database.get_event_from_handle(death_ref.ref)
                        self.doc.write_text(" † ")
                        self.doc.write_text(self.__format_date(death_event.get_date_object()))
        #death place
        # dann display place
                        place_string = place_displayer.display_event(self.database, death_event) 
                        self.doc.write_text(self.__format_place(place_string, self.placeformat))


        #burr date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
        # erst event
                                burr_event = self.database.get_event_from_handle(eventref.ref)
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(self.__format_date(burr_event.get_date_object()))
        #burr place
        # dann display place
                                place_string = place_displayer.display_event(self.database, burr_event) 
                                self.doc.write_text(self.__format_place(place_string, self.placeformat))
                    self.doc.end_paragraph()
                
    ############################################################
    # motherdetails
                mother = self.database.get_person_from_handle(fn[6].mother_handle)
                if mother:
                    self.doc.start_paragraph("PLC-PlaceDetails")                 
        #given Name
                    self.doc.write_text("und ")
                    self.doc.start_bold()
              
                    mark = ReportUtils.get_person_mark(self.database,mother)
                    text = mother.get_primary_name().get_surname()
                    self.doc.write_text(text,mark)
              
           #         self.doc.write_text("%s, " % mother.get_primary_name().get_surname())
                    self.doc.end_bold()
                    self.doc.write_text(" %s " % mother.get_primary_name().get_first_name())
                    self.doc.write_text("[%s] " % mother.get_gramps_id())
        #ggf familyID
                    for fam in mother.get_family_handle_list():
                        if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                            if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                self.doc.end_bold()
    
    #birth date
                    birth_ref = mother.get_birth_ref()
                    if birth_ref:
        # erst event
                        birth_event = self.database.get_event_from_handle(birth_ref.ref)
                        self.doc.write_text(" * ")
                        self.doc.write_text(self.__format_date(birth_event.get_date_object()))
        #birth place
        # dann display place
                        place_string = place_displayer.display_event(self.database, birth_event)
                        self.doc.write_text(self.__format_place(place_string, self.placeformat))

        #bapt date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
        # erst event
                                bapt_event = self.database.get_event_from_handle(eventref.ref)

                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(self.__format_date(bapt_event.get_date_object()))
        #bapt place
        # dann display place
                                place_string = place_displayer.display_event(self.database, bapt_event) 
                                self.doc.write_text(self.__format_place(place_string, self.placeformat))


        #death date
                    death_ref = mother.get_death_ref()
                    if death_ref:
        # erst event
                        death_event = self.database.get_event_from_handle(death_ref.ref)
                        self.doc.write_text(" † ")
                        self.doc.write_text(self.__format_date(death_event.get_date_object()))
        #death place
                        place_string = place_displayer.display_event(self.database, death_event) 
                        self.doc.write_text(self.__format_place(place_string, self.placeformat))


        #burr date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
        # erst event
                                burr_event = self.database.get_event_from_handle(eventref.ref)
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(self.__format_date(burr_event.get_date_object()))
        #burr place
        # dann display place
                                place_string = place_displayer.display_event(self.database, burr_event) 
                                self.doc.write_text(self.__format_place(place_string, self.placeformat))
                    self.doc.end_paragraph()
                
                
    ############################################################
    # Children
    
                fc = 0
                for ch in fn[6].get_child_ref_list():
                    self.doc.start_paragraph("PLC-PlaceDetailsChildren")
                    fc +=1
                    child = self.database.get_person_from_handle(ch.ref)
                    if child:
        #lnr
                        self.doc.write_text("     %s " % fc)
        #given Name
                        mark = ReportUtils.get_person_mark(self.database, child)
                        text = child.get_primary_name().get_first_name()
                        self.doc.write_text(text, mark)
           #             self.doc.write_text("%s " % child.get_primary_name().get_first_name())
                        self.doc.write_text("[%s] " % child.get_gramps_id())
        #ggf familyID
                        for fam in child.get_family_handle_list():
                            if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                                pass
                            else:
                                self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                                if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                    self.doc.start_bold()
                                    self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                    self.doc.end_bold()
        
            #birth date

                        birth_ref = child.get_birth_ref()
                        if birth_ref:
                # erst event
                            birth_event = self.database.get_event_from_handle(birth_ref.ref)
                            self.doc.write_text(" * ")
                            self.doc.write_text(self.__format_date(birth_event.get_date_object()))
            #birth place
                            place_string = place_displayer.display_event(self.database, birth_event)
                            self.doc.write_text(self.__format_place(place_string, self.placeformat))
    
    
            #bapt date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
            # erst event
                                    bapt_event = self.database.get_event_from_handle(eventref.ref)
    
                                    self.doc.write_text(" %s " % u'\u2053')
                                    self.doc.write_text(self.__format_date(bapt_event.get_date_object()))
            #bapt place
            # dann display place
                                    place_string = place_displayer.display_event(self.database, bapt_event) 
                                    self.doc.write_text(self.__format_place(place_string, self.placeformat))

                                    if self.showgodparents:
                                        Patenlist = []
                                        Patenlist = pedic[eventref.ref]
    
    
            #death date
                        death_ref = child.get_death_ref()
                        if death_ref:
            # erst event
                            death_event = self.database.get_event_from_handle(death_ref.ref)
                            self.doc.write_text(" † ")
                            self.doc.write_text(self.__format_date(death_event.get_date_object()))
            #death place
            # dann display place
                            place_string = place_displayer.display_event(self.database, death_event) 
                            self.doc.write_text(self.__format_place(place_string, self.placeformat))
    
    
    
            #burr date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
            # erst event
                                    burr_event = self.database.get_event_from_handle(eventref.ref)
                                    self.doc.write_text("%s " % u'\u26B0')
                                    self.doc.write_text(self.__format_date(burr_event.get_date_object()))
            #burr place
            # dann display place
                                    place_string = place_displayer.display_event(self.database, burr_event) 
            # dann drucken
                                    self.doc.write_text(self.__format_place(place_string, self.placeformat))
                        self.doc.end_paragraph()

 #                       print(len(Patenlist))
                        if self.showgodparents:
                        
                            if len(Patenlist)>0:
                                self.doc.start_paragraph("PLC-Godparents")
                                self.doc.write_text(" Paten: ")
                                for i,(pa_a,pa_b) in enumerate(Patenlist):
                                    self.doc.write_text(" (%s) " % str(i+1))
                             
                                    pate_name = self.database.get_person_from_handle(pa_b).get_primary_name().get_first_name() +" "+ self.database.get_person_from_handle(pa_b).get_primary_name().get_surname() 
                                    pate = self.database.get_person_from_handle(pa_b) 
                             
                                    mark = ReportUtils.get_person_mark(self.database, pate)
                                    self.doc.write_text(pate.get_primary_name().get_first_name() +" "+ pate.get_primary_name().get_surname() ,mark)
                                self.doc.end_paragraph()
                                Patenlist =[]
Ejemplo n.º 44
0
def sort_by_last_name(a):
    return locale.strxfrm(a['last_name'])
Ejemplo n.º 45
0
class PluginManager(object):
    """
        Gui to manage plugins
    """
    def __init__(self, preferences, builder):
        """
            Initializes the manager
        """
        self.preferences = preferences
        builder.connect_signals(self)
        self.plugins = main.exaile().plugins

        self.message = dialogs.MessageBar(
            parent=builder.get_object('preferences_pane'),
            buttons=gtk.BUTTONS_CLOSE)
        self.message.connect('response', self.on_messagebar_response)

        self.list = builder.get_object('plugin_tree')
        self.enabled_cellrenderer = builder.get_object('enabled_cellrenderer')

        if main.exaile().options.Debug:
            reload_cellrenderer = common.ClickableCellRendererPixbuf()
            reload_cellrenderer.props.stock_id = gtk.STOCK_REFRESH
            reload_cellrenderer.props.xalign = 1
            reload_cellrenderer.connect('clicked',
                                        self.on_reload_cellrenderer_clicked)

            name_column = builder.get_object('name_column')
            name_column.pack_start(reload_cellrenderer)
            name_column.add_attribute(reload_cellrenderer, 'visible', 3)

        self.version_label = builder.get_object('version_label')
        self.author_label = builder.get_object('author_label')
        self.name_label = builder.get_object('name_label')
        self.description = builder.get_object('description_view')

        self.model = builder.get_object('model')
        self.filter_model = self.model.filter_new()

        self.show_incompatible_cb = builder.get_object('show_incompatible_cb')
        self.show_broken_cb = builder.get_object('show_broken_cb')

        self.filter_model.set_visible_func(self._model_visible_func)

        self.status_column = builder.get_object('status_column')
        self._set_status_visible()

        selection = self.list.get_selection()
        selection.connect('changed', self.on_selection_changed)
        self._load_plugin_list()
        glib.idle_add(selection.select_path, (0, ))
        glib.idle_add(self.list.grab_focus)

    def _load_plugin_list(self):
        """
            Loads the plugin list
        """
        plugins = self.plugins.list_installed_plugins()
        uncategorized = _('Uncategorized')
        plugins_dict = {uncategorized: []}
        failed_list = []

        for plugin in plugins:
            try:
                info = self.plugins.get_plugin_info(plugin)

                compatible = self.plugins.is_compatible(info)
                broken = self.plugins.is_potentially_broken(info)

            except Exception, e:
                failed_list += [plugin]
                continue

            # determine icon to show
            if broken or not compatible:
                icon = gtk.STOCK_DIALOG_WARNING
            else:
                icon = gtk.STOCK_APPLY

            enabled = plugin in self.plugins.enabled_plugins
            plugin_data = (plugin, info['Name'], info['Version'], enabled,
                           icon, broken, compatible, True)

            if 'Category' in info:
                if info['Category'] in plugins_dict:
                    plugins_dict[info['Category']].append(plugin_data)
                else:
                    plugins_dict[info['Category']] = [plugin_data]
            else:
                plugins_dict[uncategorized].append(plugin_data)

        self.list.set_model(None)
        self.model.clear()

        plugins_dict = sorted(
            plugins_dict.iteritems(),
            key=lambda x: 'zzzz'
            if x[0] == uncategorized else locale.strxfrm(x[0]))

        for category, plugins_list in plugins_dict:
            plugins_list.sort(key=lambda x: locale.strxfrm(x[1]))

            it = self.model.append(
                None, (None, category, '', False, '', False, True, False))

            for plugin in plugins_list:
                self.model.append(it, plugin)

        self.list.set_model(self.filter_model)

        # TODO: Keep track of which categories are already expanded, and only expand those
        self.list.expand_all()

        if failed_list:
            self.message.show_error(
                _('Could not load plugin info!'),
                ngettext('Failed plugin: %s', 'Failed plugins: %s',
                         len(failed_list)) % ', '.join(failed_list))
Ejemplo n.º 46
0
 def test_strxfrm_with_diacritic(self):
     self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
Ejemplo n.º 47
0
 def sort_unicode(path):
     return locale.strxfrm(old_sort_func(path))
Ejemplo n.º 48
0
 def strxfrm(s):
     return locale.strxfrm(s.encode('utf-8'))
Ejemplo n.º 49
0
 def test_strxfrm(self):
     self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
Ejemplo n.º 50
0
# Generation Time
generationTime = datetime.datetime.now().astimezone(
    pytz.timezone(config["timezone"])).replace(microsecond=0).isoformat()
log.info("Generation Time: {0}".format(generationTime))

#### End config ####

# Read the csv and sort it
try:
    with open(sourceFile, newline="") as csvFileReader:
        readFile = csv.DictReader(csvFileReader)
        media = sorted(
            readFile,
            key=lambda tup: (
                strxfrm(tup["location"].lower(
                )),  # Sorting is: Location (branch office) -> Category -> Name
                strxfrm(tup["category"].lower()),
                strxfrm(tup["name"].lower())))

except FileNotFoundError:
    log.critical("Can't read library.csv!")
    exit(1)

log.debug("Media: {0}".format(media))

# Here we build a nested dictionary in the form
# -> location 1
#   -> category 1
#   -> category 2
# -> location 2
#   -> category 1
Ejemplo n.º 51
0
def sort_unicode(choices, key):
    """Unicode aware sorting if available."""
    return sorted(choices, key=lambda tup: locale.strxfrm(key(tup)))
Ejemplo n.º 52
0
 def sort_by_autonym(self, languages):
     """Sort a list of languages by their autonyms."""
     return sorted(
         (lang for lang in languages if self.get_autonym(lang)),
         key=lambda x: locale.strxfrm((self.get_autonym(x) or x).lower()),
     )
Ejemplo n.º 53
0
def list_pkg_by_names(download_dir):
    sort_fn = lambda p: locale.strxfrm(p.metadata.name)
    pkgs = sorted(list_pkgs(download_dir), key=sort_fn)
    return itertools.groupby(pkgs, lambda p: p.metadata.name)
Ejemplo n.º 54
0
 def sortkey():
     # HACK: Python 2 bug: strxfrm doesn't support unicode.
     # https://bugs.python.org/issue2481
     sortname = locale.strxfrm(name.encode('utf-8'))
     return sortname, name, f
Ejemplo n.º 55
0
    def _load_plugin_list(self):
        """
        Loads the plugin list
        """
        plugins = self.plugins.list_installed_plugins()
        uncategorized = _('Uncategorized')
        plugins_dict = {uncategorized: []}
        failed_list = []

        self.plugin_to_path = {}

        for plugin_name in plugins:
            try:
                info = self.plugins.get_plugin_info(plugin_name)

                compatible = self.plugins.is_compatible(info)
                broken = self.plugins.is_potentially_broken(info)

            except Exception:
                failed_list += [plugin_name]
                continue

            # determine icon to show
            if not compatible:
                icon = 'dialog-error'
            elif broken:
                icon = 'dialog-warning'
            else:
                icon = None

            enabled = plugin_name in self.plugins.enabled_plugins
            plugin_data = (
                plugin_name,
                info['Name'],
                str(info['Version']),
                enabled,
                icon,
                broken,
                compatible,
                True,
            )

            if 'Category' in info:
                cat = plugins_dict.setdefault(info['Category'], [])
                cat.append(plugin_data)
            else:
                plugins_dict[uncategorized].append(plugin_data)

        self.list.set_model(None)
        self.model.clear()

        def categorykey(item):
            if item[0] == uncategorized:
                return '\xff' * 10
            return locale.strxfrm(item[0])

        plugins_dict = sorted(plugins_dict.items(), key=categorykey)

        for category, plugins_list in plugins_dict:
            plugins_list.sort(key=lambda x: locale.strxfrm(x[1]))

            it = self.model.append(
                None, (None, category, '', False, '', False, True, False))

            for plugin_data in plugins_list:
                pit = self.model.append(it, plugin_data)
                path = self.model.get_string_from_iter(pit)
                self.plugin_to_path[plugin_data[0]] = path

        self.list.set_model(self.filter_model)

        # TODO: Keep track of which categories are already expanded, and only expand those
        self.list.expand_all()

        if failed_list:
            self.message.show_error(
                _('Could not load plugin info!'),
                ngettext('Failed plugin: %s', 'Failed plugins: %s',
                         len(failed_list)) % ', '.join(failed_list),
            )
Ejemplo n.º 56
0
 def get_instances(self):
     #return sorted(self.Class.instances(), key = lambda instance: locale.strxfrm(instance.name))
     return sorted((instance for instance in self.ontology.instances
                    if isinstance(instance, self.Class)),
                   key=lambda instance: locale.strxfrm(instance.name))
Ejemplo n.º 57
0
 def fcmp(x):
     return locale.strxfrm(x[2])
Ejemplo n.º 58
0
	def getAddonsList(self):
		from locale import strxfrm
		return sorted(addonHandler.getAvailableAddons(), key=lambda a: strxfrm(a.manifest['summary']))
Ejemplo n.º 59
0
def _compare_locale_str(value):
    # In PY2, strxfrm does not support unicode encoded values, so we have to get creative.
    if not six.PY2:
        return locale.strxfrm(force_text(value))
    else:
        return _compare_by_strcoll(force_text(value))
Ejemplo n.º 60
0
    def strxfrm(self, s):
        assert 0  # Not properly implemented. TODO

        return locale.strxfrm(s)