_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q268900
MattermostClient.user
test
def user(self, user): """Fetch user data.""" entrypoint =
python
{ "resource": "" }
q268901
RSS.fetch
test
def fetch(self, category=CATEGORY_ENTRY): """Fetch the entries from the url. The method retrieves all entries from a RSS url
python
{ "resource": "" }
q268902
RSS.fetch_items
test
def fetch_items(self, category, **kwargs): """Fetch the entries :param category: the category of items to fetch :param kwargs: backend arguments :returns: a generator of items """ logger.info("Looking for rss entries at feed '%s'", self.url) nentries = 0 # number of entries raw_entries = self.client.get_entries()
python
{ "resource": "" }
q268903
RSSCommand.setup_cmd_parser
test
def setup_cmd_parser(cls): """Returns the RSS argument parser.""" parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
python
{ "resource": "" }
q268904
BugzillaREST.fetch
test
def fetch(self, category=CATEGORY_BUG, from_date=DEFAULT_DATETIME): """Fetch the bugs from the repository. The method retrieves, from a Bugzilla repository, the bugs updated since the given date. :param category: the category of items to fetch :param from_date: obtain bugs updated since this date :returns: a
python
{ "resource": "" }
q268905
BugzillaRESTClient.bugs
test
def bugs(self, from_date=DEFAULT_DATETIME, offset=None, max_bugs=MAX_BUGS): """Get the information of a list of bugs. :param from_date: retrieve bugs that where updated from that date; dates are converted to UTC :param offset: starting position for the search; i.e to return 11th element, set this value to 10. :param max_bugs: maximum number of bugs to reteurn per query """ date = datetime_to_utc(from_date) date = date.strftime("%Y-%m-%dT%H:%M:%SZ") params = {
python
{ "resource": "" }
q268906
BugzillaRESTClient.comments
test
def comments(self, *bug_ids): """Get the comments of the given bugs. :param bug_ids: list of bug identifiers """ # Hack. The first value
python
{ "resource": "" }
q268907
BugzillaRESTClient.history
test
def history(self, *bug_ids): """Get the history of the given bugs. :param bug_ids: list of bug identifiers """ resource = urijoin(self.RBUG, bug_ids[0], self.RHISTORY) params = {
python
{ "resource": "" }
q268908
BugzillaRESTClient.attachments
test
def attachments(self, *bug_ids): """Get the attachments of the given bugs. :param bug_id: list of bug identifiers """ resource = urijoin(self.RBUG, bug_ids[0], self.RATTACHMENT) params = { self.PIDS: bug_ids,
python
{ "resource": "" }
q268909
GitLab.__get_issue_notes
test
def __get_issue_notes(self, issue_id): """Get issue notes""" notes = [] group_notes = self.client.notes(GitLabClient.ISSUES, issue_id) for raw_notes in group_notes: for note in json.loads(raw_notes): note_id = note['id']
python
{ "resource": "" }
q268910
GitLab.__fetch_merge_requests
test
def __fetch_merge_requests(self, from_date): """Fetch the merge requests""" merges_groups = self.client.merges(from_date=from_date) for raw_merges in merges_groups: merges = json.loads(raw_merges) for merge in merges: merge_id = merge['iid'] if self.blacklist_ids and merge_id in self.blacklist_ids: logger.warning("Skipping blacklisted merge request %s", merge_id)
python
{ "resource": "" }
q268911
GitLab.__get_merge_notes
test
def __get_merge_notes(self, merge_id): """Get merge notes""" notes = [] group_notes = self.client.notes(GitLabClient.MERGES, merge_id) for raw_notes in group_notes: for note in json.loads(raw_notes): note_id = note['id']
python
{ "resource": "" }
q268912
GitLab.__get_merge_versions
test
def __get_merge_versions(self, merge_id): """Get merge versions""" versions = [] group_versions = self.client.merge_versions(merge_id) for raw_versions in group_versions: for version in json.loads(raw_versions): version_id = version['id']
python
{ "resource": "" }
q268913
GitLabClient.merges
test
def merges(self, from_date=None): """Get the merge requests from pagination""" payload = { 'state': 'all', 'order_by': 'updated_at', 'sort': 'asc', 'view': 'simple',
python
{ "resource": "" }
q268914
GitLabClient.merge
test
def merge(self, merge_id): """Get the merge full data""" path = urijoin(self.base_url,
python
{ "resource": "" }
q268915
GitLabClient.merge_versions
test
def merge_versions(self, merge_id): """Get the merge versions from pagination""" payload = { 'order_by': 'updated_at', 'sort': 'asc', 'per_page': PER_PAGE
python
{ "resource": "" }
q268916
GitLabClient.merge_version
test
def merge_version(self, merge_id, version_id): """Get merge version detail""" path = urijoin(self.base_url,
python
{ "resource": "" }
q268917
GitLabClient.notes
test
def notes(self, item_type, item_id): """Get the notes from pagination""" payload = { 'order_by': 'updated_at', 'sort': 'asc', 'per_page': PER_PAGE
python
{ "resource": "" }
q268918
GitLabClient.emojis
test
def emojis(self, item_type, item_id): """Get emojis from pagination""" payload = { 'order_by': 'updated_at', 'sort': 'asc', 'per_page': PER_PAGE
python
{ "resource": "" }
q268919
GitLabClient.note_emojis
test
def note_emojis(self, item_type, item_id, note_id): """Get emojis of a note""" payload = { 'order_by': 'updated_at', 'sort': 'asc', 'per_page': PER_PAGE }
python
{ "resource": "" }
q268920
GitLabClient.calculate_time_to_reset
test
def calculate_time_to_reset(self): """Calculate the seconds to reset the token requests, by obtaining the different between the current date and the next date when the token is fully regenerated. """
python
{ "resource": "" }
q268921
GitLabClient.fetch_items
test
def fetch_items(self, path, payload): """Return the items from GitLab API using links pagination""" page = 0 # current page last_page = None # last page url_next = urijoin(self.base_url, GitLabClient.PROJECTS, self.owner + '%2F' + self.repository, path) logger.debug("Get GitLab paginated items from " + url_next) response = self.fetch(url_next, payload=payload) items = response.text page += 1 if 'last' in response.links: last_url = response.links['last']['url'] last_page = last_url.split('&page=')[1].split('&')[0] last_page = int(last_page)
python
{ "resource": "" }
q268922
GitLabClient._init_rate_limit
test
def _init_rate_limit(self): """Initialize rate limit information""" url = urijoin(self.base_url, 'projects', self.owner + '%2F' + self.repository) try: response = super().fetch(url) self.update_rate_limit(response) except requests.exceptions.HTTPError as error:
python
{ "resource": "" }
q268923
GitLabCommand.setup_cmd_parser
test
def setup_cmd_parser(cls): """Returns the GitLab argument parser.""" parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES, from_date=True, token_auth=True, archive=True) # GitLab options group = parser.parser.add_argument_group('GitLab arguments') group.add_argument('--enterprise-url', dest='base_url', help="Base URL for GitLab Enterprise instance") group.add_argument('--sleep-for-rate', dest='sleep_for_rate', action='store_true', help="sleep for getting more rate") group.add_argument('--min-rate-to-sleep', dest='min_rate_to_sleep', default=MIN_RATE_LIMIT, type=int, help="sleep until reset when the rate limit \ reaches this value") group.add_argument('--blacklist-ids', dest='blacklist_ids', nargs='*', type=int,
python
{ "resource": "" }
q268924
Slack.fetch
test
def fetch(self, category=CATEGORY_MESSAGE, from_date=DEFAULT_DATETIME): """Fetch the messages from the channel. This method fetches the messages stored on the channel that were sent since the given date. :param category: the category of items to fetch :param from_date: obtain messages sent since this date :returns: a generator of messages """ if not from_date: from_date = DEFAULT_DATETIME
python
{ "resource": "" }
q268925
Slack.metadata_id
test
def metadata_id(item): """Extracts the identifier from a Slack item. This identifier will be the mix of two fields because Slack messages does not have any unique identifier. In this case, 'ts' and 'user' values (or 'bot_id' when the message is sent by a bot) are combined because there have been cases where two messages were sent by
python
{ "resource": "" }
q268926
SlackClient.conversation_members
test
def conversation_members(self, conversation): """Fetch the number of members in a conversation, which is a supertype for public and private ones, DM and group DM. :param conversation: the ID of the conversation """ members = 0 resource = self.RCONVERSATION_INFO params = { self.PCHANNEL: conversation, } raw_response = self._fetch(resource, params) response = json.loads(raw_response)
python
{ "resource": "" }
q268927
SlackClient.channel_info
test
def channel_info(self, channel): """Fetch information about a channel.""" resource = self.RCHANNEL_INFO
python
{ "resource": "" }
q268928
SlackClient.user
test
def user(self, user_id): """Fetch user info.""" resource = self.RUSER_INFO params = { self.PUSER: user_id }
python
{ "resource": "" }
q268929
SlackCommand.setup_cmd_parser
test
def setup_cmd_parser(cls): """Returns the Slack argument parser.""" parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES, from_date=True, token_auth=True, archive=True) # Backend token is required action = parser.parser._option_string_actions['--api-token'] action.required = True # Slack options group = parser.parser.add_argument_group('Slack arguments') group.add_argument('--max-items', dest='max_items',
python
{ "resource": "" }
q268930
Bugzilla.metadata_updated_on
test
def metadata_updated_on(item): """Extracts and coverts the update time from a Bugzilla item. The timestamp is extracted from 'delta_ts' field. This date is converted to UNIX timestamp format. Due Bugzilla servers ignore the timezone on HTTP requests, it will be ignored during the conversion, too.
python
{ "resource": "" }
q268931
Bugzilla.parse_buglist
test
def parse_buglist(raw_csv): """Parse a Bugzilla CSV bug list. The method parses the CSV file and returns an iterator of dictionaries. Each one of this, contains the summary of a bug. :param raw_csv: CSV string to parse :returns: a generator of parsed bugs
python
{ "resource": "" }
q268932
Bugzilla.parse_bugs_details
test
def parse_bugs_details(raw_xml): """Parse a Bugilla bugs details XML stream. This method returns a generator which parses the given XML, producing an iterator of dictionaries. Each dictionary stores the information related to a parsed bug. If the given XML is invalid or does not contains any bug, the method will raise a ParseError exception. :param raw_xml: XML string to parse :returns: a generator of parsed bugs :raises ParseError: raised when an error occurs parsing
python
{ "resource": "" }
q268933
Bugzilla.parse_bug_activity
test
def parse_bug_activity(raw_html): """Parse a Bugzilla bug activity HTML stream. This method extracts the information about activity from the given HTML stream. The bug activity is stored into a HTML table. Each parsed activity event is returned into a dictionary. If the given HTML is invalid, the method will raise a ParseError exception. :param raw_html: HTML string to parse :returns: a generator of parsed activity events :raises ParseError: raised when an error occurs parsing the given HTML stream """ def is_activity_empty(bs): EMPTY_ACTIVITY = "No changes have been made to this (?:bug|issue) yet." tag = bs.find(text=re.compile(EMPTY_ACTIVITY)) return tag is not None def find_activity_table(bs): # The first table with 5 columns is the table of activity tables = bs.find_all('table') for tb in tables: nheaders = len(tb.tr.find_all('th', recursive=False)) if nheaders == 5: return tb raise ParseError(cause="Table of bug activity not found.") def remove_tags(bs): HTML_TAGS_TO_REMOVE = ['a', 'i', 'span'] for tag in bs.find_all(HTML_TAGS_TO_REMOVE): tag.replaceWith(tag.text) def format_text(bs): strings = [s.strip(' \n\t') for s in bs.stripped_strings] s = ' '.join(strings) return s # Parsing starts here bs = bs4.BeautifulSoup(raw_html, 'html.parser') if is_activity_empty(bs): fields = [] else: activity_tb = find_activity_table(bs) remove_tags(activity_tb) fields = activity_tb.find_all('td') while fields: #
python
{ "resource": "" }
q268934
BugzillaClient.logout
test
def logout(self): """Logout from the server.""" params = { self.PLOGOUT: '1' } self.call(self.CGI_LOGIN, params)
python
{ "resource": "" }
q268935
BugzillaClient.metadata
test
def metadata(self): """Get metadata information in XML format.""" params = {
python
{ "resource": "" }
q268936
BugzillaClient.buglist
test
def buglist(self, from_date=DEFAULT_DATETIME): """Get a summary of bugs in CSV format. :param from_date: retrieve bugs that where updated from that date """ if not self.version: self.version = self.__fetch_version() if self.version in self.OLD_STYLE_VERSIONS: order = 'Last+Changed' else: order = 'changeddate' date = from_date.strftime("%Y-%m-%d %H:%M:%S") params = {
python
{ "resource": "" }
q268937
BugzillaClient.bugs
test
def bugs(self, *bug_ids): """Get the information of a list of bugs in XML format. :param bug_ids: list of bug identifiers """ params = { self.PBUG_ID: bug_ids, self.PCTYPE:
python
{ "resource": "" }
q268938
BugzillaClient.bug_activity
test
def bug_activity(self, bug_id): """Get the activity of a bug in HTML format. :param bug_id: bug identifier """ params = { self.PBUG_ID: bug_id
python
{ "resource": "" }
q268939
Meetup.fetch
test
def fetch(self, category=CATEGORY_EVENT, from_date=DEFAULT_DATETIME, to_date=None, filter_classified=False): """Fetch the events from the server. This method fetches those events of a group stored on the server that were updated since the given date. Data comments and rsvps are included within each event. :param category: the category of items to fetch :param from_date: obtain events updated since this date :param to_date: obtain events updated before this date :param filter_classified: remove classified fields from the resulting items :returns: a generator of events """
python
{ "resource": "" }
q268940
Meetup.fetch_items
test
def fetch_items(self, category, **kwargs): """Fetch the events :param category: the category of items to fetch :param kwargs: backend arguments :returns: a generator of items """ from_date = kwargs['from_date'] to_date = kwargs['to_date'] logger.info("Fetching events of '%s' group from %s to %s", self.group, str(from_date), str(to_date) if to_date else '--') to_date_ts = datetime_to_utc(to_date).timestamp() if to_date else None nevents = 0
python
{ "resource": "" }
q268941
MeetupClient.events
test
def events(self, group, from_date=DEFAULT_DATETIME): """Fetch the events pages of a given group.""" date = datetime_to_utc(from_date) date = date.strftime("since:%Y-%m-%dT%H:%M:%S.000Z") resource = urijoin(group, self.REVENTS) # Hack required due to Metup API does not support list # values with the format `?param=value1&param=value2`. # It only works with `?param=value1,value2`. # Morever, urrlib3 encodes comma characters when values # are given using params dict, which it doesn't work # with Meetup, either. fixed_params = '?' + self.PFIELDS + '=' + ','.join(self.VEVENT_FIELDS) fixed_params += '&' + self.PSTATUS + '=' + ','.join(self.VSTATUS) resource += fixed_params
python
{ "resource": "" }
q268942
MeetupClient.comments
test
def comments(self, group, event_id): """Fetch the comments of a given event.""" resource = urijoin(group, self.REVENTS, event_id, self.RCOMMENTS) params = {
python
{ "resource": "" }
q268943
MeetupClient.rsvps
test
def rsvps(self, group, event_id): """Fetch the rsvps of a given event.""" resource = urijoin(group, self.REVENTS, event_id, self.RRSVPS) # Same hack that in 'events' method fixed_params = '?'
python
{ "resource": "" }
q268944
Askbot.__fetch_question
test
def __fetch_question(self, question): """Fetch an Askbot HTML question body. The method fetchs the HTML question retrieving the question body of the item question received :param question: item with the question itself :returns: a list of HTML page/s for the question """ html_question_items = [] npages = 1 next_request = True while next_request: try: html_question = self.client.get_html_question(question['id'], npages) html_question_items.append(html_question)
python
{ "resource": "" }
q268945
Askbot.__fetch_comments
test
def __fetch_comments(self, question): """Fetch all the comments of an Askbot question and answers. The method fetchs the list of every comment existing in a question and its answers. :param question: item with the question itself :returns: a list of comments with the ids as hashes """
python
{ "resource": "" }
q268946
Askbot.__build_question
test
def __build_question(html_question, question, comments): """Build an Askbot HTML response. The method puts together all the information regarding a question :param html_question: array of HTML raw pages :param question: question object from the API :param comments: list of comments to add :returns: a dict item with the parsed question information """ question_object = {} # Parse the user info from the soup container question_container = AskbotParser.parse_question_container(html_question[0]) # Add the info to the question object question_object.update(question_container) # Add the comments of the question (if any) if comments[int(question['id'])]: question_object['comments']
python
{ "resource": "" }
q268947
AskbotClient.get_api_questions
test
def get_api_questions(self, path): """Retrieve a question page using the API. :param page: page to retrieve """ npages = 1 next_request = True path = urijoin(self.base_url, path) while next_request: try: params = { 'page': npages, 'sort': self.ORDER_API } response = self.fetch(path, payload=params) whole_page = response.text raw_questions = json.loads(whole_page) tpages = raw_questions['pages']
python
{ "resource": "" }
q268948
AskbotClient.get_html_question
test
def get_html_question(self, question_id, page=1): """Retrieve a raw HTML question and all it's information. :param question_id: question identifier :param page: page to retrieve """ path = urijoin(self.base_url, self.HTML_QUESTION, question_id) params = {
python
{ "resource": "" }
q268949
AskbotClient.get_comments
test
def get_comments(self, post_id): """Retrieve a list of comments by a given id. :param object_id: object identifiere """ path = urijoin(self.base_url, self.COMMENTS if self._use_new_urls else self.COMMENTS_OLD) params = { 'post_id': post_id, 'post_type': 'answer', 'avatar_size': 0 } headers = {'X-Requested-With': 'XMLHttpRequest'} try: response = self.fetch(path, payload=params, headers=headers) raw = response.text except requests.exceptions.HTTPError as ex: if ex.response.status_code == 404: logger.debug("Comments URL did not work. Using old URL schema.")
python
{ "resource": "" }
q268950
AskbotParser.parse_question_container
test
def parse_question_container(html_question): """Parse the question info container of a given HTML question. The method parses the information available in the question information container. The container can have up to 2 elements: the first one contains the information related with the user who generated the question and the date (if any). The second one contains the date of the updated, and the user who updated it (if not the same who generated the question). :param html_question: raw HTML question element :returns: an object with the parsed information """ container_info = {} bs_question = bs4.BeautifulSoup(html_question, "html.parser") question =
python
{ "resource": "" }
q268951
AskbotParser.parse_answers
test
def parse_answers(html_question): """Parse the answers of a given HTML question. The method parses the answers related with a given HTML question, as well as all the comments related to the answer. :param html_question: raw HTML question element :returns: a list with the answers """ def parse_answer_container(update_info): """Parse the answer info container of a given HTML question. The method parses the information available in the answer information container. The container can have up to 2 elements: the first one contains the information related with the user who generated the question and the date (if any). The second one contains the date of the updated, and the user who updated it (if not the same who generated the question). :param update_info: beautiful soup update_info container element :returns: an object with the parsed information """ container_info = {} created = update_info[0] answered_at = created.abbr.attrs["title"] # Convert date to UNIX timestamp container_info['added_at'] = str(str_to_datetime(answered_at).timestamp()) container_info['answered_by'] = AskbotParser.parse_user_info(created) try: update_info[1] except IndexError: pass else: updated = update_info[1] updated_at = updated.abbr.attrs["title"] # Convert date to UNIX timestamp container_info['updated_at'] = str(str_to_datetime(updated_at).timestamp()) if AskbotParser.parse_user_info(updated): container_info['updated_by'] = AskbotParser.parse_user_info(updated) return container_info answer_list = [] # Select all the answers bs_question = bs4.BeautifulSoup(html_question, "html.parser") bs_answers = bs_question.select("div.answer") for bs_answer in bs_answers: answer_id = bs_answer.attrs["data-post-id"]
python
{ "resource": "" }
q268952
AskbotParser.parse_number_of_html_pages
test
def parse_number_of_html_pages(html_question): """Parse number of answer pages to paginate over them. :param html_question: raw HTML question element :returns: an integer with the number of pages """ bs_question = bs4.BeautifulSoup(html_question, "html.parser") try:
python
{ "resource": "" }
q268953
AskbotParser.parse_user_info
test
def parse_user_info(update_info): """Parse the user information of a given HTML container. The method parses all the available user information in the container. If the class "user-info" exists, the method will get all the available information in the container. If not, if a class "tip" exists, it will be a wiki post with no user associated. Else, it can be an empty container. :param update_info: beautiful soup answer container element :returns: an object with the parsed information """ user_info = {} if update_info.select("div.user-info"): # Get all the <a> elements in the container. First <a> contains the user # information, second one (if exists), the website of the user. elements = update_info.select("div.user-info")[0].find_all("a") href = elements[0].attrs["href"]
python
{ "resource": "" }
q268954
Gerrit.fetch_items
test
def fetch_items(self, category, **kwargs): """Fetch the reviews :param category: the category of items to fetch :param kwargs: backend arguments :returns: a generator of items """ from_date = kwargs['from_date'] if self.client.version[0] == 2 and self.client.version[1] ==
python
{ "resource": "" }
q268955
Gerrit.parse_reviews
test
def parse_reviews(raw_data): """Parse a Gerrit reviews list.""" # Join isolated reviews in JSON in array for parsing items_raw = "[" + raw_data.replace("\n", ",") + "]" items_raw = items_raw.replace(",]", "]") items = json.loads(items_raw) reviews =
python
{ "resource": "" }
q268956
Gerrit._fetch_gerrit28
test
def _fetch_gerrit28(self, from_date=DEFAULT_DATETIME): """ Specific fetch for gerrit 2.8 version. Get open and closed reviews in different queries. Take the newer review from both lists and iterate. """ # Convert date to Unix time from_ut = datetime_to_utc(from_date) from_ut = from_ut.timestamp() filter_open = "status:open" filter_closed = "status:closed" last_item_open = self.client.next_retrieve_group_item() last_item_closed = self.client.next_retrieve_group_item() reviews_open = self._get_reviews(last_item_open, filter_open) reviews_closed = self._get_reviews(last_item_closed, filter_closed) last_nreviews_open = len(reviews_open) last_nreviews_closed = len(reviews_closed) while reviews_open or reviews_closed: if reviews_open and reviews_closed: if reviews_open[0]['lastUpdated'] >= reviews_closed[0]['lastUpdated']:
python
{ "resource": "" }
q268957
GerritClient.version
test
def version(self): """Return the Gerrit server version.""" if self._version: return self._version cmd = self.gerrit_cmd + " %s " % (GerritClient.CMD_VERSION) logger.debug("Getting version: %s" % (cmd)) raw_data = self.__execute(cmd) raw_data = str(raw_data, "UTF-8") logger.debug("Gerrit version: %s" % (raw_data)) # output: gerrit version 2.10-rc1-988-g333a9dd m = re.match(GerritClient.VERSION_REGEX, raw_data) if not m: cause = "Invalid gerrit version %s" % raw_data raise
python
{ "resource": "" }
q268958
GerritClient.reviews
test
def reviews(self, last_item, filter_=None): """Get the reviews starting from last_item.""" cmd = self._get_gerrit_cmd(last_item, filter_) logger.debug("Getting reviews with command: %s", cmd)
python
{ "resource": "" }
q268959
GerritClient.next_retrieve_group_item
test
def next_retrieve_group_item(self, last_item=None, entry=None): """Return the item to start from in next reviews group.""" next_item = None gerrit_version = self.version if gerrit_version[0] == 2 and gerrit_version[1] > 9: if last_item is None: next_item = 0 else: next_item = last_item elif gerrit_version[0] == 2 and gerrit_version[1] == 9: #
python
{ "resource": "" }
q268960
GerritClient.__execute
test
def __execute(self, cmd): """Execute gerrit command""" if self.from_archive: response = self.__execute_from_archive(cmd)
python
{ "resource": "" }
q268961
GerritClient.__execute_from_archive
test
def __execute_from_archive(self, cmd): """Execute gerrit command against the archive""" cmd = self.sanitize_for_archive(cmd) response = self.archive.retrieve(cmd, None, None)
python
{ "resource": "" }
q268962
GerritClient.__execute_from_remote
test
def __execute_from_remote(self, cmd): """Execute gerrit command with retry if it fails""" result = None # data result from the cmd execution retries = 0 while retries < self.MAX_RETRIES: try: result = subprocess.check_output(cmd, shell=True) break except subprocess.CalledProcessError as ex: logger.error("gerrit cmd %s failed: %s", cmd, ex) time.sleep(self.RETRY_WAIT * retries) retries += 1 if
python
{ "resource": "" }
q268963
GerritCommand.setup_cmd_parser
test
def setup_cmd_parser(cls): """Returns the Gerrit argument parser.""" parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES, from_date=True, archive=True) # Gerrit options group = parser.parser.add_argument_group('Gerrit arguments') group.add_argument('--user', dest='user', help="Gerrit ssh user") group.add_argument('--max-reviews', dest='max_reviews',
python
{ "resource": "" }
q268964
Launchpad.__fetch_issue_data
test
def __fetch_issue_data(self, issue_id): """Get data associated to an issue"""
python
{ "resource": "" }
q268965
Launchpad.__fetch_issue_attachments
test
def __fetch_issue_attachments(self, issue_id): """Get attachments of an issue""" for attachments_raw in self.client.issue_collection(issue_id, "attachments"):
python
{ "resource": "" }
q268966
Launchpad.__fetch_issue_messages
test
def __fetch_issue_messages(self, issue_id): """Get messages of an issue""" for messages_raw in self.client.issue_collection(issue_id, "messages"): messages = json.loads(messages_raw) for msg in messages['entries']:
python
{ "resource": "" }
q268967
Launchpad.__fetch_issue_activities
test
def __fetch_issue_activities(self, issue_id): """Get activities on an issue""" for activities_raw in self.client.issue_collection(issue_id, "activity"):
python
{ "resource": "" }
q268968
Launchpad.__fetch_user_data
test
def __fetch_user_data(self, tag_type, user_link): """Get data associated to an user""" user_name = self.client.user_name(user_link) user = {} if not user_name:
python
{ "resource": "" }
q268969
LaunchpadClient.user
test
def user(self, user_name): """Get the user data by URL""" user = None if user_name in self._users: return self._users[user_name] url_user = self.__get_url("~" + user_name) logger.info("Getting info for %s" % (url_user))
python
{ "resource": "" }
q268970
LaunchpadClient.issue
test
def issue(self, issue_id): """Get the issue data by its ID""" path = urijoin("bugs", str(issue_id))
python
{ "resource": "" }
q268971
LaunchpadClient.issue_collection
test
def issue_collection(self, issue_id, collection_name): """Get a collection list of a given issue""" path = urijoin("bugs", str(issue_id), collection_name) url_collection = self.__get_url(path)
python
{ "resource": "" }
q268972
LaunchpadClient.__get_url_project
test
def __get_url_project(self): """Build URL project""" if self.package: url = self.__get_url_distribution_package()
python
{ "resource": "" }
q268973
LaunchpadClient.__fetch_items
test
def __fetch_items(self, path, payload): """Return the items from Launchpad API using pagination""" page = 0 # current page url_next = path fetch_data = True while fetch_data: logger.debug("Fetching page: %i", page) try: raw_content = self.__send_request(url_next, payload) content = json.loads(raw_content) except requests.exceptions.HTTPError as e: if e.response.status_code in [410]: logger.warning("Data is not available - %s", url_next)
python
{ "resource": "" }
q268974
GroupsioClient.subscriptions
test
def subscriptions(self, per_page=PER_PAGE): """Fetch the groupsio paginated subscriptions for a given token :param per_page: number of subscriptions per page :returns: an iterator of subscriptions """ url = urijoin(GROUPSIO_API_URL, self.GET_SUBSCRIPTIONS) logger.debug("Get groupsio paginated subscriptions from " + url) keep_fetching = True payload = { "limit": per_page } while keep_fetching: r = self.__fetch(url, payload)
python
{ "resource": "" }
q268975
GroupsioClient.__find_group_id
test
def __find_group_id(self): """Find the id of a group given its name by iterating on the list of subscriptions""" group_subscriptions = self.subscriptions(self.auth) for subscriptions in group_subscriptions: for sub in subscriptions: if
python
{ "resource": "" }
q268976
GroupsioClient.__fetch
test
def __fetch(self, url, payload): """Fetch requests from groupsio API""" r = requests.get(url, params=payload, auth=self.auth, verify=self.verify) try:
python
{ "resource": "" }
q268977
GroupsioCommand.setup_cmd_parser
test
def setup_cmd_parser(cls): """Returns the Groupsio argument parser.""" parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES, from_date=True, token_auth=True) # Backend token is required action = parser.parser._option_string_actions['--api-token'] action.required = True # Optional arguments group = parser.parser.add_argument_group('Groupsio arguments') group.add_argument('--mboxes-path', dest='mboxes_path', help="Path where mbox files will be stored")
python
{ "resource": "" }
q268978
uuid
test
def uuid(*args): """Generate a UUID based on the given parameters. The UUID will be the SHA1 of the concatenation of the values from the list. The separator bewteedn these values is ':'. Each value must be a non-empty string, otherwise, the function will raise an exception. :param *args: list of arguments used to generate the UUID :returns: a universal unique identifier :raises ValueError: when anyone of the values is not a string, is empty or `None`. """ def check_value(v): if not isinstance(v, str): raise ValueError("%s value is not a
python
{ "resource": "" }
q268979
fetch
test
def fetch(backend_class, backend_args, category, filter_classified=False, manager=None): """Fetch items using the given backend. Generator to get items using the given backend class. When an archive manager is given, this function will store the fetched items in an `Archive`. If an exception is raised, this archive will be removed to avoid corrupted archives. The parameters needed to initialize the `backend` class and get the items are given using `backend_args` dict parameter. :param backend_class: backend class to fetch items :param backend_args: dict of arguments needed to fetch the items :param category: category of the items to retrieve.
python
{ "resource": "" }
q268980
fetch_from_archive
test
def fetch_from_archive(backend_class, backend_args, manager, category, archived_after): """Fetch items from an archive manager. Generator to get the items of a category (previously fetched by the given backend class) from an archive manager. Only those items archived after the given date will be returned. The parameters needed to initialize `backend` and get the items are given using `backend_args` dict parameter. :param backend_class: backend class to retrive items :param backend_args: dict of arguments needed to retrieve the items :param manager: archive manager where the items will be retrieved :param category: category of the items to retrieve :param archived_after: return items archived after this date :returns: a generator of archived items """ init_args = find_signature_parameters(backend_class.__init__,
python
{ "resource": "" }
q268981
find_backends
test
def find_backends(top_package): """Find available backends. Look for the Perceval backends and commands under `top_package` and its sub-packages. When `top_package` defines a namespace, backends under that same namespace will be found too. :param top_package: package storing backends :returns: a tuple with two dicts: one with `Backend` classes and one with `BackendCommand` classes
python
{ "resource": "" }
q268982
Backend.fetch
test
def fetch(self, category, filter_classified=False, **kwargs): """Fetch items from the repository. The method retrieves items from a repository. To removed classified fields from the resulting items, set the parameter `filter_classified`. Take into account this parameter is incompatible with archiving items. Raw client data are archived before any other process. Therefore, classified data are stored within the archive. To prevent from possible data leaks or security issues when users do not need these fields, archiving and filtering are not compatible. :param category: the category of the items fetched :param filter_classified: remove classified fields from the resulting items :param kwargs: a list of other parameters (e.g., from_date, offset, etc. specific for each backend) :returns: a generator of items :raises BackendError: either when the category is not valid or 'filter_classified' and 'archive' are active at the same time. """ if category not in self.categories: cause = "%s category not valid for %s" % (category, self.__class__.__name__) raise
python
{ "resource": "" }
q268983
Backend.fetch_from_archive
test
def fetch_from_archive(self): """Fetch the questions from an archive. It returns the items stored within an archive. If this method is called but no archive was provided, the method will raise a `ArchiveError` exception. :returns: a generator of items :raises ArchiveError: raised when an error occurs accessing an archive """
python
{ "resource": "" }
q268984
Backend.filter_classified_data
test
def filter_classified_data(self, item): """Remove classified or confidential data from an item. It removes those fields that contain data considered as classified. Classified fields are defined in `CLASSIFIED_FIELDS` class attribute. :param item: fields will be removed from this item :returns: the same item but with confidential data filtered """ item_uuid = uuid(self.origin, self.metadata_id(item)) logger.debug("Filtering classified data for item %s", item_uuid) for cf in self.CLASSIFIED_FIELDS: try:
python
{ "resource": "" }
q268985
BackendCommandArgumentParser.parse
test
def parse(self, *args): """Parse a list of arguments. Parse argument strings needed to run a backend command. The result will be a `argparse.Namespace` object populated with the values obtained after the validation of the parameters. :param args: argument strings :result: an object with the parsed values """ parsed_args = self.parser.parse_args(args) # Category was not set, remove it if parsed_args.category is None: delattr(parsed_args, 'category') if self._from_date: parsed_args.from_date = str_to_datetime(parsed_args.from_date) if self._to_date and parsed_args.to_date: parsed_args.to_date = str_to_datetime(parsed_args.to_date) if self._archive and parsed_args.archived_since: parsed_args.archived_since = str_to_datetime(parsed_args.archived_since) if self._archive and parsed_args.fetch_archive and parsed_args.no_archive:
python
{ "resource": "" }
q268986
BackendCommandArgumentParser._set_auth_arguments
test
def _set_auth_arguments(self, basic_auth=True, token_auth=False): """Activate authentication arguments parsing""" group = self.parser.add_argument_group('authentication arguments') if basic_auth: group.add_argument('-u', '--backend-user', dest='user', help="backend user") group.add_argument('-p', '--backend-password', dest='password',
python
{ "resource": "" }
q268987
BackendCommandArgumentParser._set_archive_arguments
test
def _set_archive_arguments(self): """Activate archive arguments parsing""" group = self.parser.add_argument_group('archive arguments') group.add_argument('--archive-path', dest='archive_path', default=None, help="directory path to the archives") group.add_argument('--no-archive', dest='no_archive', action='store_true', help="do not archive data")
python
{ "resource": "" }
q268988
BackendCommandArgumentParser._set_output_arguments
test
def _set_output_arguments(self): """Activate output arguments parsing""" group = self.parser.add_argument_group('output arguments') group.add_argument('-o', '--output', type=argparse.FileType('w'),
python
{ "resource": "" }
q268989
BackendCommand.run
test
def run(self): """Fetch and write items. This method runs the backend to fetch the items from the given origin. Items are converted to JSON objects and written to the defined output. If `fetch-archive` parameter was given as an argument during the inizialization of the instance, the items will be retrieved using the archive manager. """ backend_args = vars(self.parsed_args) category = backend_args.pop('category', None) filter_classified = backend_args.pop('filter_classified', False) archived_since = backend_args.pop('archived_since', None) if self.archive_manager and self.parsed_args.fetch_archive: items = fetch_from_archive(self.BACKEND, backend_args, self.archive_manager, category,
python
{ "resource": "" }
q268990
BackendCommand._initialize_archive
test
def _initialize_archive(self): """Initialize archive based on the parsed parameters""" if 'archive_path' not in self.parsed_args: manager = None elif self.parsed_args.no_archive: manager = None else: if not self.parsed_args.archive_path:
python
{ "resource": "" }
q268991
MBox.metadata_updated_on
test
def metadata_updated_on(item): """Extracts the update time from a MBox item. The timestamp used is extracted from 'Date' field in its several forms. This date is converted to UNIX timestamp format. :param item: item generated by the backend
python
{ "resource": "" }
q268992
MBox.parse_mbox
test
def parse_mbox(filepath): """Parse a mbox file. This method parses a mbox file and returns an iterator of dictionaries. Each one of this contains an email message. :param filepath: path of the mbox to parse :returns : generator of messages; each message is stored in a
python
{ "resource": "" }
q268993
MBox._fetch_and_parse_messages
test
def _fetch_and_parse_messages(self, mailing_list, from_date): """Fetch and parse the messages from a mailing list""" from_date = datetime_to_utc(from_date) nmsgs, imsgs, tmsgs = (0, 0, 0) for mbox in mailing_list.mboxes: tmp_path = None try: tmp_path = self._copy_mbox(mbox) for message in self.parse_mbox(tmp_path): tmsgs += 1 if not self._validate_message(message): imsgs += 1 continue # Ignore those messages sent before the given date dt = str_to_datetime(message[MBox.DATE_FIELD])
python
{ "resource": "" }
q268994
MBox._copy_mbox
test
def _copy_mbox(self, mbox): """Copy the contents of a mbox to a temporary file""" tmp_path = tempfile.mktemp(prefix='perceval_') with mbox.container as f_in:
python
{ "resource": "" }
q268995
MBox._validate_message
test
def _validate_message(self, message): """Check if the given message has the mandatory fields""" # This check is "case insensitive" because we're # using 'CaseInsensitiveDict' from requests.structures # module to store the contents of a message. if self.MESSAGE_ID_FIELD not in message: logger.warning("Field 'Message-ID' not found in message %s; ignoring", message['unixfrom']) return False if not message[self.MESSAGE_ID_FIELD]: logger.warning("Field 'Message-ID' is empty in message %s; ignoring", message['unixfrom']) return False if self.DATE_FIELD not in message: logger.warning("Field 'Date' not found in message %s; ignoring", message['unixfrom']) return False if not message[self.DATE_FIELD]:
python
{ "resource": "" }
q268996
MBox._casedict_to_dict
test
def _casedict_to_dict(self, message): """Convert a message in CaseInsensitiveDict to dict. This method also converts well known problematic headers, such as Message-ID and Date to a common name. """ message_id = message.pop(self.MESSAGE_ID_FIELD) date = message.pop(self.DATE_FIELD)
python
{ "resource": "" }
q268997
_MBox.get_message
test
def get_message(self, key): """Return a Message representation or raise a KeyError.""" start, stop = self._lookup(key) self._file.seek(start) from_line = self._file.readline().replace(mailbox.linesep, b'') string = self._file.read(stop - self._file.tell()) msg = self._message_factory(string.replace(mailbox.linesep, b'\n')) try: msg.set_from(from_line[5:].decode('ascii'))
python
{ "resource": "" }
q268998
Git.fetch
test
def fetch(self, category=CATEGORY_COMMIT, from_date=DEFAULT_DATETIME, to_date=DEFAULT_LAST_DATETIME, branches=None, latest_items=False, no_update=False): """Fetch commits. The method retrieves from a Git repository or a log file a list of commits. Commits are returned in the same order they were obtained. When `from_date` parameter is given it returns items commited since the given date. The list of `branches` is a list of strings, with the names of the branches to fetch. If the list of branches is empty, no commit is fetched. If the list of branches is None, all commits for all branches will be fetched. The parameter `latest_items` returns only those commits which are new since the last time this method was called. The parameter `no_update` returns all commits without performing an update of the repository before. Take into account that `from_date` and `branches` are ignored when the commits are fetched from a Git log file or when `latest_items` flag is set. The class raises a `RepositoryError` exception when an error occurs accessing the repository. :param category: the category of items to fetch :param from_date: obtain commits newer than a specific date (inclusive)
python
{ "resource": "" }
q268999
Git.fetch_items
test
def fetch_items(self, category, **kwargs): """Fetch the commits :param category: the category of items to fetch :param kwargs: backend arguments :returns: a generator of items """ from_date = kwargs['from_date'] to_date = kwargs['to_date'] branches = kwargs['branches'] latest_items = kwargs['latest_items'] no_update = kwargs['no_update'] ncommits = 0 try: if os.path.isfile(self.gitpath): commits = self.__fetch_from_log() else:
python
{ "resource": "" }