Esempio n. 1
0
def reviews_pastehtml_upload(source, input_type="html"):
    """
    Uploads 'source' as an 'input_type' type to pastehtml.com.

    source ....... source of the webpage/text
    input_type ... txt or html (default html)

    """
    url = "http://pastehtml.com/upload/create?input_type=%s&result=address"
    request = urllib2.Request(url % input_type, data=urlencode([("txt", source)]))

    result = keep_trying(lambda: urllib2.urlopen(request), urllib2.URLError, "access pastehtml.com")

    s = result.read()
    # There is a bug at pastehtml.com, that sometimes it returns:
    # http://pastehtml.comhttp://pastehtml.com/view/1eddmnp.html
    # instead of:
    # http://pastehtml.com/view/1eddmnp.html
    # So we check if this is the case, and correct it:
    if s.find("http", 2) != -1:
        s = s[s.find("http", 2):]
    return s
Esempio n. 2
0
def reviews_pastehtml_upload(source, input_type="html"):
    """
    Uploads 'source' as an 'input_type' type to pastehtml.com.

    source ....... source of the webpage/text
    input_type ... txt or html (default html)

    """
    url = "http://pastehtml.com/upload/create?input_type=%s&result=address"
    request = urllib2.Request(url % input_type, data=urlencode([("txt", source)]))

    result = keep_trying(lambda: urllib2.urlopen(request), urllib2.URLError, "access pastehtml.com")

    s = result.read()
    # There is a bug at pastehtml.com, that sometimes it returns:
    # http://pastehtml.comhttp://pastehtml.com/view/1eddmnp.html
    # instead of:
    # http://pastehtml.com/view/1eddmnp.html
    # So we check if this is the case, and correct it:
    if s.find("http", 2) != -1:
        s = s[s.find("http", 2):]
    return s
Esempio n. 3
0
def reviews_sympy_org_upload(data, url_base):
    def _do_upload():
        s = JSONRPCService(url_base + "/async")
        r = s.RPC.upload_task(data["num"], data["result"],
                data["interpreter"], data["testcommand"], data["log"])
        if "task_url" not in r:
            # This happens for example when the server is over quota, see
            # https://github.com/sympy/sympy-bot/issues/110

            # Note that this exact error message is checked below, in case
            # something else raises a ValueError
            raise urllib2.URLError("Quota")

        return r

    def _handler(e):
        if e.message == "Quota":
            print "Server appears to be over quota."

    r = keep_trying(_do_upload, urllib2.URLError, "access %s" %
                    url_base, _handler)

    return r["task_url"]
Esempio n. 4
0
def github_get_pull_request(urls, n):
    """
    Returns pull request 'n'.
    """
    url = urls.single_pull_template % n
    issue_url = urls.single_issue_template % n

    def _check_issue(e):
        """
        It's possible the "pull request" is really an issue. If it is, the
        issue url will exist.
        """
        try:
            issue = _query(issue_url)
        except urllib2.URLError:
            pass
        else:
            print ("Pull request %d appears to be an issue "
                   "(no code is attached). Skipping..." % n)
            return False

    return keep_trying(lambda: _query(url), urllib2.URLError,
                       "get pull request %d" % n, _check_issue)
Esempio n. 5
0
def reviews_sympy_org_upload(data, url_base):
    def _do_upload():
        s = JSONRPCService(url_base + "/async")
        r = s.RPC.upload_task(data["num"], data["result"],
                data["interpreter"], data["testcommand"], data["log"])
        if "task_url" not in r:
            # This happens for example when the server is over quota, see
            # https://github.com/sympy/sympy-bot/issues/110

            # Note that this exact error message is checked below, in case
            # something else raises a ValueError
            raise urllib2.URLError("Quota")

        return r

    def _handler(e):
        if e.message == "Quota":
            print "Server appears to be over quota."

    r = keep_trying(_do_upload, urllib2.URLError, "access %s" %
                    url_base, _handler)

    return r["task_url"]
Esempio n. 6
0
def github_get_pull_request(urls, n):
    """
    Returns pull request 'n'.
    """
    url = urls.single_pull_template % n
    issue_url = urls.single_issue_template % n

    def _check_issue(e):
        """
        It's possible the "pull request" is really an issue. If it is, the
        issue url will exist.
        """
        try:
            issue = _query(issue_url)
        except urllib2.URLError:
            pass
        else:
            print ("Pull request %d appears to be an issue "
                   "(no code is attached). Skipping..." % n)
            return False

    return keep_trying(lambda: _query(url), urllib2.URLError,
                       "get pull request %d" % n, _check_issue)
Esempio n. 7
0
def github_get_user_repos(urls, username):
    url = urls.user_repos_template % username
    return keep_trying(lambda: _query(url), urllib2.URLError, "get user repository information")
Esempio n. 8
0
def github_get_pull_request_all(urls):
    """
    Returns all github pull requests.
    """
    return keep_trying(lambda: _query(urls.pull_list_url), urllib2.URLError,
                       "get list of all pull requests")
Esempio n. 9
0
def github_get_user_repos(urls, username):
    url = urls.user_repos_template % username
    return keep_trying(lambda: _query(url), urllib2.URLError, "get user repository information")
Esempio n. 10
0
def github_get_pull_request_all(urls):
    """
    Returns all github pull requests.
    """
    return keep_trying(lambda: _query(urls.pull_list_url), urllib2.URLError,
                       "get list of all pull requests")