@@ -198,9 +198,9 @@ def check_for_stored_token(self, tokenfile):
198
198
def check_network_accessibility (func ):
199
199
""" Decorator function, not to be called directly.
200
200
Checks if network is accessible and buffers the network request so
201
- that it can be sent again if it fails the first time, due to an invalidated
202
- OAuth2 token. In this case the user will be presented with the login
203
- screen again. If the same user successfully logs in again, the request
201
+ that it can be sent again if it fails the first time, due to an invalidated
202
+ OAuth2 token. In this case the user will be presented with the login
203
+ screen again. If the same user successfully logs in again, the request
204
204
will be resent. """
205
205
206
206
@wraps (func )
@@ -220,7 +220,7 @@ def func_wrapper(inst, *args, **kwargs):
220
220
# Add tuple with current user, and request to be performed
221
221
# to the pending request dictionary
222
222
inst .pending_requests [request_id ] = (
223
- inst .logged_in_user ['data' ]['id' ],
223
+ inst .logged_in_user ['data' ]['id' ],
224
224
current_request )
225
225
# Add current request id to kwargs of function being called
226
226
kwargs ['_request_id' ] = request_id
@@ -271,7 +271,7 @@ def __check_request_parameters(self, url, callback):
271
271
if not isinstance (url , QtCore .QUrl ) and not isinstance (url , basestring ):
272
272
raise TypeError ("url should be a string or QUrl object" )
273
273
if not isinstance (url , QtCore .QUrl ):
274
- url = get_QUrl (url )
274
+ url = QtCore . QUrl (url )
275
275
if not callable (callback ):
276
276
raise TypeError ("callback should be a function or callable." )
277
277
return url
@@ -322,7 +322,7 @@ def get(self, url, callback, *args, **kwargs):
322
322
if not self .add_token (request ):
323
323
self .warning_message .emit ('Warning' ,
324
324
_ (u"Token could not be added to the request" ))
325
-
325
+
326
326
# Check if this is a redirect and keep a count to prevent endless
327
327
# redirects. If redirect_count is not set, init it to 0
328
328
kwargs ['redirect_count' ] = kwargs .get ('redirect_count' ,0 )
@@ -681,10 +681,10 @@ def download_file(self, url, destination, *args, **kwargs):
681
681
kwargs ['destination' ] = destination
682
682
kwargs ['download_url' ] = url
683
683
# Extra call to get() to make sure OAuth2 token is still valid before download
684
- # is initiated. If not, this way the request can be repeated after the user
684
+ # is initiated. If not, this way the request can be repeated after the user
685
685
# reauthenticates
686
686
self .get_logged_in_user (self .__download , * args , ** kwargs )
687
-
687
+
688
688
def upload_file (self , url , source_file , * args , ** kwargs ):
689
689
""" Upload a file to the specified destination on the OSF
690
690
@@ -716,7 +716,7 @@ def upload_file(self, url, source_file, *args, **kwargs):
716
716
Any other keywoard arguments that you want to have passed to the callback
717
717
"""
718
718
# Extra call to get() to make sure OAuth2 token is still valid before download
719
- # is initiated. If not, this way the request can be repeated after the user
719
+ # is initiated. If not, this way the request can be repeated after the user
720
720
# reauthenticates
721
721
kwargs ['upload_url' ] = url
722
722
kwargs ['source_file' ] = source_file
@@ -730,7 +730,7 @@ def __reply_finished(self, callback, *args, **kwargs):
730
730
# Get the error callback function, if set
731
731
errorCallback = kwargs .get ('errorCallback' , None )
732
732
# Get the request id, if set (only for authenticated requests, if a user
733
- # is logged in), so it can be repeated if the user is required to
733
+ # is logged in), so it can be repeated if the user is required to
734
734
# reauthenticate.
735
735
current_request_id = kwargs .pop ('_request_id' , None )
736
736
@@ -794,7 +794,7 @@ def __reply_finished(self, callback, *args, **kwargs):
794
794
return
795
795
# Perform another request with the redirect_url and pass on the callback
796
796
redirect_url = reply .attribute (request .RedirectionTargetAttribute )
797
- # For now, the redirects only work for GET operations (but to my
797
+ # For now, the redirects only work for GET operations (but to my
798
798
# knowledge, those are the only operations they occur for)
799
799
if reply .operation () == self .GetOperation :
800
800
self .get (redirect_url , callback , * args , ** kwargs )
@@ -813,8 +813,8 @@ def __reply_finished(self, callback, *args, **kwargs):
813
813
reply .deleteLater ()
814
814
815
815
def __create_progress_dialog (self , text , filesize ):
816
- """ Creates a progress dialog
817
-
816
+ """ Creates a progress dialog
817
+
818
818
Parameters
819
819
----------
820
820
text : str
@@ -838,7 +838,7 @@ def __transfer_progress(self, transfered, total):
838
838
self .sender ().property ('progressDialog' ).setValue (transfered )
839
839
840
840
def __download (self , reply , download_url , * args , ** kwargs ):
841
- """ The real download function, that is a callback for get_logged_in_user()
841
+ """ The real download function, that is a callback for get_logged_in_user()
842
842
in download_file() """
843
843
# Create tempfile
844
844
tmp_file = QtCore .QTemporaryFile ()
@@ -858,11 +858,11 @@ def __download(self, reply, download_url, *args, **kwargs):
858
858
859
859
# Callback function for when bytes are received
860
860
kwargs ['readyRead' ] = self .__download_readyRead
861
- # Download the file with a get request
861
+ # Download the file with a get request
862
862
self .get (download_url , self .__download_finished , * args , ** kwargs )
863
863
864
864
def __download_readyRead (self , * args , ** kwargs ):
865
- """ callback for a reply object to indicate that data is ready to be
865
+ """ callback for a reply object to indicate that data is ready to be
866
866
written to a buffer. """
867
867
868
868
reply = self .sender ()
@@ -912,7 +912,6 @@ def __upload(self, reply, upload_url, source_file, *args, **kwargs):
912
912
""" Callback for get_logged_in_user() in upload_file(). Does the real
913
913
uploading. """
914
914
# Put checks for the url to be a string or QUrl
915
-
916
915
# Check source file
917
916
if isinstance (source_file , basestring ):
918
917
# Check if the specified file exists, because a situation is possible in which
@@ -941,7 +940,7 @@ def __upload(self, reply, upload_url, source_file, *args, **kwargs):
941
940
kwargs ['uploadProgress' ] = self .__transfer_progress
942
941
943
942
source_file .open (QtCore .QIODevice .ReadOnly )
944
- self .put (upload_url , self .__upload_finished , data_to_send = source_file ,
943
+ self .put (upload_url , self .__upload_finished , data_to_send = source_file ,
945
944
* args , ** kwargs )
946
945
947
946
def __upload_finished (self , reply , * args , ** kwargs ):
@@ -950,7 +949,7 @@ def __upload_finished(self, reply, *args, **kwargs):
950
949
progressDialog = kwargs .pop ('progressDialog' , None )
951
950
if isinstance (progressDialog , QtWidgets .QWidget ):
952
951
progressDialog .deleteLater ()
953
- if not 'data_to_send' in kwargs or not isinstance (kwargs ['data_to_send' ],
952
+ if not 'data_to_send' in kwargs or not isinstance (kwargs ['data_to_send' ],
954
953
QtCore .QIODevice ):
955
954
raise AttributeError ("No valid open file handle" )
956
955
# Close the source file
@@ -963,13 +962,13 @@ def __upload_finished(self, reply, *args, **kwargs):
963
962
964
963
def __close_file_handles (self , * args , ** kwargs ):
965
964
""" Closes any open file handles after a failed transfer. Called by
966
- __reply_finished when a HTTP response code indicating an error has been
965
+ __reply_finished when a HTTP response code indicating an error has been
967
966
received """
968
967
# When a download is failed, close the file handle stored in tmp_file
969
968
tmp_file = kwargs .pop ('tmp_file' , None )
970
969
if isinstance (tmp_file , QtCore .QIODevice ):
971
970
tmp_file .close ()
972
- # File uploads are stored in data_to_send
971
+ # File uploads are stored in data_to_send
973
972
data_to_send = kwargs .pop ('data_to_send' , None )
974
973
if isinstance (data_to_send , QtCore .QIODevice ):
975
974
data_to_send .close ()
@@ -992,4 +991,4 @@ def set_logged_in_user(self, user_data):
992
991
for (user_id , request ) in self .pending_requests .values ():
993
992
if user_id == self .logged_in_user ['data' ]['id' ]:
994
993
request ()
995
- self .pending_requests = {}
994
+ self .pending_requests = {}
0 commit comments