Calum Lind 535b13b5f1 [Plugins] Convert plugins to deluge_ module prefix convention
This commit reverts namespace for the plugins and uses a module prefix
"deluge_" in it's place. The distribution package name remains the same
for now but will also be considered to use a prefix to help find the
third-party plugins e.g. Deluge-{Plugin} and the pluginmanager will
strip the prefix for displaying.

The change is a result of problems trying to package Deluge with
pyinstaller and the pkg_resources namespaces is not compatible.
Testing alternatives to using the pkgutil or PEP420 (native) namespaces
did not yield any joy either as importing eggs with namespaces does not
work. [1]

At this point importable eggs are considered deprecated but there is no
viable alternative yet. [2]

[1] https://github.com/pypa/packaging-problems/issues/212
[2] https://github.com/pypa/packaging-problems/issues/244
2019-05-15 19:20:08 +01:00

73 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Steve 'Tarka' Smith (tarka@internode.on.net)
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
from __future__ import unicode_literals
import gzip
import logging
import socket
from struct import unpack
log = logging.getLogger(__name__)
class PGException(Exception):
pass
# Incrementally reads PeerGuardian blocklists v1 and v2.
# See http://wiki.phoenixlabs.org/wiki/P2B_Format
class PGReader(object):
def __init__(self, filename):
log.debug('PGReader loading: %s', filename)
try:
with gzip.open(filename, 'rb') as _file:
self.fd = _file
except IOError:
log.debug('Blocklist: PGReader: Incorrect file type or list is corrupt')
# 4 bytes, should be 0xffffffff
buf = self.fd.read(4)
hdr = unpack('l', buf)[0]
if hdr != -1:
raise PGException(_('Invalid leader') + ' %d' % hdr)
magic = self.fd.read(3)
if magic != 'P2B':
raise PGException(_('Invalid magic code'))
buf = self.fd.read(1)
ver = ord(buf)
if ver != 1 and ver != 2:
raise PGException(_('Invalid version') + ' %d' % ver)
def __next__(self):
# Skip over the string
buf = -1
while buf != 0:
buf = self.fd.read(1)
if buf == '': # EOF
return False
buf = ord(buf)
buf = self.fd.read(4)
start = socket.inet_ntoa(buf)
buf = self.fd.read(4)
end = socket.inet_ntoa(buf)
return (start, end)
# Python 2 compatibility
next = __next__
def close(self):
self.fd.close()