예제 #1
0
 def do_GET(self):
     ''' Present frontpage with user authentication. '''
     if self.headers.get('Authorization') is None:
         self.do_authhead()
         self.wfile.write(b'no auth header received')
     elif self.headers.get('Authorization') == 'Basic ' + self.KEY:
         #SimpleHTTPRequestHandler.do_GET(self)
         CGIHTTPRequestHandler.do_GET(self)
     else:
         self.do_authhead()
         self.wfile.write(self.headers.get('Authorization'))
         self.wfile.write('not authenticated')
예제 #2
0
 def do_GET(self):
     current_dir = os.getcwd()
     target = os.path.join(current_dir, self.path[1:])
     # Debug
     print('Path:', self.path)
     print('Could be:', target)
     # File requested?
     if os.path.isfile(target):
         # CGI script requested?
         if os.path.splitext(target)[1] == '.py':
             CGIHTTPRequestHandler.do_GET(self)
             return
         # no CGI
         else:
             self.serve_file(target)
     # no file
     else:
         self.serve_default()
예제 #3
0
    def do_GET(self):
        if self.path == '/table/':  # Обрабатываем, действия, происходящие при переходе по пути /table/
            template = '''  
                <tr>
                    <td>{}</td>
                    <td>{}</td>
                    <td>{}</td>
                    <td>{}</td>
                    <td>{}</td>
                    <td>{}</td>
                    <td>{}</td>
                </tr>
            '''  # Шаблон строки таблицы
            tbody = ''  # Здесь будут все строки таблицы peoples
            cursor = db.cursor()  # Создаем курсор перед выполением запроса
            cursor.execute('''
                SELECT p.surname, p.name, p.patronymic, r.region, c.city, p.telephone, p.email FROM peoples p
                JOIN regions r ON p.regionId = r.id
                JOIN cities c ON (p.cityId=c.id AND p.regionId = c.regionId)            
            ''')  # Выполняем запрос SQL
            peoples = cursor.fetchall()  # Забираем все найденные данные
            for person in peoples:
                tbody += template.format(
                    *person
                )  # Постепенно заполняем tbody, подставляя в шаблон строки полученные с запроса данные

            table = open('peoples.html', encoding='utf-8').readlines(
            )  # Считываем html файл, который сдержит в себе саму таблицу с шапкой, но пока без тела
            table = ('%s' * len(table) % tuple(table)).format(
                tbody
            )  # подставляем полученное тело таблицы tbody в таблицу, считанную из html файла
            self.send_response(200)  # ответ get запроса (ОК)
            self.send_header("Content-type",
                             "text/html")  # Тип получаемых данных - html
            self.end_headers()  # конец заголовка ответа get запроса
            self.wfile.write(
                table.encode('cp1251')
            )  # Записываем тело ответа get запроса (это весь сформированный выше html файл с таблицей)
        else:
            CGIHTTPRequestHandler.do_GET(
                self
            )  # Если пользователь перешел не по /table/, то изменений нет
예제 #4
0
 def do_GET(self):
     CGIHTTPRequestHandler.do_GET(self)
     print("do_GET, path: %s %s" % (self.path, self.client_address[0]))
     pass
예제 #5
0
 def do_GET(self):
     CGIHTTPRequestHandler.do_GET(self)
     if self.path == '/quit.html':
         quit()
예제 #6
0
 def do_GET(self):
     CGIHTTPRequestHandler.do_GET(self)