@@ -69,7 +69,7 @@ def repo_url(user_name, repo_name):
6969
7070 return 'https://bitbucket.com/%s/%s' % (quote (user_name ), quote (repo_name ))
7171
72- def download_info (self , url , tag_prefix = None ):
72+ async def download_info (self , url , tag_prefix = None ):
7373 """
7474 Retrieve information about downloading a package
7575
@@ -97,12 +97,12 @@ def download_info(self, url, tag_prefix=None):
9797 `date` - the ISO-8601 timestamp string when the version was published
9898 """
9999
100- output = self .download_info_from_branch (url )
100+ output = await self .download_info_from_branch (url )
101101 if output is None :
102- output = self .download_info_from_tags (url , tag_prefix )
102+ output = await self .download_info_from_tags (url , tag_prefix )
103103 return output
104104
105- def download_info_from_branch (self , url , default_branch = None ):
105+ async def download_info_from_branch (self , url , default_branch = None ):
106106 """
107107 Retrieve information about downloading a package
108108
@@ -135,18 +135,18 @@ def download_info_from_branch(self, url, default_branch=None):
135135 if branch is None :
136136 branch = default_branch
137137 if branch is None :
138- repo_info = self .fetch_json (self ._api_url (user_repo ))
138+ repo_info = await self .fetch_json (self ._api_url (user_repo ))
139139 branch = repo_info ['mainbranch' ].get ('name' , 'master' )
140140
141141 branch_url = self ._api_url (user_repo , '/refs/branches/%s' % branch )
142- branch_info = self .fetch_json (branch_url )
142+ branch_info = await self .fetch_json (branch_url )
143143
144144 timestamp = branch_info ['target' ]['date' ][0 :19 ].replace ('T' , ' ' )
145145 version = re .sub (r'[\-: ]' , '.' , timestamp )
146146
147147 return [self ._make_download_info (user_repo , branch , version , timestamp )]
148148
149- def download_info_from_releases (self , url , asset_templates , tag_prefix = None ):
149+ async def download_info_from_releases (self , url , asset_templates , tag_prefix = None ):
150150 """
151151 BitBucket doesn't support releases in ways GitHub/Gitlab do.
152152
@@ -158,7 +158,7 @@ def download_info_from_releases(self, url, asset_templates, tag_prefix=None):
158158
159159 return None
160160
161- def download_info_from_tags (self , url , tag_prefix = None ):
161+ async def download_info_from_tags (self , url , tag_prefix = None ):
162162 """
163163 Retrieve information about downloading a package
164164
@@ -188,12 +188,12 @@ def download_info_from_tags(self, url, tag_prefix=None):
188188 if not tags_match :
189189 return None
190190
191- def _get_releases (user_repo , tag_prefix , page_size = 100 ):
191+ async def _get_releases (user_repo , tag_prefix , page_size = 100 ):
192192 used_versions = set ()
193193 query_string = urlencode ({'pagelen' : page_size })
194194 tags_url = self ._api_url (user_repo , '/refs/tags?%s' % query_string )
195195 while tags_url :
196- tags_json = self .fetch_json (tags_url )
196+ tags_json = await self .fetch_json (tags_url )
197197 for tag in tags_json ['values' ]:
198198 version = version_match_prefix (tag ['name' ], tag_prefix )
199199 if version and version not in used_versions :
@@ -212,7 +212,7 @@ def _get_releases(user_repo, tag_prefix, page_size=100):
212212 num_releases = 0
213213
214214 output = []
215- for release in sorted ( _get_releases (user_repo , tag_prefix ), reverse = True ):
215+ async for release in _get_releases (user_repo , tag_prefix ):
216216 version , tag , timestamp = release
217217
218218 output .append (self ._make_download_info (user_repo , tag , str (version ), timestamp ))
@@ -221,9 +221,10 @@ def _get_releases(user_repo, tag_prefix, page_size=100):
221221 if max_releases > 0 and num_releases >= max_releases :
222222 break
223223
224+ output .sort (reverse = True )
224225 return output
225226
226- def repo_info (self , url ):
227+ async def repo_info (self , url ):
227228 """
228229 Retrieve general information about a repository
229230
@@ -254,7 +255,7 @@ def repo_info(self, url):
254255
255256 user_repo = "%s/%s" % (user_name , repo_name )
256257 api_url = self ._api_url (user_repo )
257- repo_info = self .fetch_json (api_url )
258+ repo_info = await self .fetch_json (api_url )
258259
259260 if branch is None :
260261 branch = repo_info ['mainbranch' ].get ('name' , 'master' )
@@ -266,7 +267,7 @@ def repo_info(self, url):
266267 author = repo_info ['owner' ].get ('username' )
267268
268269 is_client = self .settings .get ('min_api_calls' , False )
269- readme_url = None if is_client else self ._readme_url (user_repo , branch )
270+ readme_url = None if is_client else await self ._readme_url (user_repo , branch )
270271
271272 return {
272273 'name' : repo_info ['name' ],
@@ -279,7 +280,7 @@ def repo_info(self, url):
279280 'default_branch' : branch
280281 }
281282
282- def user_info (self , url ):
283+ async def user_info (self , url ):
283284 """
284285 For API compatibility with other clients.
285286
@@ -341,7 +342,7 @@ def _api_url(self, user_repo, suffix=''):
341342
342343 return 'https://api.bitbucket.org/2.0/repositories/%s%s' % (user_repo , suffix )
343344
344- def _readme_url (self , user_repo , branch , prefer_cached = False ):
345+ async def _readme_url (self , user_repo , branch , prefer_cached = False ):
345346 """
346347 Parse the root directory listing for the repo and return the URL
347348 to any file that looks like a readme
@@ -367,7 +368,7 @@ def _readme_url(self, user_repo, branch, prefer_cached=False):
367368
368369 try :
369370 while listing_url :
370- root_dir_info = self .fetch_json (listing_url , prefer_cached )
371+ root_dir_info = await self .fetch_json (listing_url , prefer_cached )
371372
372373 for entry in root_dir_info ['values' ]:
373374 if entry ['path' ].lower () in _readme_filenames :
0 commit comments