11from time import sleep
22
33from ravenpackapi .exceptions import api_method
4+ from ravenpackapi .upload .upload_utils import retry_404
45
56FILE_FIELDS = (
67 'file_id' , 'file_name' , 'folder_id' ,
@@ -64,33 +65,36 @@ def get_metadata(self, force_refresh=False):
6465
6566 @api_method
6667 def save_original (self , filename ):
67- response = self .api .request ('%s/files/%s' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
68- stream = True )
68+ response = retry_404 (self .api .request ,
69+ '%s/files/%s' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
70+ stream = True )
6971 with open (filename , 'wb' ) as f :
7072 for chunk in response .iter_content (chunk_size = self .api ._CHUNK_SIZE ):
7173 f .write (chunk )
7274
7375 @api_method
7476 def save_analytics (self , filename , output_format = 'application/json' ):
7577 self .wait_for_completion ()
76- response = self .api .request ('%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
77- headers = dict (
78- Accept = output_format ,
79- ** self .api .headers
80- ),
81- stream = True )
78+ response = retry_404 (self .api .request ,
79+ '%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
80+ headers = dict (
81+ Accept = output_format ,
82+ ** self .api .headers
83+ ),
84+ stream = True )
8285 with open (filename , 'wb' ) as f :
8386 for chunk in response .iter_content (chunk_size = self .api ._CHUNK_SIZE ):
8487 f .write (chunk )
8588
8689 @api_method
8790 def get_analytics (self , output_format = 'application/json' ):
8891 self .wait_for_completion ()
89- response = self .api .request ('%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
90- headers = dict (
91- Accept = output_format ,
92- ** self .api .headers
93- ))
92+ response = retry_404 (self .api .request ,
93+ '%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
94+ headers = dict (
95+ Accept = output_format ,
96+ ** self .api .headers
97+ ))
9498 if output_format == 'application/json' :
9599 return response .json ()
96100 else :
@@ -99,22 +103,27 @@ def get_analytics(self, output_format='application/json'):
99103 @api_method
100104 def save_annotated (self , filename ):
101105 self .wait_for_completion ()
102- response = self .api .request ('%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
103- stream = True )
106+ response = retry_404 (self .api .request ,
107+ '%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
108+ stream = True )
104109 with open (filename , 'wb' ) as f :
105110 for chunk in response .iter_content (chunk_size = self .api ._CHUNK_SIZE ):
106111 f .write (chunk )
107112
108113 @api_method
109114 def get_annotated (self ):
110115 self .wait_for_completion ()
111- response = self .api .request ('%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id ))
116+ response = retry_404 (self .api .request ,
117+ '%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id )
118+ )
112119 return response .text
113120
114121 @api_method
115122 def delete (self ):
116- response = self .api .request ('%s/files/%s' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
117- method = 'delete' )
123+ response = retry_404 (self .api .request ,
124+ '%s/files/%s' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
125+ method = 'delete'
126+ )
118127 return response
119128
120129 @api_method
0 commit comments