def get_back_path(unit): parts = [(unit.name, '#')] counter = 1 while True: unit = unit.parent if unit is None: break parts.append((unit.name, '../' * counter + quote(unit.name))) counter += 1 continue result = [] index = len(parts) - 1 while True: name, url = parts[index] result.append('<a href="') result.append(url) result.append('">') result.append(html_escape(name)) result.append('</a>') if index == 0: break index -= 1 result.append(' / ') continue return ''.join(result)
def render_description_to(self, extend): organizations = self.organizations if organizations is None: return extend.append('\n\n**Organizations:**\n') for organization in organizations: organization_name = organization.name extend.append('[') extend.append(organization_name) extend.append('](https://github.com/') extend.append(quote(organization_name)) extend.append(')') organization_description = organization.description if (organization_description is not None): if len(organization_description) > 100: organization_description = organization_description[:100] + ' ...' extend.append(': ') extend.append(organization_description) extend.append('\n') truncated = self.truncated if truncated: extend.append('*') extend.append(repr(truncated)) extend.append(' truncated*') else: del extend[-1] return extend
def render_description_to(self, extend): bio = self.bio if (bio is not None): extend.append('```\n') extend.append(bio) extend.append('\n```\n') quoted_name = quote(self.user_name) extend.append('Followers: [') extend.append(repr(self.follower_count)) extend.append('](https://github.com/') extend.append(quoted_name) extend.append('?tab=followers)\n' 'Following: [') extend.append(repr(self.following_count)) extend.append('](https://github.com/') extend.append(quoted_name) extend.append('?tab=following)\n' 'Repositories: [') extend.append(repr(self.repo_count)) extend.append('](https://github.com/') extend.append(quoted_name) extend.append('?tab=following)\n' 'Gists: [') extend.append(repr(self.gist_count)) extend.append('](https://gist.github.com/') extend.append(quoted_name) extend.append(')') if self.has_extra_fields: extend.append('\n') company = self.company if (company is not None): extend.append('\nCompany: ') extend.append(company) location = self.location if (location is not None): extend.append('\nLocation: ') extend.append(location) twitter_user_name = self.twitter_user_name if (twitter_user_name is not None): extend.append('\nTwitter: @') extend.append(twitter_user_name) blog_name = self.blog_name if (blog_name is not None): blog_link = self.blog_link extend.append('\nBlog: [') extend.append(blog_name) extend.append('](') extend.append(blog_link) extend.append(')') return extend
def render_description_to(self, extend): names = self.names limit = len(names) if limit: index = 0 while True: name = names[index] index += 1 extend.append(repr(index)) extend.append('.: [') extend.append(name) extend.append('](https://github.com/') extend.append(quote(name)) extend.append(')') if index == limit: break extend.append('\n') return extend
def render(self): url = quote(self.url, safe=':@', protected='/') value = html_escape(self.value) return f'<a href="{url}">{value}</a>'
def get_searched_info(path, order_priority_base=0): unit = MAPPED_OBJECTS.get(path, None) if unit is None: type_ = None order_priority = 100 else: unit_type = type(unit) if unit_type is FunctionUnit: parent = path.parent parent_unit = MAPPED_OBJECTS.get(parent, None) if parent_unit is None: type_ = 'function' order_priority = UNIT_TYPE_ORDER_PRIORITY_FUNCTION elif type(parent_unit) is TypeUnit: type_ = 'method' order_priority = UNIT_TYPE_ORDER_PRIORITY_METHOD else: type_ = 'function' order_priority = UNIT_TYPE_ORDER_PRIORITY_FUNCTION else: try: type_, order_priority = UNIT_TYPE_ORDER_PRIORITY_TYPE_NAME_RELATION[ unit_type] except KeyError: type_ = None order_priority = UNIT_TYPE_ORDER_PRIORITY_NONE backfetched = [] while True: parent = path.parent parent_unit = MAPPED_OBJECTS.get(parent, None) if parent_unit is None: break if type(parent_unit) is ModuleUnit: break backfetched.append(path.parts[-1]) path = parent continue url_parts = [] name_parts = [] parts = path.parts limit = len(parts) if limit: index = 0 while True: part = parts[index] part = quote(part) url_parts.append(part) index += 1 if index == limit: break url_parts.append('/') name_parts.append(parts[-1]) index = len(backfetched) if index: url_parts.append('#') while True: index -= 1 part = backfetched[index] name_parts.append(part) part = part.lower().replace(' ', '-') part = quote(part) url_parts.append(part) if index == 0: break url_parts.append('-') continue name = '.'.join(name_parts) if order_priority == UNIT_TYPE_ORDER_PRIORITY_CLASS_ATTRIBUTE: while True: docs = unit.docs if (docs is None): fail = True break parent = unit.parent if (parent is None): fail = True break docs = parent.docs if (docs is None): fail = True break attribute_sections = [] for section_name, section_parts in docs.sections: if section_name is None: continue if ATTRIBUTE_SECTION_NAME_RP.fullmatch(section_name) is None: continue attribute_sections.append(section_name) continue if not attribute_sections: fail = True break best_match_name = None best_match_priority = 100 for attribute_section_name in attribute_sections: priority = CLASS_ATTRIBUTE_SECTION_PRIORITIES.get( attribute_section_name, CLASS_ATTRIBUTE_SECTION_DEFAULT) if priority < best_match_priority: best_match_priority = priority best_match_name = attribute_section_name url_parts[-1] = best_match_name.lower().replace(' ', '-') fail = False break if fail: del url_parts[-2:] url = ''.join(url_parts) if unit is None: preview = None else: preview = unit.preview return order_priority_base + order_priority, name, url, type_, preview
async def __call__(self, key): cache = self.cache try: result = cache[key] except KeyError: pass else: cache.move_to_end(key) return result, False if self.limit.is_active(): return None, True quoted_key = quote(key) active = self.active try: waiters = active[key] except KeyError: pass else: waiter = Future(KOKORO) waiters.append(waiter) return await waiter waiters = [] active[key] = waiters try: async with self.limit.lock: # Check time again, because we may become limited when we get here. if self.limit.is_active(): result = None limited = True else: url = self.query_builder(quoted_key) async with self.http.get( url, headers=GITHUB_HEADERS) as response: self.limit.set(response.headers) if response.status in (200, 404): result_data = await response.json() else: result_data = None result = self.object_type(result_data) if len(cache) == 1000: del cache[next(iter(cache))] cache[key] = result limited = False except BaseException as err: try: del active[key] except KeyError: pass else: for waiter in waiters: waiter.set_exception_if_pending(err) raise err else: try: del active[key] except KeyError: pass else: for waiter in waiters: waiter.set_result_if_pending((result, limited)) return result, limited