def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None):
        try:
            curl = commandline.find_binary('curl')
        except commandline.BinaryNotFoundError:
            sublime.error_message("I couldn't find \"curl\" on your system. Curl is required on Linux. Please install it and try again.")
            return

        curl_options = ['-i', '-L', '--user-agent', 'Sublime Github', '-s']
        if auth:
            curl_options.extend(['--user', "%s:%s" % auth])
        if self.verify:
            curl_options.extend(['--cacert', self.verify])
        if headers:
            for k, v in headers.iteritems():
                curl_options.extend(['-H', "%s: %s" % (k, v)])
        if method in ('post', 'patch'):
            curl_options.extend(['-d', data])
        if method == 'patch':
            curl_options.extend(['-X', 'PATCH'])
        if params:
            url += '?' + '&'.join(['='.join([k, str(v)]) for k, v in params.iteritems()])

        command = [curl] + curl_options + [url]

        response = self._build_response(commandline.execute(command))
        response.url = url
        return response
    def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None):
        curl = commandline.find_binary("curl")
        curl_options = ["-i", "-L", "-f", "--user-agent", "Sublime Github", "-s"]
        if auth:
            curl_options.extend(["--user", "%s:%s" % auth])
        if self.verify:
            curl_options.extend(["--cacert", self.verify])
        if headers:
            for k, v in headers.iteritems():
                curl_options.extend(["-H", "%s: %s" % (k, v)])
        if method in ("post", "patch"):
            curl_options.extend(["-d", data])
        if method == "patch":
            curl_options.extend(["-X", "PATCH"])
        if params:
            url += "?" + "&".join(["=".join([k, str(v)]) for k, v in params.iteritems()])

        command = [curl] + curl_options + [url]

        try:
            response = self._build_response(commandline.execute(command))
            response.url = url
            return response
        except commandline.NonCleanExitError, e:
            error_string = ""
            if e.returncode == 22:
                error_string = "HTTP error 404"
            elif e.returncode == 6:
                error_string = "URL error host not found"
            else:
                print "%s: Downloading %s timed out, trying again" % (__name__, url)

            raise self.CurlException("%s: %s %s %s %s" % (__name__, e, error_string, method, url))
예제 #3
0
    def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None, proxies=None):
        try:
            curl = commandline.find_binary('curl')
        except commandline.BinaryNotFoundError:
            sublime.error_message("I couldn't find \"curl\" on your system. Curl is required on Linux. Please install it and try again.")
            return

        curl_options = ['-i', '-L', '--user-agent', 'Sublime Github', '-s']
        if auth:
            curl_options.extend(['--user', "%s:%s" % auth])
        if self.verify:
            curl_options.extend(['--cacert', self.verify])
        if headers:
            for k, v in headers.iteritems():
                curl_options.extend(['-H', "%s: %s" % (k, v)])
        if method in ('post', 'patch'):
            curl_options.extend(['-d', data])
        if method == 'patch':
            curl_options.extend(['-X', 'PATCH'])
        if params:
            url += '?' + '&'.join(['='.join([k, str(v)]) for k, v in params.iteritems()])
        if proxies and proxies.get('https', None) :
            curl_options.extend(['-x', proxies['https']])

        command = [curl] + curl_options + [url]

        logger.debug("CurlSession: invoking curl with %s" % command)
        try:
            command_response = commandline.execute(command)
        except commandline.CommandExecutionError, e:
            logger.error("Curl execution: %s" % repr(e))
            self._handle_curl_error(e.errorcode)
            return
예제 #4
0
    def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None):
        curl = commandline.find_binary('curl')
        curl_options = ['-i', '-L', '-f', '--user-agent', 'Sublime Github', '-s']
        if auth:
            curl_options.extend(['--user', "%s:%s" % auth])
        if self.verify:
            curl_options.extend(['--cacert', self.verify])
        if headers:
            for k, v in headers.iteritems():
                curl_options.extend(['-H', "%s: %s" % (k, v)])
        if method in ('post', 'patch'):
            curl_options.extend(['-d', data])
        if method == 'patch':
            curl_options.extend(['-X', 'PATCH'])
        if params:
            url += '?' + '&'.join(['='.join([k, str(v)]) for k, v in params.iteritems()])

        command = [curl] + curl_options + [url]

        try:
            response = self._build_response(commandline.execute(command))
            response.url = url
            return response
        except commandline.NonCleanExitError, e:
            error_string = ''
            if e.returncode == 22:
                error_string = 'HTTP error 404'
            elif e.returncode == 6:
                error_string = 'URL error host not found'
            else:
                print "%s: Downloading %s timed out, trying again" % (__name__, url)

            raise self.CurlException("%s: %s %s %s %s" % (__name__, e, error_string, method, url))
