# Path: wdom/parser.py
# def parse_html(html: str, parser: FragmentParser = None) -> Node:
#     """Parse HTML fragment and return DocumentFragment object.
# 
#     DocumentFragment object has parsed Node objects as its child nodes.
#     """
#     parser = parser or FragmentParser()
#     parser.feed(html)
#     return parser.root
# 
# Path: wdom/server/_tornado.py
# def is_connected() -> bool:
#     def get(self) -> None:
#     def open(self) -> None:
#     def on_message(self, message: str) -> None:
#     async def terminate(self) -> None:
#     def on_close(self) -> None:
#     def set_extra_headers(self, path: str) -> None:
#     def __init__(self, *args: Any, **kwargs: Any) -> None:
#     def log_request(self, handler: web.RequestHandler) -> None:
#     def add_static_path(self, prefix: str, path: str) -> None:
#     def add_favicon_path(self, path: str) -> None:
# def get_app(*args: Any, **kwargs: Any) -> Application:
# def set_application(app: Application) -> None:
# def start_server(app: web.Application = None, port: int = None,
#                  address: str = None, **kwargs: Any) -> HTTPServer:
# def stop_server(server: HTTPServer) -> None:
# class MainHandler(web.RequestHandler):
# class WSHandler(websocket.WebSocketHandler):
# class StaticFileHandlerNoCache(web.StaticFileHandler):
# class Application(web.Application):


from cProfile import Profile
from pstats import Stats
from pathlib import Path
from wdom.parser import parse_html
from wdom.server import _tornado
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



# fake connection
_tornado.connections.append(1)  # type: ignore

root = Path(__file__).absolute().parent.parent
html_file = root / 'docs/_build/html/node.html'
with open(html_file) as f:
    real_html = f.read()

src = '<div>' + '''
  <div a="1">
    <span b="2">text</span>
    <span b="2">text</span>
    <span b="2">text</span>
    <span b="2">text</span>
  </div>
''' * 1000 + '</div>'

if __name__ == '__main__':
    profiler = Profile()
    # profiler.runcall(parse_html, real_html)

# Path: wdom/parser.py
# def parse_html(html: str, parser: FragmentParser = None) -> Node:
#     """Parse HTML fragment and return DocumentFragment object.
# 
#     DocumentFragment object has parsed Node objects as its child nodes.
#     """
#     parser = parser or FragmentParser()
#     parser.feed(html)
#     return parser.root
# 
# Path: wdom/server/_tornado.py
# def is_connected() -> bool:
#     def get(self) -> None:
#     def open(self) -> None:
#     def on_message(self, message: str) -> None:
#     async def terminate(self) -> None:
#     def on_close(self) -> None:
#     def set_extra_headers(self, path: str) -> None:
#     def __init__(self, *args: Any, **kwargs: Any) -> None:
#     def log_request(self, handler: web.RequestHandler) -> None:
#     def add_static_path(self, prefix: str, path: str) -> None:
#     def add_favicon_path(self, path: str) -> None:
# def get_app(*args: Any, **kwargs: Any) -> Application:
# def set_application(app: Application) -> None:
# def start_server(app: web.Application = None, port: int = None,
#                  address: str = None, **kwargs: Any) -> HTTPServer:
# def stop_server(server: HTTPServer) -> None:
# class MainHandler(web.RequestHandler):
# class WSHandler(websocket.WebSocketHandler):
# class StaticFileHandlerNoCache(web.StaticFileHandler):
# class Application(web.Application):


# Path: profile/parser.py
from cProfile import Profile
from pstats import Stats
from pathlib import Path
from wdom.parser import parse_html
from wdom.server import _tornado

#!/usr/bin/env python3
# -*- coding: utf-8 -*-



# fake connection
_tornado.connections.append(1)  # type: ignore

root = Path(__file__).absolute().parent.parent
html_file = root / 'docs/_build/html/node.html'
with open(html_file) as f:
    real_html = f.read()

src = '<div>' + '''
  <div a="1">
    <span b="2">text</span>
    <span b="2">text</span>
    <span b="2">text</span>
    <span b="2">text</span>
  </div>
''' * 1000 + '</div>'

if __name__ == '__main__':
    profiler = Profile()
    # profiler.runcall(parse_html, real_html)

    profiler.runcall(parse_html, src)  # ~1.7 sec