Skip to content

Commit 09018d8

Browse files
authored
Update to v1.0.2
1 parent 4fbb520 commit 09018d8

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/fortune/main.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
import time
1414

1515
import strfile
16+
import rot13
1617

1718
# Version string used by the what(1) and ident(1) commands:
18-
ID = "@(#) $Id: fortune - print a random, hopefully interesting, adage v1.0.0 (August 11, 2021) by Hubert Tournier $"
19+
ID = "@(#) $Id: fortune - print a random, hopefully interesting, adage v1.0.2 (August 13, 2021) by Hubert Tournier $"
1920

2021
# Default parameters. Can be overcome by environment variables, then command line options
2122
parameters = {
@@ -555,7 +556,7 @@ def search_for_pattern(fortune_files):
555556
continue
556557

557558
if file["Header"]["rotated flag"]:
558-
fortune = rot13(fortune)
559+
fortune = rot13.rot(fortune)
559560

560561
if parameters["Ignore case"]:
561562
results = re.search(parameters["Pattern"], fortune, flags=re.IGNORECASE)
@@ -592,24 +593,6 @@ def select_fortune_file(fortune_files):
592593
return None
593594

594595

595-
################################################################################
596-
def rot13(fortune):
597-
"""Return the ROT13 version of the given fortune"""
598-
# TODO:
599-
# To be moved one day in a future rot13 command/library
600-
rotated_fortune = ""
601-
for character in fortune:
602-
if character.isalpha():
603-
if character.isupper():
604-
rotated_fortune += chr(ord('A') + (ord(character) - ord('A') + 13) % 26)
605-
else:
606-
rotated_fortune += chr(ord('a') + (ord(character) - ord('a') + 13) % 26)
607-
else:
608-
rotated_fortune += character
609-
610-
return rotated_fortune
611-
612-
613596
################################################################################
614597
def select_fortune(file):
615598
"""Randomly choose a fortune from a fortune file"""
@@ -643,7 +626,7 @@ def select_fortune(file):
643626
continue
644627

645628
if file["Header"]["rotated flag"]:
646-
return rot13(fortune)
629+
return rot13.rot(fortune)
647630

648631
return fortune
649632

0 commit comments

Comments
 (0)