# 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

class ResponseThreadPool:
    """Allows requests to be invoked concurrently, and allows client code to
    inspect instance's responses as they are returned.
    """
    def get_response(self, request, ordering):
        """Calls request with specified args and kwargs parsed from request
        string.

        Also sets "Response" key in env to `Response` object, to provide true
        "chaining" of requests. If two requests are run serially, the second
        request can reference the response returned by the previous request.
        """
        if isinstance(request, Request):  # no need to prepare request
            req = request._replace(ordering=ordering)
        else:
            req = prepare_request(request, self.env, ordering, self.view)
        if req.error is not None:
            return Response(req, None, None)

        if self.handle_special(req):
            return Response(req, None, 'skwarg')  # "special" requests handled separately
        self.pending_requests.add(req)
        res, err = None, ''
        if self.is_done:  # prevents further requests from being made if pool is cancelled
            return Response(req, res, err)  # check using: https://requestb.in/

        try:
            if req.session:
                session = self.env.get(req.session)

# 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


class ResponseThreadPool:
    """Allows requests to be invoked concurrently, and allows client code to
    inspect instance's responses as they are returned.
    """
    def get_response(self, request, ordering):
        """Calls request with specified args and kwargs parsed from request
        string.

        Also sets "Response" key in env to `Response` object, to provide true
        "chaining" of requests. If two requests are run serially, the second
        request can reference the response returned by the previous request.
        """
        if isinstance(request, Request):  # no need to prepare request
            req = request._replace(ordering=ordering)
        else:
            req = prepare_request(request, self.env, ordering, self.view)
        if req.error is not None:
            return Response(req, None, None)

        if self.handle_special(req):
            return Response(req, None, 'skwarg')  # "special" requests handled separately
        self.pending_requests.add(req)
        res, err = None, ''
        if self.is_done:  # prevents further requests from being made if pool is cancelled
            return Response(req, res, err)  # check using: https://requestb.in/

        try:
            if req.session:
                session = self.env.get(req.session)

                if is_instance(session, 'requests.sessions.Session'):