当前位置: 首页>>代码示例>>Python>>正文


Python URLObject.set_query_param方法代码示例

本文整理汇总了Python中urlobject.URLObject.set_query_param方法的典型用法代码示例。如果您正苦于以下问题:Python URLObject.set_query_param方法的具体用法?Python URLObject.set_query_param怎么用?Python URLObject.set_query_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urlobject.URLObject的用法示例。


在下文中一共展示了URLObject.set_query_param方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_pulls

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def get_pulls(labels=None, state="open", since=None, org=False):
    url = URLObject("https://api.github.com/repos/edx/edx-platform/issues")
    if labels:
        url = url.set_query_param('labels', ",".join(labels))
    if since:
        url = url.set_query_param('since', since.isoformat())
    if state:
        url = url.set_query_param('state', state)
    url = url.set_query_param('sort', 'updated')

    org_fn = None
    if org:
        try:
            with open("mapping.yaml") as fmapping:
                user_mapping = yaml.load(fmapping)
            def_org = "other"
        except IOError:
            user_mapping = {}
            def_org = "---"

        def org_fn(issue):
            return user_mapping.get(issue["user.login"], {}).get("institution", def_org)

    issues = JPullRequest.from_json(paginated_get(url), org_fn)
    if org:
        issues = sorted(issues, key=operator.itemgetter("org"))

    return issues
开发者ID:nedbat,项目名称:jreport,代码行数:30,代码来源:pulls.py

示例2: show_pulls

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def show_pulls(jrep, labels=None, show_comments=False, state="open", since=None, org=False):
    issues = get_pulls(labels, state, since, org)

    category = None
    for index, issue in enumerate(issues):
        issue.finish_loading()
        if issue.get("org") != category:
            # new category! print category header
            category = issue["org"]
            print("-- {category} ----".format(category=category))

        if 0:
            import pprint
            pprint.pprint(issue.obj)
        print(issue.format(ISSUE_FMT))

        if show_comments:
            comments_url = URLObject(issue['comments_url'])
            comments_url = comments_url.set_query_param("sort", "created")
            comments_url = comments_url.set_query_param("direction", "desc")
            comments = paginated_get(comments_url)
            last_five_comments = reversed(more_itertools.take(5, comments))
            for comment in last_five_comments:
                print(comment.format(COMMENT_FMT))

    # index is now set to the total number of pull requests
    print()
    print("{num} pull requests".format(num=index+1))
开发者ID:nedbat,项目名称:jreport,代码行数:30,代码来源:pulls.py

示例3: get_pulls

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def get_pulls(owner_repo, labels=None, state="open", since=None, org=False):
    url = URLObject("https://api.github.com/repos/{}/issues".format(owner_repo))
    if labels:
        url = url.set_query_param('labels', ",".join(labels))
    if since:
        url = url.set_query_param('since', since.isoformat())
    if state:
        url = url.set_query_param('state', state)
    url = url.set_query_param('sort', 'updated')

    org_fn = None
    if org:
        try:
            with open("people.yaml") as fpeople:
                people = yaml.load(fpeople)
            def_org = "other"
        except IOError:
            people = {}
            def_org = "---"

        def org_fn(issue):
            user_info = people.get(issue["user.login"])
            if not user_info:
                user_info = {"institution": "unsigned"}
            return user_info.get("institution", def_org)

    issues = JPullRequest.from_json(paginated_get(url), org_fn)
    if org:
        issues = sorted(issues, key=operator.itemgetter("org"))

    return issues
开发者ID:jeancfo,项目名称:repo-tools,代码行数:33,代码来源:pulls.py

