# Path: slackclient/slackrequest.py
# class SlackRequest(object):
#     def __init__(self, proxies=None):
# 
#         # __name__ returns 'slackclient.slackrequest', we only want 'slackclient'
#         client_name = __name__.split('.')[0]
#         client_version = __version__  # Version is returned from version.py
# 
#         # Construct the user-agent header with the package info, Python version and OS version.
#         self.default_user_agent = {
#             "client": "{0}/{1}".format(client_name, client_version),
#             "python": "Python/{v.major}.{v.minor}.{v.micro}".format(v=sys.version_info),
#             "system": "{0}/{1}".format(platform.system(), platform.release())
#         }
# 
#         self.custom_user_agent = None
#         self.proxies = proxies
# 
#     def get_user_agent(self):
#         # Check for custom user-agent and append if found
#         if self.custom_user_agent:
#             custom_ua_list = ["/".join(client_info) for client_info in self.custom_user_agent]
#             custom_ua_string = " ".join(custom_ua_list)
#             self.default_user_agent['custom'] = custom_ua_string
# 
#         # Concatenate and format the user-agent string to be passed into request headers
#         ua_string = []
#         for key, val in self.default_user_agent.items():
#             ua_string.append(val)
# 
#         user_agent_string = " ".join(ua_string)
#         return user_agent_string
# 
#     def append_user_agent(self, name, version):
#         if self.custom_user_agent:
#             self.custom_user_agent.append([name.replace("/", ":"), version.replace("/", ":")])
#         else:
#             self.custom_user_agent = [[name, version]]
# 
#     def do(self, token, request="?", post_data=None, domain="slack.com", timeout=None):
#         """
#         Perform a POST request to the Slack Web API
# 
#         Args:
#             token (str): your authentication token
#             request (str): the method to call from the Slack API. For example: 'channels.list'
#             timeout (float): stop waiting for a response after a given number of seconds
#             post_data (dict): key/value arguments to pass for the request. For example:
#                 {'channel': 'CABC12345'}
#             domain (str): if for some reason you want to send your request to something other
#                 than slack.com
#         """
# 
#         # Pull file out so it isn't JSON encoded like normal fields.
#         # Only do this for requests that are UPLOADING files; downloading files
#         # use the 'file' argument to point to a File ID.
#         post_data = post_data or {}
#         upload_requests = ['files.upload']
#         files = None
#         if request in upload_requests:
#             files = {'file': post_data.pop('file')} if 'file' in post_data else None
# 
#         for k, v in six.iteritems(post_data):
#             if not isinstance(v, six.string_types):
#                 post_data[k] = json.dumps(v)
# 
#         url = 'https://{0}/api/{1}'.format(domain, request)
#         post_data['token'] = token
#         headers = {'user-agent': self.get_user_agent()}
# 
#         return requests.post(url,
#                              headers=headers,
#                              data=post_data,
#                              files=files,
#                              timeout=timeout,
#                              proxies=self.proxies)
# 
# Path: slackclient/channel.py
# class Channel(object):
#     '''
#     A Channel represents a public or private Slack Channel instance
#     '''
#     def __init__(self, server, name, channel_id, members=None):
#         self.server = server
#         self.name = name
#         self.id = channel_id
#         self.members = [] if members is None else members
# 
#     def __eq__(self, compare_str):
#         if self.name == compare_str or "#" + self.name == compare_str or self.id == compare_str:
#             return True
#         else:
#             return False
# 
#     def __hash__(self):
#         return hash(self.id)
# 
#     def __str__(self):
#         data = ""
#         for key in list(self.__dict__.keys()):
#             data += "{0} : {1}\n".format(key, str(self.__dict__[key])[:40])
#         return data
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def send_message(self, message, thread=None, reply_broadcast=False):
#         '''
#         Sends a message to a this Channel.
# 
#         Include the parent message's thread_ts value in `thread`
#         to send to a thread.
# 
#         :Args:
#             message (message) - the string you'd like to send to the channel
#             thread (str or None) - the parent message ID, if sending to a
#                 thread
#             reply_broadcast (bool) - if messaging a thread, whether to
#                 also send the message back to the channel
# 
#         :Returns:
#             None
#         '''
#         self.server.rtm_send_message(self.id, message, thread, reply_broadcast)


from .slackrequest import SlackRequest
from requests.packages.urllib3.util.url import parse_url
from .channel import Channel
from .user import User
from .util import SearchList, SearchDict
from ssl import SSLError
from websocket import create_connection
import json



class Server(object):
    '''
    The Server object owns the websocket connection and all attached channel information.


    '''
    def __init__(self, token, connect=True, proxies=None):
        self.token = token
        self.username = None
        self.domain = None
        self.login_data = None
        self.websocket = None
        self.users = SearchDict()
        self.channels = SearchList()
        self.connected = False
        self.ws_url = None
        self.proxies = proxies

