Exemplo n.º 1
0
ShockwaveFlashPlugin = Plugin({'name'        : 'Shockwave Flash',
                               'filename'    : 'C:\\WINDOWS\\system32\\Macromed\\Flash\\NPSWF32.dll',
                               'description' : 'Shockwave Flash 10.0 r42'})

AdobeAcrobatPlugin   = Plugin({'name'        : 'Adobe Acrobat',
                               'filename'    : 'C:\\Program Files\\Internet Explorer\\PLUGINS\\nppdf32.dll',
                               'description' : 'Adobe Acrobat Plug-In'})

AdobePDFPlugin       = Plugin({'name'        : 'Adobe PDF',
                               'filename'    : 'C:\\Program Files\\Internet Explorer\\PLUGINS\\nppdf32.dll',
                               'description' : 'Adobe PDF Plug-In'})


Plugins = Array()
Plugins.append(ShockwaveFlashPlugin)
Plugins.append(AdobeAcrobatPlugin)
Plugins.append(AdobePDFPlugin)


class Navigator(object):
    appCodeName         = config.appCodeName    # The internal "code" name of the current browser 
    appName             = config.appName        # The official name of the browser
    appVersion          = config.appVersion     # The version of the browser as a string 
    buildID             = ""                    # The build identifier of the browser (e.g. "2006090803") 
    cookieEnabled       = True                  # A boolean indicating whether cookies are enabled    
    language            = ""                    # A string representing the language version of the browser
    mimeTypes           = []                    # A list of the MIME types supported by the browser     
    onLine              = True                  # A boolean indicating whether the browser is working online  
    oscpu               = ""                    # A string that represents the current operating system    
    platform            = ""                    # A string representing the platform of the browser     
Exemplo n.º 2
0
ShockwaveFlashPlugin = Plugin({'name'        : 'Shockwave Flash',
                               'filename'    : 'C:\\WINDOWS\\system32\\Macromed\\Flash\\NPSWF32.dll',
                               'description' : 'Shockwave Flash 10.0 r42'})

AdobeAcrobatPlugin   = Plugin({'name'        : 'Adobe Acrobat',
                               'filename'    : 'C:\\Program Files\\Internet Explorer\\PLUGINS\\nppdf32.dll',
                               'description' : 'Adobe Acrobat Plug-In'})

AdobePDFPlugin       = Plugin({'name'        : 'Adobe PDF',
                               'filename'    : 'C:\\Program Files\\Internet Explorer\\PLUGINS\\nppdf32.dll',
                               'description' : 'Adobe PDF Plug-In'})


Plugins = Array()
Plugins.append(ShockwaveFlashPlugin)
Plugins.append(AdobeAcrobatPlugin)
Plugins.append(AdobePDFPlugin)


class Navigator(object):
    appCodeName         = config.appCodeName    # The internal "code" name of the current browser 
    appName             = config.appName        # The official name of the browser
    appVersion          = config.appVersion     # The version of the browser as a string 
    buildID             = ""                    # The build identifier of the browser (e.g. "2006090803") 
    cookieEnabled       = True                  # A boolean indicating whether cookies are enabled    
    language            = ""                    # A string representing the language version of the browser
    mimeTypes           = []                    # A list of the MIME types supported by the browser     
    onLine              = True                  # A boolean indicating whether the browser is working online  
    oscpu               = ""                    # A string that represents the current operating system    
    platform            = ""                    # A string representing the platform of the browser     
Exemplo n.º 3
0
    start_time1 = time()
    max_heap = MaxHeap()
    from random import randint

    for i in range(n):
        max_heap.add(randint(0, n))

    arr = []
    for i in range(n):
        arr.append(max_heap.extract_max())

    print('heap add: ', time() - start_time1)  # head add:  5.748132228851318

    for i in range(n - 1):
        if arr[i] < arr[i + 1]:
            raise ValueError("Error!")

    start_time2 = time()
    arr = Array()
    from random import randint

    for i in range(n):
        arr.add_last(randint(0, n))
    max_heap = MaxHeap(arr)

    print('heapify: ', time() - start_time2)  # heapify:  4.680660963058472

    arr = []
    for i in range(n):
        arr.append(max_heap.extract_max())