示例4: get_pulls

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def get_pulls(owner_repo, labels=None, state="open", since=None, org=False, pull_details=None):
    """
    Get a bunch of pull requests (actually issues).

    `pull_details` indicates how much information you want from the associated
    pull request document.  None means just issue information is enough. "list"
    means the information available when listing pull requests is enough. "all"
    means you need all the details.  See the GitHub API docs for the difference:
    https://developer.github.com/v3/pulls/

    """
    url = URLObject("https://api.github.com/repos/{}/issues".format(owner_repo))
    if labels:
        url = url.set_query_param('labels', ",".join(labels))
    if since:
        url = url.set_query_param('since', since.isoformat())
    if state:
        url = url.set_query_param('state', state)
    url = url.set_query_param('sort', 'updated')

    org_fn = None
    if org:
        try:
            with open("people.yaml") as fpeople:
                people = yaml.load(fpeople)
            def_org = "other"
        except IOError:
            people = {}
            def_org = "---"

        def org_fn(issue):
            user_info = people.get(issue["user.login"])
            if not user_info:
                user_info = {"institution": "unsigned"}
            return user_info.get("institution", def_org)

    issues = JPullRequest.from_json(paginated_get(url), org_fn)
    if org:
        issues = sorted(issues, key=operator.itemgetter("org"))

    pulls = None
    if pull_details == "list":
        issues = list(issues)
        if issues:
            # Request a bunch of pull details up front, for joining to.  We can't
            # ask for exactly the ones we need, so make a guess.
            limit = int(len(issues) * 1.5)
            pull_url = URLObject("https://api.github.com/repos/{}/pulls".format(owner_repo))
            if state:
                pull_url = pull_url.set_query_param('state', state)
            pulls = { pr['number']: pr for pr in paginated_get(pull_url, limit=limit) }

    for issue in issues:
        if pull_details:
            issue.load_pull_details(pulls=pulls)
        issue['id'] = "{}.{}".format(owner_repo, issue['number'])
        yield issue
开发者ID:IdahoInstitute,项目名称:repo-tools,代码行数:59,代码来源:pulls.py

示例5: url_with_page_number

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
    def url_with_page_number(self, page_number):
        """
        Constructs a url used for getting the next/previous urls
        """
        url = URLObject(self.request.get_full_path())
        url = url.set_query_param('page', str(page_number))

        limit = self.get_limit()
        if limit != self.limit:
            url = url.set_query_param('limit', str(limit))

        return url
开发者ID:cspanring,项目名称:shareabouts-api,代码行数:14,代码来源:mixins.py

示例6: process_url

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def process_url(url, tracking_id):
    amazon_url = URLObject(url)

    amazon_url = amazon_url.with_scheme('https')
    amazon_url = amazon_url.set_query_param('tag', tracking_id)

    return amazon_url
开发者ID:jachin,项目名称:brocket,代码行数:9,代码来源:__init__.py

示例7: jira_group_members

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def jira_group_members(groupname, session=None, start=0, retries=3, debug=False):
    """
    JIRA's group members API is horrible. This makes it easier to use.
    """
    session = session or requests.Session()
    url = URLObject("/rest/api/2/group").set_query_param("groupname", groupname)
    more_results = True
    while more_results:
        end = start + 49  # max 50 users per page
        expand = "users[{start}:{end}]".format(start=start, end=end)
        result_url = url.set_query_param("expand", expand)
        for _ in xrange(retries):
            try:
                if debug:
                    print(result_url, file=sys.stderr)
                result_resp = session.get(result_url)
                result = result_resp.json()
                break
            except ValueError:
                continue
        result_resp.raise_for_status()
        result = result_resp.json()
        if not result:
            break
        users = result["users"]["items"]
        for user in users:
            yield user
        returned = len(users)
        total = result["users"]["size"]
        if start + returned < total:
            start += returned
        else:
            more_results = False
开发者ID:stovar04,项目名称:openedx-webhooks,代码行数:35,代码来源:utils.py

示例8: as_value

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
    def as_value(self, data, context):
        # The queries of the current URL, not using sequences here
        # since the order of sorting arguments matter
        url = URLObject(context['request'].get_full_path())
        queries = url.query.dict

        name, orderings = data['with'], data['by']
        query = self.find_query(queries.get(name), orderings, orderings[0])
        url = url.set_query_param(name, query)

        # If this isn't a block tag we probably only want the URL
        if not self._meta.block:
            return url

        label = self.nodelist.render(context)
        if not label.strip():
            raise TemplateSyntaxError("No label was specified")

        parts = []
        for part in query.split(','):
            part = part.strip()
            if part.startswith('-'):
                part = part.lstrip('-')
                # Translators: Used in title of descending sort fields
                text = _("'%(sort_field)s' (desc)")
            else:
                # Translators: Used in title of ascending sort fields
                text = _("'%(sort_field)s' (asc)")
            parts.append(text % {'sort_field': part})
        # Translators: Used for the link/form input title excluding the sort fields
        title = (_('Sort by: %(sort_fields)s') %
                 {'sort_fields': get_text_list(parts, _('and'))})

        extra_context = dict(data, title=title, label=label, url=url, query=query)
        return render_to_string(self.using(data), extra_context, context)
