# Buggy code
def UpdateDownloadFilters(self):
    proccessedfilters = []
    outfilter = "(\\\\("
    failed = {}
    df = self.np.config.sections["transfers"]["downloadfilters"]
    df.sort()
    # Get Filters from config file and check their escaped status
    # Test if they are valid regular expressions and save error messages

    for item in df:
        filter, escaped = item
        if escaped:
            dfilter = re.escape(filter)
            dfilter = dfilter.replace("\\*", ".*")
        else:
            dfilter = filter
        try:
            re.compile("(" + dfilter + ")")
            outfilter += dfilter
            proccessedfilters.append(dfilter)
        except Exception as e:
            failed[dfilter] = e

        proccessedfilters.append(dfilter)

        if item is not df[-1]:
            outfilter += "|"

    # Crop trailing pipes
    while outfilter[-1] == "|":
        outfilter = outfilter[:-1]

    outfilter += ")$)"
    try:
        re.compile(outfilter)
        self.np.config.sections["transfers"]["downloadregexp"] = outfilter
        # Send error messages for each failed filter to log window
        if len(list(failed.keys())) >= 1:
            errors = ""
            for filter, error in list(failed.items()):
                errors += "Filter: %s Error: %s " % (filter, error)
            error = _(
                "Error: %(num)d Download filters failed! %(error)s "
                % {"num": len(list(failed.keys())), "error": errors}
            )
            self.logMessage(error)
    except Exception as e:
        # Strange that individual filters _and_ the composite filter both fail
        self.logMessage(
            _("Error: Download Filter failed! Verify your filters. Reason: %s" % e)
        )
        self.np.config.sections["transfers"]["downloadregexp"] = ""


# Traceback (SystemError)
Thu 07:58 Nicotine+ supports a country code blocker. This requires a (GPL'ed) library called GeoIP. You can find it here: C library:       https://github.com/maxmind/geoip-api-c Python
bindings: https://github.com/maxmind/geoip-api-python (the python bindings require the C library)
Traceback (most recent call last):
File "/usr/local/bin/nicotine", line 255, in <module>
run()
File "/usr/local/bin/nicotine", line 231, in run
app = frame.MainApp(data_dir, config, plugins, trayicon, hidden, bindip, port)
File "/usr/local/lib/python3.7/site-packages/pynicotine/gtkgui/frame.py", line 3595, in __init__
self.frame = NicotineFrame(data_dir, config, plugins, trayicon, start_hidden, bindip, port)
File "/usr/local/lib/python3.7/site-packages/pynicotine/gtkgui/frame.py", line 273, in __init__
config
File "/usr/local/lib/python3.7/site-packages/pynicotine/pynicotine.py", line 130, in __init__
self.shares = Shares(self)
File "/usr/local/lib/python3.7/site-packages/pynicotine/shares.py", line 75, in __init__
self.CompressShares("normal")
File "/usr/local/lib/python3.7/site-packages/pynicotine/shares.py", line 201, in CompressShares
m.makeNetworkMessage(nozlib=0, rebuild=True)
File "/usr/local/lib/python3.7/site-packages/pynicotine/slskmessages.py", line 1709, in makeNetworkMessage
msg = msg + self.packObject(len(list(self.list.keys())))
File "/usr/local/lib/python3.7/_collections_abc.py", line 720, in __iter__
yield from self._mapping
File "/usr/local/lib/python3.7/shelve.py", line 95, in __iter__
for k in self.dict.keys():
SystemError: Negative size passed to PyBytes_FromStringAndSize

# Fixed code
def UpdateDownloadFilters(self):
    proccessedfilters = []
    outfilter = "(\\\\("
    failed = {}
    df = self.np.config.sections["transfers"]["downloadfilters"]
    df.sort()
    # Get Filters from config file and check their escaped status
    # Test if they are valid regular expressions and save error messages

    for item in df:
        filter, escaped = item
        if escaped:
            dfilter = re.escape(filter)
            dfilter = dfilter.replace("\\*", ".*")
        else:
            dfilter = filter
        try:
            re.compile("(" + dfilter + ")")
            outfilter += dfilter
            proccessedfilters.append(dfilter)
        except Exception as e:
            failed[dfilter] = e

        proccessedfilters.append(dfilter)

        if item is not df[-1]:
            outfilter += "|"

    # Crop trailing pipes
    while outfilter[-1] == "|":
        outfilter = outfilter[:-1]

    outfilter += ")$)"
    try:
        re.compile(outfilter)
        self.np.config.sections["transfers"]["downloadregexp"] = outfilter
        # Send error messages for each failed filter to log window
        if len(failed) >= 1:
            errors = ""
            for filter, error in list(failed.items()):
                errors += "Filter: %s Error: %s " % (filter, error)
            error = _(
                "Error: %(num)d Download filters failed! %(error)s "
                % {"num": len(failed), "error": errors}
            )
            self.logMessage(error)
    except Exception as e:
        # Strange that individual filters _and_ the composite filter both fail
        self.logMessage(
            _("Error: Download Filter failed! Verify your filters. Reason: %s" % e)
        )
        self.np.config.sections["transfers"]["downloadregexp"] = ""