diff options
Diffstat (limited to 'cgi/api.py')
-rw-r--r-- | cgi/api.py | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -12,11 +12,11 @@ def api(self, path_split): if len(path_split) > 2: try: self.output = api_process(self, path_split) - except APIError, e: + except APIError as e: self.output = api_error("error", e.message) - except UserError, e: + except UserError as e: self.output = api_error("failed", e.message) - except Exception, e: + except Exception as e: import sys import traceback exc_type, exc_value, exc_traceback = sys.exc_info() @@ -37,7 +37,7 @@ def api_process(self, path_split): #bans = ['181.72.116.62'] bans = [] if ip in bans: - raise APIError, "You have been blacklisted." + raise APIError("You have been blacklisted.") # with open('../api_log.txt', 'a') as f: # logstr = "[%s] %s: %s\n" % (formatTimestamp(t), ip, repr(path_split)) @@ -66,16 +66,16 @@ def api_process(self, path_split): try: limit = int(data_limit) except ValueError: - raise APIError, "Limit must be numeric" + raise APIError("Limit must be numeric") if data_since: try: since = int(data_since) except ValueError: - raise APIError, "Since must be numeric" + raise APIError("Since must be numeric") if limit > 50: - raise APIError, "Maximum limit is 50" + raise APIError("Maximum limit is 50") sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % ( since, limit) @@ -101,10 +101,10 @@ def api_process(self, path_split): try: limit = int(data_limit) except ValueError: - raise APIError, "Limit must be numeric" + raise APIError("Limit must be numeric") if limit > 50: - raise APIError, "Maximum limit is 50" + raise APIError("Maximum limit is 50") threads = getLastAge(limit) if threads[0]['bumped'] > int(data_time): @@ -121,28 +121,28 @@ def api_process(self, path_split): numreplies = 2 if not data_board: - raise APIError, "Missing parameters" + raise APIError("Missing parameters") if data_limit: try: limit = int(data_limit) except ValueError: - raise APIError, "Limit must be numeric" + raise APIError("Limit must be numeric") if data_offset: try: offset = int(data_offset) except ValueError: - raise APIError, "Offset must be numeric" + raise APIError("Offset must be numeric") if data_replies: try: numreplies = int(data_replies) except ValueError: - raise APIError, "Replies must be numeric" + raise APIError("Replies must be numeric") if data_replies and limit > 30: - raise APIError, "Maximum limit is 30" + raise APIError("Maximum limit is 30") board = setBoard(data_board) @@ -207,19 +207,19 @@ def api_process(self, path_split): limit = 1000 if not data_board or (not data_threadid and not data_threadts): - raise APIError, "Missing parameters" + raise APIError("Missing parameters") if data_limit: try: limit = int(data_limit) except ValueError: - raise APIError, "Limit must be numeric" + raise APIError("Limit must be numeric") if data_offset: try: offset = int(data_offset) except ValueError: - raise APIError, "Offset must be numeric" + raise APIError("Offset must be numeric") if data_striphtml: if int(data_striphtml) == 1: @@ -241,13 +241,13 @@ def api_process(self, path_split): pass if not search_val: - raise APIError, "No thread ID" + raise APIError("No thread ID") op_post = FetchOne("SELECT id, timestamp, subject, locked FROM posts WHERE `%s` = '%d' AND boardid = '%s' AND parentid = 0" % ( search_field, search_val, board["id"])) if not op_post: - raise APIError, "Not a thread" + raise APIError("Not a thread") values['id'] = int(op_post['id']) values['timestamp'] = int(op_post['timestamp']) @@ -297,7 +297,7 @@ def api_process(self, path_split): data_postnum = formdata.get('num') if not data_board and (not data_postid or (not data_postnum and not data_parentid)): - raise APIError, "Missing parameters" + raise APIError("Missing parameters") board = setBoard(data_board) postid = 0 @@ -308,13 +308,13 @@ def api_process(self, path_split): try: postid = int(data_postid) except ValueError: - raise APIError, "Post ID must be numeric" + raise APIError("Post ID must be numeric") post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id`='%d' AND boardid='%s'" % ( postid, board["id"])) if not post: - raise APIError, "Post ID cannot be found" + raise APIError("Post ID cannot be found") values['posts'] = [] @@ -345,7 +345,7 @@ def api_process(self, path_split): data_password = formdata.get('password') if not data_board or not data_postid or not data_password: - raise APIError, "Missing parameters" + raise APIError("Missing parameters") imageonly = False board = setBoard(data_board) @@ -353,7 +353,7 @@ def api_process(self, path_split): try: postid = int(data_postid) except ValueError: - raise APIError, "Post ID must be numeric" + raise APIError("Post ID must be numeric") if data_imageonly and data_imageonly == 1: imageonly = True @@ -363,7 +363,7 @@ def api_process(self, path_split): boarddir = formdata.get('board') if not boarddir: - raise APIError, "Missing parameters" + raise APIError("Missing parameters") parent = formdata.get('parent') trap1 = formdata.get('name', '') @@ -378,7 +378,7 @@ def api_process(self, path_split): oek_file = formdata.get('oek_file') password = formdata.get('password', '') noimage = formdata.get('noimage') - mobile = ("mobile" in formdata.keys()) + mobile = ("mobile" in formdata) # call post function (post_url, ttaken, postid) = self.make_post(ip, boarddir, parent, trap1, trap2, name, @@ -394,10 +394,10 @@ def api_process(self, path_split): try: limit = int(data_limit) except ValueError: - raise APIError, "Limit must be numeric" + raise APIError("Limit must be numeric") if limit > 30: - raise APIError, "Maximum limit is 30" + raise APIError("Maximum limit is 30") threads = getNewThreads(limit) values['threads'] = threads @@ -419,7 +419,7 @@ def api_process(self, path_split): board['numthreads'] = int(board['numthreads']) board['maxsize'] = int(board['maxsize']) else: - raise APIError, "Invalid method" + raise APIError("Invalid method") values['time'] = int(t) #values['time_taken'] = time.time() - t |