# Path: core/utils/network_utils.py
# def get_socket(host, port):
#     s = None
# 
#     addr_info = socket.getaddrinfo(
#         host, port, socket.AF_UNSPEC, socket.SOCK_STREAM
#     )
#     for af, socktype, proto, canonname, sa in addr_info:
#         try:
#             s = socket.socket(af, socktype, proto)
#         except socket.error:
#             s = None
#             continue
#         try:
#             s = socket.create_connection((host, port), timeout=0.1)
#         except socket.error:
#             s.close()
#             s = None
#             continue
#         break
# 
#     return s


import BaseHTTPServer
import copy
import json
import os
import threading
import time
import socket
import unittest
    import httplib
from Queue import Queue, Empty
from mock import Mock, patch, PropertyMock
from nose.twistedtools import reactor
from core.utils.network_utils import get_socket
from twisted.internet.defer import Deferred, TimeoutError
from twisted.python.failure import Failure
        from core.db.models import Provider
        from vmmaster.server import VMMasterServer
def open_url_request(client, session, data):
    return client.post("/wd/hub/session/{}/url".format(session), data=json.dumps(data))


def delete_session_request(client, session):
    return client.delete("/wd/hub/session/%s" % str(session))


def get_session_request(client, session):
    return client.get("/wd/hub/session/{}".format(session))


def run_script(client, session, script):
    return client.post(
        "/wd/hub/session/%s/vmmaster/runScript" % str(session),
        data=json.dumps({"script": script})
    )


def vmmaster_label(client, session, label=None):
    return client.post(
        "/wd/hub/session/%s/vmmaster/vmmasterLabel" % str(session),
        data=json.dumps({"label": label})
    )


def server_is_up(address, wait=5):
    time_start = time.time()
    while time.time() - time_start < wait:
        time.sleep(0.1)

# Path: core/utils/network_utils.py
# def get_socket(host, port):
#     s = None
# 
#     addr_info = socket.getaddrinfo(
#         host, port, socket.AF_UNSPEC, socket.SOCK_STREAM
#     )
#     for af, socktype, proto, canonname, sa in addr_info:
#         try:
#             s = socket.socket(af, socktype, proto)
#         except socket.error:
#             s = None
#             continue
#         try:
#             s = socket.create_connection((host, port), timeout=0.1)
#         except socket.error:
#             s.close()
#             s = None
#             continue
#         break
# 
#     return s


# Path: tests/helpers.py
import BaseHTTPServer
import copy
import json
import os
import threading
import time
import socket
import unittest
    import httplib
from Queue import Queue, Empty
from mock import Mock, patch, PropertyMock
from nose.twistedtools import reactor
from core.utils.network_utils import get_socket
from twisted.internet.defer import Deferred, TimeoutError
from twisted.python.failure import Failure
        from core.db.models import Provider
        from vmmaster.server import VMMasterServer

def open_url_request(client, session, data):
    return client.post("/wd/hub/session/{}/url".format(session), data=json.dumps(data))


def delete_session_request(client, session):
    return client.delete("/wd/hub/session/%s" % str(session))


def get_session_request(client, session):
    return client.get("/wd/hub/session/{}".format(session))


def run_script(client, session, script):
    return client.post(
        "/wd/hub/session/%s/vmmaster/runScript" % str(session),
        data=json.dumps({"script": script})
    )


def vmmaster_label(client, session, label=None):
    return client.post(
        "/wd/hub/session/%s/vmmaster/vmmasterLabel" % str(session),
        data=json.dumps({"label": label})
    )


def server_is_up(address, wait=5):
    time_start = time.time()
    while time.time() - time_start < wait:
        time.sleep(0.1)

        if get_socket(address[0], address[1]):