22import urllib
33import simplejson as json
44import re
5+ from yaml import load , dump
6+ try :
7+ from yaml import CLoader as Loader , CDumper as Dumper
8+ except ImportError :
9+ from yaml import Loader , Dumper
510
11+ import xml .etree .ElementTree
612
713class Jokes :
814 def __init__ (self ):
915 self .http = urllib3 .PoolManager ()
10- print ("Sv443's JokeAPI" )
1116
1217 def build_request (
1318 self ,
@@ -148,11 +153,6 @@ def send_request(self, request, response_format, return_headers, auth_token, use
148153 except :
149154 print (data )
150155 raise
151- else :
152- data = str (data )[2 :- 1 ].replace (r'\n' , '\n ' ).replace ('\\ ' , '' )
153- if len (' ' .join (re .split ("error" , data .lower ().replace ("\n " , "NEWLINECHAR" ))[0 :][1 :]).replace (
154- '<' , '' ).replace ('/' , '' ).replace (' ' , '' ).replace (':' , '' ).replace ('>' , '' ).replace ('NEWLINECHAR' , '\n ' )) == 4 :
155- return [Exception (f"API returned an error. Full response: \n \n { data } " )]
156156
157157 headers = str (r .headers ).replace (r'\n' , '' ).replace (
158158 '\n ' , '' ).replace (r'\\' , '' ).replace (r"\'" , '' )[15 :- 1 ]
@@ -164,7 +164,9 @@ def send_request(self, request, response_format, return_headers, auth_token, use
164164 if auth_token :
165165 returns .append ({"Token-Valid" : bool (int (re .split (r"Token-Valid" , headers )[1 ][4 ]))})
166166
167- return returns
167+ if len (returns ) > 1 :
168+ return returns
169+ return returns [0 ]
168170
169171 def get_joke (
170172 self ,
0 commit comments