Ejemplo n.º 1
0
 def passage(self, reference="-"):
     match = self._PASSAGE_REGEX.match(reference)
     if match is None:
         raise utils.BibleReferenceError(
             f"the reference, '{reference}' does not match the expected regex, {self._PASSAGE_REGEX}"
         )
     groups = match.groupdict()
     chapter_number_start = utils.safe_int(groups["chapter_number_start"])
     chapter_start = self[chapter_number_start or 1]
     verse_number_start = utils.safe_int(groups["verse_number_start"])
     verse_start = chapter_start[verse_number_start or 1]
     if groups["range"] is None:
         chapter_end = chapter_start
         verse_end = verse_start
     else:
         verse_number_end = utils.safe_int(groups["verse_number_end"])
         chapter_end = self[
             utils.safe_int(groups["chapter_number_end"])
             or (chapter_number_start if verse_number_end else len(self))]
         verse_end = chapter_end[verse_number_end or len(chapter_end)]
     if int(verse_end.int_reference) < int(verse_start.int_reference):
         raise utils.BibleReferenceError(
             "the requested passage range is invalid; the right hand side of the range must be greater than the left"
         )
     return self._translation.Passage(self, chapter_start, verse_start,
                                      self, chapter_end, verse_end)
Ejemplo n.º 2
0
 def passage(self, reference=None, int_reference=None):
     if reference is not None:
         if int_reference is not None:
             raise ValueError(
                 "reference and int_reference are mutually exclusive arguments; only 1 should be not None"
             )
         match = self._PASSAGE_REGEX.match(utils.slugify(reference))
         if match is None:
             raise utils.BibleReferenceError(
                 f"the reference, '{reference}' does not match the expected regex, {self._PASSAGE_REGEX}"
             )
         book_start_group = "book_name_start"
         book_end_group = "book_name_end"
     else:
         if int_reference is None:
             raise ValueError(
                 "either reference or int_reference must be not None")
         match = self._INT_PASSAGE_REGEX.match(utils.slugify(int_reference))
         if match is None:
             raise utils.BibleReferenceError(
                 f"the int_reference, {int_reference} does not match the expected regex, {self._INT_PASSAGE_REGEX}"
             )
         book_start_group = "book_number_start"
         book_end_group = "book_number_end"
     groups = match.groupdict()
     book_start_identifier = utils.safe_int(groups[book_start_group])
     book_start = self._books[book_start_identifier or 1]
     chapter_number_start = utils.safe_int(groups["chapter_number_start"])
     chapter_start = book_start[chapter_number_start or 1]
     verse_start = chapter_start[
         utils.safe_int(groups["verse_number_start"]) or 1]
     if groups["range"] is None:
         book_end = book_start
         chapter_end = chapter_start
         verse_end = verse_start
     else:
         chapter_number_end = utils.safe_int(groups["chapter_number_end"])
         verse_number_end = utils.safe_int(groups["verse_number_end"])
         book_end = self._books[utils.safe_int(groups[book_end_group]) or (
             book_start_identifier if (
                 chapter_number_end or verse_number_end) else len(self))]
         chapter_end = book_end[chapter_number_end or (
             chapter_number_start if verse_number_end else len(book_end))]
         verse_end = chapter_end[verse_number_end or len(chapter_end)]
     if int(verse_end.int_reference) < int(verse_start.int_reference):
         raise utils.BibleReferenceError(
             "the requested passage range is invalid; the right hand side of the range must be greater than the left"
         )
     return self.Passage(book_start, chapter_start, verse_start, book_end,
                         chapter_end, verse_end)
Ejemplo n.º 3
0
 def __getitem__(self, key):
     try:
         return self._chapters[key]
     except KeyError:
         raise utils.BibleReferenceError(
             f"{key} is not a valid number between {str(self.first())} and {str(self.last())}"
         )
Ejemplo n.º 4
0
 def __getitem__(self, key):
     try:
         return self._books[utils.slugify(key)]
     except KeyError:
         raise utils.BibleReferenceError(f"{key} cannot be found")