# Path: webalchemy/saferef.py
# def safeRef(target, onDelete=None):
#     """Return a *safe* weak reference to a callable target
# 
#     target -- the object to be weakly referenced, if it's a
#         bound method reference, will create a BoundMethodWeakref,
#         otherwise creates a simple weakref.
#     onDelete -- if provided, will have a hard reference stored
#         to the callable to be called after the safe reference
#         goes out of scope with the reference object, (either a
#         weakref or a BoundMethodWeakref) as argument.
#     """
#     if hasattr(target, '__self__'):
#         if target.__self__ is not None:
#             # Turn a bound method into a BoundMethodWeakref instance.
#             # Keep track of these instances for lookup by disconnect().
#             assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference""" % (target,)
#             reference = get_bound_method_weakref(
#                 target=target,
#                 onDelete=onDelete
#             )
#             return reference
#     if callable(onDelete):
#         return weakref.ref(target, onDelete)
#     else:
#         return weakref.ref(target)
# 
# Path: webalchemy/htmlparser.py
# def get_element_ids(html):
#     ids = []
# 
#     class MyHTMLParser(HTMLParser):
#         def handle_starttag(self, tag, attrs):
#             for attr in attrs:
#                 if attr[0] == 'id':
#                     ids.append(attr[1])
#     parser = MyHTMLParser()
#     parser.feed(html)
#     return ids


import re
import random
import inspect
import logging
from ast import parse
from types import FunctionType
from inspect import getsource
from textwrap import dedent
from pythonium.veloce.veloce import Veloce
from webalchemy.saferef import safeRef
from webalchemy.htmlparser import get_element_ids
        self.rdoc.inline(js)
        self.style = StyleAtt(self.rdoc, self.varname)
        self.style(**kwargs)


class RemoteDocument:
    # TODO: remove block altogether...
    def __init__(self):
        self.varname = 'document'
        self.__uid_count = 0
        self.__code_strings = []
        self.__block_ixs = []
        self.__varname_element_dict = {}
        self.body = Element(self, 'body', '', customvarname='document.body')
        self.head = Element(self, 'head', '', customvarname='document.head')
        self.pop_all_code()  # body and head are special: created by static content
        self.app = SimpleProp(self, 'document', 'app', create=True)
        self.props = SimpleProp(self, 'document')
        self.localStorage = SimpleProp(self, 'localStorage')
        self.sessionStorage = SimpleProp(self, 'localStorage')
        self.stylesheet = _StyleSheet(self)
        self.vendor_prefix = None
        self.jsrpcweakrefs = {}
        self.window = Window(self)
        self.KeyCode = KeyCode

    def parse_elements(self, html):
        class E:
            pass
        e = E()

# Path: webalchemy/saferef.py
# def safeRef(target, onDelete=None):
#     """Return a *safe* weak reference to a callable target
# 
#     target -- the object to be weakly referenced, if it's a
#         bound method reference, will create a BoundMethodWeakref,
#         otherwise creates a simple weakref.
#     onDelete -- if provided, will have a hard reference stored
#         to the callable to be called after the safe reference
#         goes out of scope with the reference object, (either a
#         weakref or a BoundMethodWeakref) as argument.
#     """
#     if hasattr(target, '__self__'):
#         if target.__self__ is not None:
#             # Turn a bound method into a BoundMethodWeakref instance.
#             # Keep track of these instances for lookup by disconnect().
#             assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference""" % (target,)
#             reference = get_bound_method_weakref(
#                 target=target,
#                 onDelete=onDelete
#             )
#             return reference
#     if callable(onDelete):
#         return weakref.ref(target, onDelete)
#     else:
#         return weakref.ref(target)
# 
# Path: webalchemy/htmlparser.py
# def get_element_ids(html):
#     ids = []
# 
#     class MyHTMLParser(HTMLParser):
#         def handle_starttag(self, tag, attrs):
#             for attr in attrs:
#                 if attr[0] == 'id':
#                     ids.append(attr[1])
#     parser = MyHTMLParser()
#     parser.feed(html)
#     return ids


# Path: webalchemy/remotedocument.py
import re
import random
import inspect
import logging
from ast import parse
from types import FunctionType
from inspect import getsource
from textwrap import dedent
from pythonium.veloce.veloce import Veloce
from webalchemy.saferef import safeRef
from webalchemy.htmlparser import get_element_ids

        self.rdoc.inline(js)
        self.style = StyleAtt(self.rdoc, self.varname)
        self.style(**kwargs)


class RemoteDocument:
    # TODO: remove block altogether...
    def __init__(self):
        self.varname = 'document'
        self.__uid_count = 0
        self.__code_strings = []
        self.__block_ixs = []
        self.__varname_element_dict = {}
        self.body = Element(self, 'body', '', customvarname='document.body')
        self.head = Element(self, 'head', '', customvarname='document.head')
        self.pop_all_code()  # body and head are special: created by static content
        self.app = SimpleProp(self, 'document', 'app', create=True)
        self.props = SimpleProp(self, 'document')
        self.localStorage = SimpleProp(self, 'localStorage')
        self.sessionStorage = SimpleProp(self, 'localStorage')
        self.stylesheet = _StyleSheet(self)
        self.vendor_prefix = None
        self.jsrpcweakrefs = {}
        self.window = Window(self)
        self.KeyCode = KeyCode

    def parse_elements(self, html):
        class E:
            pass
        e = E()

        for id in get_element_ids(html):