1- # -*- coding: utf-8 -*-
2- #
31# Copyright 2021-2024 Michael Samoglyadov
42#
53# Licensed under the Apache License, Version 2.0 (the "License");
1715import os
1816
1917from flask import Flask , Response , jsonify , render_template , request
20-
2118from nested_diff import Differ , Patcher
22- from nested_diff .formatters import HtmlFormatter , TextFormatter , TermFormatter
19+ from nested_diff .formatters import HtmlFormatter , TermFormatter , TextFormatter
2320from nested_diff .handlers import TextHandler
2421
25-
2622flask_kwargs = {}
2723
2824for kw in ('static_folder' , 'static_url_path' , 'template_folder' ):
2925 try :
3026 flask_kwargs [kw ] = os .environ ['NESTED_DIFF_REST_' + kw .upper ()]
31- except KeyError :
27+ except KeyError : # noqa: PERF203
3228 pass
3329
3430app = Flask (__name__ , ** flask_kwargs )
@@ -76,7 +72,7 @@ def diff():
7672 try :
7773 old = request .json .get ('a' , None )
7874 new = request .json .get ('b' , None )
79- except Exception :
75+ except Exception : # noqa: BLE001
8076 return Response ('Bad request' , status = 400 )
8177
8278 try :
@@ -87,7 +83,7 @@ def diff():
8783
8884 if text_diff_ctx >= 0 :
8985 differ .set_handler (TextHandler (context = text_diff_ctx ))
90- except Exception :
86+ except Exception : # noqa: BLE001
9187 return Response ('Incorrect diff options' , status = 400 )
9288
9389 _ , diff = differ .diff (old , new )
@@ -102,7 +98,7 @@ def diff():
10298
10399
104100@app .route ('/api/v1/format' , methods = ['POST' ])
105- def format ():
101+ def format_diff ():
106102 try :
107103 diff = request .json .get ('diff' , {})
108104 ofmt = request .json .get ('ofmt' , None )
@@ -112,7 +108,7 @@ def format():
112108 ofmt_opts = request .json .get ('ofmt_opts' , {})
113109
114110 return format_diff_response (ofmt , diff , ofmt_opts )
115- except Exception :
111+ except Exception : # noqa: BLE001
116112 return Response ('Incorrect arguments' , status = 400 )
117113
118114
@@ -123,9 +119,9 @@ def patch():
123119 Patcher ().patch (
124120 request .json ['target' ],
125121 request .json ['patch' ],
126- )
122+ ),
127123 )
128- except Exception :
124+ except Exception : # noqa: BLE001
129125 return Response ('Incorrect arguments' , status = 400 )
130126
131127
@@ -155,5 +151,5 @@ def nested_diff_script():
155151 app .run (
156152 host = os .environ .get ('NESTED_DIFF_REST_HOST' , 'localhost' ),
157153 port = os .environ .get ('NESTED_DIFF_REST_PORT' , 8080 ),
158- debug = True if 'NESTED_DIFF_REST_DEBUG' in os .environ else False ,
154+ debug = 'NESTED_DIFF_REST_DEBUG' in os .environ ,
159155 )
0 commit comments