예제 #5
0
    def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None):
        try:
            curl = commandline.find_binary('curl')
        except commandline.BinaryNotFoundError:
            sublime.error_message("I couldn't find \"curl\" on your system. Curl is required on Linux. Please install it and try again.")
            return

        curl_options = ['-i', '-L', '--user-agent', 'Sublime Github', '-s']
        if auth:
            curl_options.extend(['--user', "%s:%s" % auth])
        if self.verify:
            curl_options.extend(['--cacert', self.verify])
        if headers:
            for k, v in headers.iteritems():
                curl_options.extend(['-H', "%s: %s" % (k, v)])
        if method in ('post', 'patch'):
            curl_options.extend(['-d', data])
        if method == 'patch':
            curl_options.extend(['-X', 'PATCH'])
        if params:
            url += '?' + '&'.join(['='.join([k, str(v)]) for k, v in params.iteritems()])

        command = [curl] + curl_options + [url]

        response = self._build_response(commandline.execute(command))
        response.url = url
        return response
예제 #6
0
    def request(self,
                method,
                url,
                headers=None,
                params=None,
                data=None,
                auth=None,
                allow_redirects=False,
                config=None,
                proxies=None):
        try:
            curl = commandline.find_binary('curl')
        except commandline.BinaryNotFoundError:
            sublime.error_message(
                "I couldn't find \"curl\" on your system. Curl is required on Linux. Please install it and try again."
            )
            return

        curl_options = ['-i', '-L', '--user-agent', 'Sublime Trello', '-s']
        if auth:
            curl_options.extend(['--user', "%s:%s" % auth])
        if self.verify:
            curl_options.extend(['--cacert', self.verify])
        if headers:
            for k, v in headers.items():
                curl_options.extend(['-H', "%s: %s" % (k, v)])

        if method.lower() in ('post', 'patch', 'put') and not data is None:
            curl_options.extend(['-d', data])

        curl_options.extend(['-X', method.upper()])

        if params:
            url += '?' + '&'.join(
                ['='.join([k, str(v)]) for k, v in params.items()])
        if proxies and proxies.get('https', None):
            curl_options.extend(['-x', proxies['https']])

        command = [curl] + curl_options + [url]

        logger.debug("CurlSession: invoking curl with %s" % command)

        try:
            command_response = commandline.execute(command)
        except commandline.CommandExecutionError as e:
            logger.error("Curl execution: %s" % repr(e))
            self._handle_curl_error(e.errorcode)
            return

        response = self._build_response(command_response)
        response.url = url
        return response
예제 #7
0
def post(url, data, header):
    curl = commandline.find_binary("curl")
    if not curl:
        return False
    command = [curl, "-f", "--user-agent", "Sublime Github", "-s", "-3", "--insecure"]
    if data:
        command.append("-d")
        command.append(data)
    for k, v in header.iteritems():
        command.append("-H")
        command.append("%s: %s" % (k, v))
    command.append(url)

    print command

    return commandline.execute(command)
예제 #8
0
    def on_post_save(self, view):
        try:
            lessc = commandline.find_binary("lessc")
        except commandline.BinaryNotFoundError:
            sublime.error_message(
                'I couldn\'t find "less" binary on your system. Less is required on your system. Please install it and try again.'
            )
            return

        if not view.file_name().endswith(".less"):
            return

        filename = view.file_name()
        output_filename = filename.replace(".less", ".css")

        command = [lessc] + [filename]
        output = commandline.execute(command)

        output_file = open(output_filename, "w")
        output_file.write(output)
        output_file.close()
예제 #9
0
def post(url, data, tries=3):
    curl = commandline.find_binary('curl')
    command = [curl, '-f', '--user-agent', 'Sublime Github', '-s',
               '-d', data, url]

    while tries > 1:
        tries -= 1
        try:
            return commandline.execute(command)
        except (commandline.NonCleanExitError) as (e):
            if e.returncode == 22:
                error_string = 'HTTP error 404'
            elif e.returncode == 6:
                error_string = 'URL error host not found'
            else:
                print "%s: Downloading %s timed out, trying again" % (__name__, url)
                continue

            sublime.error_message("%s: %s %s posting %s ." %
                                  (__name__, error_message, error_string, url))
        break
    return False