# Path: core/parsers.py
# PREFIX = r'[\w_][\w\d_]*\.'
# 
# Path: core/helpers.py
# def truncate(s, l, ellipsis='…'):
#     """Truncates string to length `l` if need be and adds `ellipsis`.
#     """
#     try:
#         _l = len(s)
#     except:
#         return s
# 
#     if _l > l:
#         try:
#             return s[:l] + ellipsis  # in case s is a byte string
#         except:
#             return s[:l]
#     return s
# 
# def prepend_scheme(url):
#     """Prepend scheme to URL if necessary.
#     """
#     if isinstance(url, str) and len(url.split('://')) == 1:
#         scheme = sublime.load_settings('Requester.sublime-settings').get('scheme', 'http')
#         return scheme + '://' + url
#     return url
# 
# def is_instance(obj, s):
#     """Is object an instance of class named `s`?
#     """
#     return s in str(type(obj))
# 
# def is_auxiliary_view(view):
#     """Was view opened by a Requester command? This is useful, e.g., to
#     avoid resetting `env_file` and `env_string` on these views.
#     """
#     if view.settings().get('requester.response_view', False):
#         return True
#     if view.settings().get('requester.test_view', False):
#         return True
#     return False


import sublime
import re
from urllib import parse
from concurrent import futures
from collections import namedtuple, deque
from ..deps import requests
from .parsers import PREFIX
from .helpers import truncate, prepend_scheme, is_instance, is_auxiliary_view
        from ..commands.download import Download
        from ..commands.upload import Upload
    if 'filename' in kwargs:
        skwargs['filename'] = str(kwargs.pop('filename'))
    if 'streamed' in kwargs:
        skwargs['streamed'] = str(kwargs.pop('streamed'))
    if 'chunked' in kwargs:
        skwargs['chunked'] = str(kwargs.pop('chunked'))

    if 'gql' in kwargs:
        skwargs['gql'] = kwargs.pop('gql')
        gqlargs = {'query': skwargs['gql']}
        if 'gqlv' in kwargs:
            gqlargs['variables'] = kwargs.pop('gqlv')
        if 'gqlo' in kwargs:
            gqlargs['operationName'] = kwargs.pop('gqlo')
        if method == 'GET':
            kwargs['params'] = gqlargs
        if method == 'POST':
            kwargs['json'] = gqlargs

    if 'timeout' not in kwargs:
        kwargs['timeout'] = settings.get('timeout', None)
    if 'allow_redirects' not in kwargs:
        kwargs['allow_redirects'] = settings.get('allow_redirects', True)
    return Request(req, method, url, args, kwargs, ordering, session, skwargs, error)


def prepend_library(req):
    """Makes sure "requests." is prepended to call to requests.
    """
    req = req.strip()

# Path: core/parsers.py
# PREFIX = r'[\w_][\w\d_]*\.'
# 
# Path: core/helpers.py
# def truncate(s, l, ellipsis='…'):
#     """Truncates string to length `l` if need be and adds `ellipsis`.
#     """
#     try:
#         _l = len(s)
#     except:
#         return s
# 
#     if _l > l:
#         try:
#             return s[:l] + ellipsis  # in case s is a byte string
#         except:
#             return s[:l]
#     return s
# 
# def prepend_scheme(url):
#     """Prepend scheme to URL if necessary.
#     """
#     if isinstance(url, str) and len(url.split('://')) == 1:
#         scheme = sublime.load_settings('Requester.sublime-settings').get('scheme', 'http')
#         return scheme + '://' + url
#     return url
# 
# def is_instance(obj, s):
#     """Is object an instance of class named `s`?
#     """
#     return s in str(type(obj))
# 
# def is_auxiliary_view(view):
#     """Was view opened by a Requester command? This is useful, e.g., to
#     avoid resetting `env_file` and `env_string` on these views.
#     """
#     if view.settings().get('requester.response_view', False):
#         return True
#     if view.settings().get('requester.test_view', False):
#         return True
#     return False


# Path: core/responses.py
import sublime
import re
from urllib import parse
from concurrent import futures
from collections import namedtuple, deque
from ..deps import requests
from .parsers import PREFIX
from .helpers import truncate, prepend_scheme, is_instance, is_auxiliary_view
        from ..commands.download import Download
        from ..commands.upload import Upload

    if 'filename' in kwargs:
        skwargs['filename'] = str(kwargs.pop('filename'))
    if 'streamed' in kwargs:
        skwargs['streamed'] = str(kwargs.pop('streamed'))
    if 'chunked' in kwargs:
        skwargs['chunked'] = str(kwargs.pop('chunked'))

    if 'gql' in kwargs:
        skwargs['gql'] = kwargs.pop('gql')
        gqlargs = {'query': skwargs['gql']}
        if 'gqlv' in kwargs:
            gqlargs['variables'] = kwargs.pop('gqlv')
        if 'gqlo' in kwargs:
            gqlargs['operationName'] = kwargs.pop('gqlo')
        if method == 'GET':
            kwargs['params'] = gqlargs
        if method == 'POST':
            kwargs['json'] = gqlargs

    if 'timeout' not in kwargs:
        kwargs['timeout'] = settings.get('timeout', None)
    if 'allow_redirects' not in kwargs:
        kwargs['allow_redirects'] = settings.get('allow_redirects', True)
    return Request(req, method, url, args, kwargs, ordering, session, skwargs, error)


def prepend_library(req):
    """Makes sure "requests." is prepended to call to requests.
    """
    req = req.strip()

    if not re.match(PREFIX, req):