# Path: slackclient/slackrequest.py
# class SlackRequest(object):
#     def __init__(self, proxies=None):
# 
#         # __name__ returns 'slackclient.slackrequest', we only want 'slackclient'
#         client_name = __name__.split('.')[0]
#         client_version = __version__  # Version is returned from version.py
# 
#         # Construct the user-agent header with the package info, Python version and OS version.
#         self.default_user_agent = {
#             "client": "{0}/{1}".format(client_name, client_version),
#             "python": "Python/{v.major}.{v.minor}.{v.micro}".format(v=sys.version_info),
#             "system": "{0}/{1}".format(platform.system(), platform.release())
#         }
# 
#         self.custom_user_agent = None
#         self.proxies = proxies
# 
#     def get_user_agent(self):
#         # Check for custom user-agent and append if found
#         if self.custom_user_agent:
#             custom_ua_list = ["/".join(client_info) for client_info in self.custom_user_agent]
#             custom_ua_string = " ".join(custom_ua_list)
#             self.default_user_agent['custom'] = custom_ua_string
# 
#         # Concatenate and format the user-agent string to be passed into request headers
#         ua_string = []
#         for key, val in self.default_user_agent.items():
#             ua_string.append(val)
# 
#         user_agent_string = " ".join(ua_string)
#         return user_agent_string
# 
#     def append_user_agent(self, name, version):
#         if self.custom_user_agent:
#             self.custom_user_agent.append([name.replace("/", ":"), version.replace("/", ":")])
#         else:
#             self.custom_user_agent = [[name, version]]
# 
#     def do(self, token, request="?", post_data=None, domain="slack.com", timeout=None):
#         """
#         Perform a POST request to the Slack Web API
# 
#         Args:
#             token (str): your authentication token
#             request (str): the method to call from the Slack API. For example: 'channels.list'
#             timeout (float): stop waiting for a response after a given number of seconds
#             post_data (dict): key/value arguments to pass for the request. For example:
#                 {'channel': 'CABC12345'}
#             domain (str): if for some reason you want to send your request to something other
#                 than slack.com
#         """
# 
#         # Pull file out so it isn't JSON encoded like normal fields.
#         # Only do this for requests that are UPLOADING files; downloading files
#         # use the 'file' argument to point to a File ID.
#         post_data = post_data or {}
#         upload_requests = ['files.upload']
#         files = None
#         if request in upload_requests:
#             files = {'file': post_data.pop('file')} if 'file' in post_data else None
# 
#         for k, v in six.iteritems(post_data):
#             if not isinstance(v, six.string_types):
#                 post_data[k] = json.dumps(v)
# 
#         url = 'https://{0}/api/{1}'.format(domain, request)
#         post_data['token'] = token
#         headers = {'user-agent': self.get_user_agent()}
# 
#         return requests.post(url,
#                              headers=headers,
#                              data=post_data,
#                              files=files,
#                              timeout=timeout,
#                              proxies=self.proxies)
# 
# Path: slackclient/channel.py
# class Channel(object):
#     '''
#     A Channel represents a public or private Slack Channel instance
#     '''
#     def __init__(self, server, name, channel_id, members=None):
#         self.server = server
#         self.name = name
#         self.id = channel_id
#         self.members = [] if members is None else members
# 
#     def __eq__(self, compare_str):
#         if self.name == compare_str or "#" + self.name == compare_str or self.id == compare_str:
#             return True
#         else:
#             return False
# 
#     def __hash__(self):
#         return hash(self.id)
# 
#     def __str__(self):
#         data = ""
#         for key in list(self.__dict__.keys()):
#             data += "{0} : {1}\n".format(key, str(self.__dict__[key])[:40])
#         return data
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def send_message(self, message, thread=None, reply_broadcast=False):
#         '''
#         Sends a message to a this Channel.
# 
#         Include the parent message's thread_ts value in `thread`
#         to send to a thread.
# 
#         :Args:
#             message (message) - the string you'd like to send to the channel
#             thread (str or None) - the parent message ID, if sending to a
#                 thread
#             reply_broadcast (bool) - if messaging a thread, whether to
#                 also send the message back to the channel
# 
#         :Returns:
#             None
#         '''
#         self.server.rtm_send_message(self.id, message, thread, reply_broadcast)


# Path: slackclient/server.py
from .slackrequest import SlackRequest
from requests.packages.urllib3.util.url import parse_url
from .channel import Channel
from .user import User
from .util import SearchList, SearchDict
from ssl import SSLError
from websocket import create_connection
import json




class Server(object):
    '''
    The Server object owns the websocket connection and all attached channel information.


    '''
    def __init__(self, token, connect=True, proxies=None):
        self.token = token
        self.username = None
        self.domain = None
        self.login_data = None
        self.websocket = None
        self.users = SearchDict()
        self.channels = SearchList()
        self.connected = False
        self.ws_url = None
        self.proxies = proxies

        self.api_requester = SlackRequest(proxies=proxies)