/usr/lib/python3/dist-packages/pynzb/base.py is in python3-pynzb 0.1.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import datetime
import time
def parse_date(date):
if isinstance(date, str):
date = int(date)
gmtime = time.gmtime(date)
return datetime.date(gmtime.tm_year, gmtime.tm_mon, gmtime.tm_mday)
class NZBSegment(object):
def __init__(self, bytes, number, message_id=None):
self.bytes = int(bytes)
self.number = int(number)
if message_id:
self.message_id = message_id
def set_message_id(self, message_id):
self.message_id = message_id
class NZBFile(object):
def __init__(self, poster, date, subject, groups=None, segments=None):
self.poster = poster
self.date = parse_date(date)
self.subject = subject
self.groups = groups or []
self.segments = segments or []
def add_group(self, group):
self.groups.append(group)
def add_segment(self, segment):
self.segments.append(segment)
class BaseNZBParser(object):
def parse(self, xml):
raise NotImplementedError
class BaseETreeNZBParser(BaseNZBParser):
def get_etree_iter(self, xml, et=None):
raise NotImplementedError
def parse(self, xml):
context = self.get_etree_iter(xml)
files, current_file, current_segment = [], None, None
for event, elem in context:
if event == "start":
# If it's an NZBFile, create an object so that we can add the
# appropriate stuff to it.
if elem.tag == "{http://www.newzbin.com/DTD/2003/nzb}file":
current_file = NZBFile(
poster = elem.attrib['poster'],
date = elem.attrib['date'],
subject = elem.attrib['subject']
)
elif event == "end":
if elem.tag == "{http://www.newzbin.com/DTD/2003/nzb}file":
files.append(current_file)
elif elem.tag == "{http://www.newzbin.com/DTD/2003/nzb}group":
current_file.add_group(elem.text)
elif elem.tag == "{http://www.newzbin.com/DTD/2003/nzb}segment":
current_file.add_segment(
NZBSegment(
bytes = elem.attrib['bytes'],
number = elem.attrib['number'],
message_id = elem.text
)
)
# Clear the element, we don't need it any more.
elem.clear()
return files
|