def gather_info(self):
     """Walk through emails within selected label and collect info."""
     self.M.select(self.label)
     rc, data = self.M.search(None, 'ALL')
     i = 1
     if testcase:        # for debugging only: can choose a single email to test on. (set at top)
         print '\n-------- SINGLE TESTCASE:', testcase
         resp, header = self.M.FETCH(testcase, '(BODY[HEADER])')
         msg = HeaderParser().parsestr(header[0][1])
         e_sub = re_sub(msg['Subject'])
         print msg['From'], '---'
         e_from = extract_emails(msg['From'])
         e_to = extract_emails(msg['To'])
         e_cc = extract_emails(msg['CC'])
         for key in msg.keys():
             print key, ':\n', msg[key], '\n'
         print 'Sub:', e_sub
         print 'Frm:', e_from
         print 'To: ', e_to
         print 'CC: '
         for email in e_cc:
             print '\t', email
         #print 'Dte:', e_date
         print '\n'
     else:               # normal functionality - iterates over labels returned num list.
         total = self.get_count()
         for num in data[0].split():
             #percent_done = get_percentage(i, total)
             print 'Grabbing', str(num).zfill(len(total)), 'of', total#, '\tComplete:', percent_done
             resp, header = self.M.FETCH(num, '(BODY[HEADER])')
             if debug: print 'header_data:\n', header
             msg = HeaderParser().parsestr(header[0][1])
             e_sub = re_sub(msg['Subject'])
             e_from = extract_emails(msg['From'])
             e_to = extract_emails(msg['To'])
             e_cc = extract_emails(msg['CC'])
             #e_date = date_to_epoch(msg['Date'])
             self.add_info_norm(e_sub, e_from, e_to, e_cc)
             if debug:
                 print 'Sub: ', e_sub
                 print 'Frm: ', e_from
                 print 'To:  ', e_to
                 print 'CC: '
                 for email in e_cc:
                     print '\t', email
                 #print 'Date:', e_date
                 print '\n'
             i += 1
             if limit:
                 if i > max_limit:
                     print '\nReached "max_limit" of', max_limit, '- Ending c.gather_info()\n'
                     break
Exemple #2
0
    def __init__(self, filename: Path, authors_overrides: dict):
        """Init object from an open PEP file object.

        pep_file is full text of the PEP file, filename is path of the PEP file, author_lookup is author exceptions file

        """
        self.filename: Path = filename

        # Parse the headers.
        pep_text = filename.read_text(encoding="utf-8")
        metadata = HeaderParser().parsestr(pep_text)
        required_header_misses = PEP.required_headers - set(metadata.keys())
        if required_header_misses:
            _raise_pep_error(self, f"PEP is missing required headers {required_header_misses}")

        try:
            self.number = int(metadata["PEP"])
        except ValueError:
            _raise_pep_error(self, "PEP number isn't an integer")

        # Check PEP number matches filename
        if self.number != int(filename.stem[4:]):
            _raise_pep_error(self, f"PEP number does not match file name ({filename})", pep_num=True)

        # Title
        self.title: str = metadata["Title"]

        # Type
        self.pep_type: str = metadata["Type"]
        if self.pep_type not in TYPE_VALUES:
            _raise_pep_error(self, f"{self.pep_type} is not a valid Type value", pep_num=True)

        # Status
        status = metadata["Status"]
        if status in SPECIAL_STATUSES:
            status = SPECIAL_STATUSES[status]
        if status not in STATUS_VALUES:
            _raise_pep_error(self, f"{status} is not a valid Status value", pep_num=True)

        # Special case for Active PEPs.
        if status == STATUS_ACTIVE and self.pep_type not in ACTIVE_ALLOWED:
            msg = "Only Process and Informational PEPs may have an Active status"
            _raise_pep_error(self, msg, pep_num=True)

        # Special case for Provisional PEPs.
        if status == STATUS_PROVISIONAL and self.pep_type != TYPE_STANDARDS:
            msg = "Only Standards Track PEPs may have a Provisional status"
            _raise_pep_error(self, msg, pep_num=True)
        self.status: str = status

        # Parse PEP authors
        self.authors: list[Author] = _parse_authors(self, metadata["Author"], authors_overrides)
Exemple #3
0
    def __init__(self, filename: Path):
        """Init object from an open PEP file object.

        pep_file is full text of the PEP file, filename is path of the PEP file, author_lookup is author exceptions file

        """
        self.filename: Path = filename

        # Parse the headers.
        pep_text = filename.read_text(encoding="utf-8")
        metadata = HeaderParser().parsestr(pep_text)
        required_header_misses = PEP.required_headers - set(metadata.keys())
        if required_header_misses:
            _raise_pep_error(
                self,
                f"PEP is missing required headers {required_header_misses}")

        try:
            self.number = int(metadata["PEP"])
        except ValueError:
            _raise_pep_error(self, "PEP number isn't an integer")

        # Check PEP number matches filename
        if self.number != int(filename.stem[4:]):
            _raise_pep_error(
                self,
                f"PEP number does not match file name ({filename})",
                pep_num=True)

        # Title
        self.title: str = metadata["Title"]

        # Type
        self.pep_type: str = metadata["Type"]
        if self.pep_type not in TYPE_VALUES:
            _raise_pep_error(self,
                             f"{self.pep_type} is not a valid Type value",
                             pep_num=True)

        # Status
        status = metadata["Status"]
        if status in SPECIAL_STATUSES:
            status = SPECIAL_STATUSES[status]
        if status not in STATUS_VALUES:
            _raise_pep_error(self,
                             f"{status} is not a valid Status value",
                             pep_num=True)

        # Special case for Active PEPs.
        if status == STATUS_ACTIVE and self.pep_type not in ACTIVE_ALLOWED:
            msg = "Only Process and Informational PEPs may have an Active status"
            _raise_pep_error(self, msg, pep_num=True)

        # Special case for Provisional PEPs.
        if status == STATUS_PROVISIONAL and self.pep_type != TYPE_STANDARDS:
            msg = "Only Standards Track PEPs may have a Provisional status"
            _raise_pep_error(self, msg, pep_num=True)
        self.status: str = status

        # Parse PEP authors
        self.authors: list[Author] = _parse_authors(self, metadata["Author"],
                                                    AUTHOR_OVERRIDES)

        # Topic (for sub-indices)
        _topic = metadata.get("Topic", "").lower().split(",")
        self.topic: set[str] = {
            topic
            for topic_raw in _topic if (topic := topic_raw.strip())
        }

        # Other headers
        self.created = metadata["Created"]
        self.discussions_to = metadata["Discussions-To"]
        self.python_version = metadata["Python-Version"]
        self.replaces = metadata["Replaces"]
        self.requires = metadata["Requires"]
        self.resolution = metadata["Resolution"]
        self.superseded_by = metadata["Superseded-By"]
        if metadata["Post-History"]:
            # Squash duplicate whitespace
            self.post_history = " ".join(metadata["Post-History"].split())
        else:
            self.post_history = None