]> jfr.im git - z_archive/twitter.git/commitdiff
Fix ResourceWarning on read_bearer_toke_file func
authorCristovao Verstraeten <redacted>
Tue, 15 Mar 2016 21:39:32 +0000 (22:39 +0100)
committerCristovao Verstraeten <redacted>
Tue, 15 Mar 2016 21:39:32 +0000 (22:39 +0100)
This should fix the following warning when doing a unit test: ResourceWarning: unclosed file <_io.TextIOWrapper name='bearer_token' mode='r' encoding='cp1252'>

twitter/oauth2.py

index fb5fefe9e4543aefb534b8d67ae76c354d3d8c82..330d88cac38fd6018fd810f8d65d1de2236e5379 100644 (file)
@@ -46,7 +46,9 @@ def read_bearer_token_file(filename):
     Read a token file and return the oauth2 bearer token.
     """
     f = open(filename)
-    return f.readline().strip()
+    bearer_token = f.readline().strip()
+    f.close()
+    return bearer_token
 
 class OAuth2(Auth):
     """