开发者ID:adamchainz,项目名称:django-sorter,代码行数:37,代码来源:sorter_tags.py

示例9: jira_paginated_get

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def jira_paginated_get(url, obj_name, session=None, start=0, retries=3, **fields):
    """
    Like ``paginated_get``, but uses JIRA's conventions for a paginated API, which
    are different from Github's conventions.
    """
    session = session or requests.Session()
    url = URLObject(url)
    more_results = True
    while more_results:
        result_url = (
            url.set_query_param("startAt", str(start))
               .set_query_params(**fields)
        )
        for _ in xrange(retries):
            try:
                result_resp = session.get(result_url)
                result = result_resp.json()
                break
            except ValueError:
                continue
        if not result_resp.ok:
            raise requests.exceptions.RequestException(result)
        result = result_resp.json()
        for obj in result[obj_name]:
            yield obj
        returned = len(result[obj_name])
        total = result["total"]
        if start + returned < total:
            start += returned
        else:
            more_results = False
开发者ID:dan-f,项目名称:openedx-webhooks,代码行数:33,代码来源:utils.py

示例10: url_with_page_number

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
    def url_with_page_number(self, page_number):
        """
        Constructs a url used for getting the next/previous urls
        """
        if self.request.is_secure():
            protocol = 'https://'
        else:
            protocol = 'http://'
        url = URLObject(protocol+self.request.get_host()+self.request.get_full_path())
        url = url.set_query_param('page', str(page_number))

        limit = self.get_limit()
        if limit != self.limit:
            url = url.set_query_param('limit', str(limit))

        return url
开发者ID:amosson,项目名称:django-rest-framework,代码行数:18,代码来源:mixins.py

示例11: should_transition

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def should_transition(issue):
    """
    Return a boolean indicating if the given issue should be transitioned
    automatically from "Needs Triage" to an open status.
    """
    issue_key = to_unicode(issue["key"])
    issue_status = to_unicode(issue["fields"]["status"]["name"])
    project_key = to_unicode(issue["fields"]["project"]["key"])
    if issue_status != "Needs Triage":
        print(
            "{key} has status {status}, does not need to be processed".format(
                key=issue_key, status=issue_status,
            ),
            file=sys.stderr,
        )
        return False

    # Open source pull requests do not skip Needs Triage.
    # However, if someone creates a subtask on an OSPR issue, that subtasks
    # might skip Needs Triage (it just follows the rest of the logic in this
    # function.)
    is_subtask = issue["fields"]["issuetype"]["subtask"]
    if project_key == "OSPR" and not is_subtask:
        print(
            "{key} is an open source pull request, and does not need to be processed.".format(
                key=issue_key
            ),
            file=sys.stderr,
        )
        return False

    user_url = URLObject(issue["fields"]["creator"]["self"])
    user_url = user_url.set_query_param("expand", "groups")

    user_resp = jira_get(user_url)
    if not user_resp.ok:
        raise requests.exceptions.RequestException(user_resp.text)

    user = user_resp.json()
    user_group_map = {g["name"]: g["self"] for g in user["groups"]["items"]}
    user_groups = set(user_group_map)

    exempt_groups = {
        # group name: set of projects that they can create non-triage issues
        "edx-employees": {"ALL"},
        "clarice": {"MOB"},
        "bnotions": {"MOB"},
        "opencraft": {"SOL"},
    }
    for user_group in user_groups:
        if user_group not in exempt_groups:
            continue
        exempt_projects = exempt_groups[user_group]
        if "ALL" in exempt_projects:
            return True
        if project_key in exempt_projects:
            return True

    return False
开发者ID:sarina,项目名称:openedx-webhooks,代码行数:61,代码来源:jira.py

