Skip to content

Commit e3ab4ea

Browse files
committed
Fixed comments regarding :random
1 parent 417f7f9 commit e3ab4ea

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

lib/routing.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,31 @@ def handle_if_random_request(self,topic):
114114
"""
115115
Return topic type for `topic` or "unknown" if topic can't be determined.
116116
"""
117-
118-
def __select_random_topic(stripped_topic,topic_list):
119-
#Here we remove the special pages if present
117+
118+
def __select_random_topic(prefix,topic_list):
119+
#Here we remove the special cases
120120
if ":list" in topic_list: topic_list.remove(":list")
121121
if "rosetta/" in topic_list: topic_list.remove("rosetta/")
122122
random_topic = random.choice(topic_list)
123-
print("Il random_topic è {}".format(stripped_topic + random_topic))
124-
return stripped_topic + random_topic
123+
return prefix + random_topic
125124

126-
print("Entrato in handle_if_random_request con {}".format(topic))
127125
if topic.endswith('/:random') or topic.lstrip('/') == ':random':
128126
#We strip the :random part and see if the query is valid by running a get_topics_list()
129-
130-
# Here we take the cheat.sh/x/ part
131-
stripped_topic = topic[:-7]
132-
133-
topic_list = [x[len(stripped_topic):]
127+
prefix = topic[:-7]
128+
topic_list = [x[len(prefix):]
134129
for x in self.get_topics_list()
135-
if x.startswith(stripped_topic)]
136-
130+
if x.startswith(prefix)]
137131
if '' in topic_list: topic_list.remove('')
138132
if topic_list:
139-
#This is a correct formatted query like /cpp/:random
140-
print("La richiesta random è giusta")
141-
print("Questa è la topic_list della richiesta :random = {}".format(topic_list))
142-
random_topic = __select_random_topic(stripped_topic,topic_list)
133+
# This is a correct formatted random query like /cpp/:random, the topic_list is not empty.
134+
random_topic = __select_random_topic(prefix,topic_list)
143135
return random_topic
144136
else:
145-
#This is wrongly random formatted
146-
# It is not a valid random request, we just strip the /:random
137+
# This is a wrongly formatted random query like /xyxyxy/:random, the topic_list not empty
138+
# we just strip the /:random and let the already implemented logic handle it.
147139
wrongly_formatted_random = topic[:-8]
148-
print("La richiesta random è sbagliata")
149-
print("Eseguo lo stripping = {}".format(wrongly_formatted_random))
150140
return wrongly_formatted_random
141+
151142
#Here if not a random requst, we just forward the topic
152143
return topic
153144

0 commit comments

Comments
 (0)