29 print("\n--> Ajenti stopped")
30
31class TestBasicHttp:
32 def test_identity(self, handle_ajenti_process): 33 rq = requests.get(url)
34 assert rq.status_code == 200
35 assert 'x-auth-identity' in rq.headers
84 @post(r'/api/datetime/time/(?P<time>\d+)')
85 @authorize('datetime:write')
86 @endpoint(api=True)
87 def handle_api_time_set(self, http_context, time=None): 88 """
89 Set time on the server through date command.
90
54intersphinx_mapping = {'http://docs.python.org/': None}
55
56
57def skip(app, what, name, obj, skip, options): 58 for x in ['all', 'any', 'classes', 'implementations']:
59 if hasattr(obj, x):
60 try:
23 return f
24 return decorator
25
26def requests_decorator_generator(method): 27 """
28 Factorization to generate request decorators like @get or @post.
29
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()