示例12: get_pulls

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def get_pulls(owner_repo, labels=None, state="open", since=None, org=False, pull_details=None):
    """
    Get a bunch of pull requests (actually issues).

    `pull_details` indicates how much information you want from the associated
    pull request document.  None means just issue information is enough. "list"
    means the information available when listing pull requests is enough. "all"
    means you need all the details.  See the GitHub API docs for the difference:
    https://developer.github.com/v3/pulls/

    """
    url = URLObject("https://api.github.com/repos/{}/issues".format(owner_repo))
    if labels:
        url = url.set_query_param('labels', ",".join(labels))
    if since:
        url = url.set_query_param('since', since.isoformat())
    if state:
        url = url.set_query_param('state', state)
    url = url.set_query_param('sort', 'updated')

    issues = PullRequest.from_json(paginated_get(url))
    if org:
        issues = sorted(issues, key=operator.attrgetter("org"))

    pulls = None
    if pull_details == "list":
        issues = list(issues)
        if issues:
            # Request a bunch of pull details up front, for joining to.  We can't
            # ask for exactly the ones we need, so make a guess.
            limit = int(len(issues) * 1.5)
            pull_url = URLObject("https://api.github.com/repos/{}/pulls".format(owner_repo))
            if state:
                pull_url = pull_url.set_query_param('state', state)
            pulls = { pr['number']: pr for pr in paginated_get(pull_url, limit=limit) }

    for issue in issues:
        if pull_details:
            issue.load_pull_details(pulls=pulls)
        issue.id = "{}.{}".format(owner_repo, issue.number)
        yield issue
开发者ID:edx,项目名称:repo-tools,代码行数:43,代码来源:githubapi.py

示例13: get_duration_info

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def get_duration_info(since=None, labels=None, pull_requests=False):
    labels = labels or []

    url = URLObject("https://api.github.com/repos/edx/edx-platform/issues")
    # we only care about closed PRs for now
    url = url.set_query_param('state', 'closed')
    if labels:
        url = url.set_query_param('labels', ",".join(labels))
    if since:
        url = url.set_query_param('since', since.isoformat())

    counter = defaultdict(list)
    for issue in paginated_get(url):
        if pull_requests and not issue['pull_request']['url']:
            continue
        num = issue['number']
        created_at = iso8601.parse_date(issue["created_at"])
        closed_at = iso8601.parse_date(issue["closed_at"])
        duration = closed_at - created_at
        segment = get_segment(duration)
        counter[segment].append(num)

    return counter
开发者ID:nedbat,项目名称:jreport,代码行数:25,代码来源:timetoclose.py

示例14: jira_paginated_get

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def jira_paginated_get(url, session=None,
                       start=0, start_param="startAt", obj_name=None,
                       retries=3, debug=False, **fields):
    """
    Like ``paginated_get``, but uses JIRA's conventions for a paginated API, which
    are different from Github's conventions.
    """
    session = session or requests.Session()
    url = URLObject(url)
    more_results = True
    while more_results:
        result_url = (
            url.set_query_param(start_param, str(start))
               .set_query_params(**fields)
        )
        for _ in xrange(retries):
            try:
                if debug:
                    print(result_url, file=sys.stderr)
                result_resp = session.get(result_url)
                result = result_resp.json()
                break
            except ValueError:
                continue
        result_resp.raise_for_status()
        result = result_resp.json()
        if not result:
            break
        if obj_name:
            objs = result[obj_name]
        else:
            objs = result
        for obj in objs:
            yield obj
        # are we done yet?
        if isinstance(result, dict):
            returned = len(objs)
            total = result["total"]
            if start + returned < total:
                start += returned
            else:
                more_results = False
        else:
            # `result` is a list
            start += len(result)
            more_results = True  # just keep going until there are no more results.
开发者ID:stovar04,项目名称:openedx-webhooks,代码行数:48,代码来源:utils.py

示例15: add_comma_separated_query_param

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import set_query_param [as 别名]
def add_comma_separated_query_param(url, param_name, value):
    """
    >>> str(add_comma_separated_query_param("http://a.com/a/b/c", "sort", "a"))
    'http://a.com/a/b/c?sort=a'
    >>> str(add_comma_separated_query_param("http://a.com/a/b/c?sort=a", "sort", "b"))
    'http://a.com/a/b/c?sort=a%2Cb'
    >>> str(add_comma_separated_query_param("http://a.com/a/b/c", "sort", ("a", "b")))
    'http://a.com/a/b/c?sort=a%2Cb'
    """
    if not isinstance(url, URL):
        url = URL(url)
    if isinstance(value, (list, tuple)):
        value = ",".join(value)
    existing_sort = url.query_dict.get(param_name, "")
    if existing_sort:
        existing_sort = "{0},".format(existing_sort)

    return url.set_query_param(param_name, "{0}{1}".format(existing_sort, value))
开发者ID:Infinidat,项目名称:infinisdk,代码行数:20,代码来源:query_utils.py


注:本文中的urlobject.URLObject.set_query_param方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。