Esempio n. 1
0
    def start_server(self, host=None, port=None):
        if not port: port = DEFAULT_PORT
        if not host: host = DEFAULT_HOST

        self.address = (host, port)
        self.server = DjangoServer(host, port)
        self.server.start(self.settings)
Esempio n. 2
0
class DjangoHTTPContext(DjangoContext):

    def start_server(self, host=None, port=None):
        if not port: port = DEFAULT_PORT
        if not host: host = DEFAULT_HOST

        self.address = (host, port)
        self.server = DjangoServer(host, port)
        self.server.start(self.settings)

    def __init__(self, parent):
        super(DjangoHTTPContext, self).__init__(parent)
        self.ignore('start_server', 'settings')

    @property
    def host(self):
        if hasattr(self, 'address'):
            return self.address[0]
        return self.find_in_parent('host')

    @property
    def port(self):
        if hasattr(self, 'address'):
            return self.address[1]
        return self.find_in_parent('port')

    def get_url(self, path):
        if re.match('^https?:\/\/', path):
            return path
        return 'http://%s:%d%s' % (self.host, self.port, path)