Exemplo n.º 4
0
class DOMObject(object):
    def __init__(self, window, tag, parser):
        self.tagName  = tag
        self.__parser = parser
        self.__dict__['__window'] = window 

        if tag == 'body': 
            self.__dict__['__window'].document.body = self
        if tag == 'select': 
            self.options = Array()
        if tag == 'input': 
            self.value = ''
        if tag == 'option': 
            self.value = 0

        self.children   = []
        self.childNodes = Array()
        self.style      = CSSStyleDeclaration()
        self.__dict__['__window'].document.all.append(self)

        # assign an initial id to every dom node
        varname = 'domnode' + str(int(time.time()*10000000))
        self.__setattr__('id', varname)

    def handle_src(self, name, val):
        url = self.__dict__['__window'].document.location.fix_url(val)

        if config.retrieval_all:
            hc.get(url, self.__dict__['__window'].document.location.href)
        
        scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
        if scheme not in ('http','file','https','ftp'):
            config.VERBOSE(config.VERBOSE_WARNING, "[WARNING] Got unknown scheme: %s in %s.%s ."%(url,self.tagName, name));
            if 'onerror' in self.__dict__:
                config.VERBOSE(config.VERBOSE_DEBUG, "[DEBUG] Calling onerror of %s."%(self.tagName));
                self.onerror()

        if self.tagName == "iframe":
            from Window import Window
            from PageParser import PageParser
            window = Window(self.__dict__['__window'].__dict__['__root'],
                            self.__dict__['__window'].document.location.fix_url(val),
                            self.__dict__['__window'].document.location.href)
            parser = PageParser(window, window.document, window.__dict__['__html'])
            parser.close()

    def handle_id(self, name, val):
        self.__dict__[name] = val
        val = val.replace(':','_').replace('-','_')
        try:
            #if self.__dict__['__window'].__dict__['__cx'].execute('typeof ' + val + ' == "undefined"'):
            self.__dict__['__window'].__dict__['__cx'].add_global(val, self)
        except:
            #traceback.print_exc()
            pass
                
        self.__dict__['__window'].__dict__['__fl'][-1].__setattr__(val, self)

    def handle_name(self, name, val):
        self.handle_id(name, val)

    def handle_innerHTML(self, name, val):
        val = str(val)
        if self.__parser:
            self.__parser.html = self.__parser.html[:self.begin] + val + self.__parser.html[self.end:]
            dev = self.end - self.begin - len(val)
            for i in self.__dict__['__window'].document.all:
                if i.begin:
                    if i.begin > self.end:
                        i.begin -= dev
                if i.end:
                    if i.end >= self.end:
                        i.end -= dev
            
            self.__parser.current -= dev
            return
        
        from PageParser import PageParser
        self.__parser = PageParser(self.__dict__['__window'], self.__dict__['__window'].document, val)

    def __setattr__(self, name, val):
        try:
            handler = getattr(self, "handle_%s" % (name, ))
            handler(name, val)
        except:
            pass
        
        #if it's an event, let it be a function
        if dataetc.isevent(name, self.tagName):
            # using 'this' in methods may cause additional problems.
            # i think i find a way to handle this, but there could 
            # be some cases it cannot cover.
            val = str(val) + ';'
            cx = self.__dict__['__window'].__dict__['__cx']
            val = cx.patch_script(val)
            try:
                if 'id' in self.__dict__:
                    vals    = re.split('(?<=[^a-zA-Z0-9_])this(?=[^a-zA-Z0-9_])', val)
                    valstmp = re.split('^this(?=[^a-zA-Z0-9_])', vals[0])
                    if len(vals) > 1:
                        vals = valstmp + vals[1:]
                    valstmp = re.split('(?<=[^a-zA-Z0-9_])this$', vals[-1])
                    if len(vals) > 1:
                        vals = vals[:-1] + valstmp
                    val = self.id.join(vals)
                self.__dict__[name] = cx.execute('function(){' + val + '}')
            except:
                try:
                    p = val.decode('string-escape')
                    self.__dict__[name] = cx.execute('function(){' + p + '}')
                except:
                    print val
                    #traceback.print_exc()
        
        self.__dict__[name] = val

    def focus(self):
        if 'onfocus' in self.__dict__: 
            self.onfocus()
        self.__dict__['__window'].document.activeElement = self

    def blur(self):
        if 'onblur' in self.__dict__: 
            self.onblur()

    def __getattr__(self, name):
        if name == 'innerHTML': 
            return self.__parser.html[self.begin:self.end]
        
        return unknown()

    def appendChild(self, dom):
        if self.childNodes.length == 0: 
            self.firstChild = dom
        self.childNodes.append(dom)
        self.lastChild = dom
        dom.__dict__['parentNode'] = self
        self.children.append(dom)

    def removeChild(self, dom):
        self.childNodes.remove(dom)
        if self.childNodes.length == 0:
            self.firstChild = None
            self.lastChild  = None
        else:
            self.firstChild = self.childNodes[0]
            self.lastChild  = self.childNodes[self.childNodes.length - 1]

    def setAttribute(self, attname, attval):
        self.__setattr__(attname, attval)

    def removeAttribute(self, attname):
        if self.__dict__[attname]: 
            del self.__dict__[attname]
Exemplo n.º 5
0
    print('5. remove item at first occurrance')
    print('6. index of item at first occurrance')
    print('7. reverse array')
    print('8. Exit')

    choice = input("Enter your choice: ")
    choice = int(choice)

    if choice == 1:
        for item in arr.items:
            print(item, end=" ")

    elif choice == 2:
        # append elements
        itemToAdd = int(input("Enter integer to append: "))
        arr.append(itemToAdd)

    elif choice == 3:
        # insert elements
        itemToInsert = int(input("Enter integer to insert: "))
        insertPosition = int(input("Enter position to insert: "))
        arr.insert(insertPosition, itemToInsert)

    elif choice == 4:
        # pop element
        print(f"popped item is {arr.pop()}")
    elif choice == 5:
        # remove element
        itemToRemove = int(input("Enter integer to remove: "))
        print(arr.remove(itemToRemove))
    elif choice == 6: