Esempio n. 1
0
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """
        request = RequestFactory().get(path)
        request.path_info = path
        request.META.setdefault('SERVER_PORT', 80)
        request.META.setdefault('SERVER_NAME', self.server_name)

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            raise StaticGeneratorException("The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err)))
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """

        request = self.http_request()
        request.path_info = urllib.unquote(path).decode('utf8')
        request.META.setdefault('SERVER_PORT', self.server_port)
        request.META.setdefault('SERVER_NAME', self.server_name)
        request.method = "GET"
        request.staticgenerator = True

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            #print "The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err))
            #raise StaticGeneratorException("The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err)))
            return None
Esempio n. 3
0
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """

        request = self.http_request()
        # We must parse the path to grab query string
        parsed = urlparse.urlparse(path)
        request.path_info = parsed.path
        request.GET = QueryDict(parsed.query)
        request.REQUEST = request.GET
        request.META.setdefault('SERVER_PORT', 80)
        request.META.setdefault('SERVER_NAME', self.server_name)
        request.META.setdefault('REMOTE_ADDR', '127.0.0.1')

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            raise StaticGeneratorException("The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err)))
Esempio n. 4
0
    if len(sys.argv) > 1 and sys.argv[1] == "test":
        """
        테스팅 플래그가 활성화되어 있는 경우, 정상적인 API 서버 실행 대신에, 
        지정한 테스트 케이스를 실행한다.
        """
        print("Running in testing mode...")

        tcRunner = Tester()
        tcRunner.runTestcases(sys.argv)

        # 테스트 케이스 실행이 끝나면 스크립트를 종료
        exit(0)

app = Flask('SimpleSearchEngine')
handlers = {
    "/": DummyHandler(),
    "/dummy": DummyHandler(),
    "/search": SearchHandler()
}


@app.route('/')
@app.route('/dummy', methods=['GET'])
@app.route('/search', methods=['GET'])
def searchKeyword():
    if request.method == 'GET':

        if len(request.args) > 0:
            res = handlers[request.path].handle(request.args)
        else:
            res = "Keyword is empty"