예제 #1
0
def _GetAspellIndex(root=None):
    RAD = RemoteAspellDictionary
    response, content = urlcacheopen(httpjoin(root or RAD.ROOT, '0index.html'),
                                     decode=False)

    if not response.ok:
        print 'Unhandled HTTP response code: %r' % response
        return ()

    soup = soupify(content)
    results = {}
    for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'):
        contents = row.findAll('td')
        if len(contents) == 4:
            id, name_english, name_native, dictionary_path = contents
            id = id.find(href=True)

            if id is None:
                continue

            id = id['href']
            if id not in results:
                dictionary_path = dictionary_path.find(href=True)
                if dictionary_path is None:
                    continue
                dictionary_path = dictionary_path['href']

                name_english = name_english.renderContents(None).decode('xml')
                name_native = name_native.renderContents(None).decode(
                    'xml').strip() or None
                results[id] = RAD(id, name_english, name_native, id,
                                  dictionary_path)

    return results.values()
예제 #2
0
파일: dicts.py 프로젝트: AlexUlrich/digsby
def _GetAspellIndex(root=None):
    RAD = RemoteAspellDictionary
    response, content = urlcacheopen(httpjoin(root or RAD.ROOT,'0index.html'), decode=False)

    if not response.ok:
        print 'Unhandled HTTP response code: %r' % response
        return ()

    soup = soupify(content)
    results = {}
    for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'):
        contents = row.findAll('td')
        if len(contents) == 4:
            id, name_english, name_native, dictionary_path = contents
            id = id.find(href=True)

            if id is None:
                continue

            id = id['href']
            if id not in results:
                dictionary_path = dictionary_path.find(href=True)
                if dictionary_path is None:
                    continue
                dictionary_path = dictionary_path['href']

                name_english = name_english.renderContents(None).decode('xml')
                name_native = name_native.renderContents(None).decode('xml').strip() or None
                results[id] = RAD(id, name_english, name_native, id, dictionary_path)

    return results.values()
예제 #3
0
    def loadimages(self):
        try:
            self.img_sm = urlcacheopen(self.thumbnail_url)
        except:
            self.imb_sm = 'javascript'

        if self.img_sm and 'javascript' in self.img_sm:
            self.img_sm = None

        try:
            self.img_lg = urlcacheopen(self.web_url)
        except:
            self.img_lg = 'javascript'

        if self.img_lg and 'javascript' in self.img_lg:
            self.img_lg = None
예제 #4
0
    def fetch_sig(self, root=None):
        '''
        Fetches the .sig file for the remote dictionary file. Returns True if successful, else False.
        If successful, sets _needs_update to be True if the file has changed (that is, if it was fetched
        from the server and not the local cache).
        '''
        if self.sig is None:
            response, content = urlcacheopen(self.get_digest_location(root))
            if not response.ok:
                return False

            self.sig = content
            self.needs_update = not response.fromcache

        return True
예제 #5
0
파일: dicts.py 프로젝트: AlexUlrich/digsby
    def fetch_sig(self, root=None):
        '''
        Fetches the .sig file for the remote dictionary file. Returns True if successful, else False.
        If successful, sets _needs_update to be True if the file has changed (that is, if it was fetched
        from the server and not the local cache).
        '''
        if self.sig is None:
            response, content = urlcacheopen(self.get_digest_location(root))
            if not response.ok:
                return False

            self.sig = content
            self.needs_update = not response.fromcache

        return True
예제 #6
0
파일: dicts.py 프로젝트: AlexUlrich/digsby
def DownloadAllDictionaries(infodict, towhere, root=None):

    if root is None:
        root = RemoteAspellDictionary.ROOT

    for id in infodict:
        name = infodict[id]['name_english']
        bz2path = infodict[id]['location']

        localpath = path(towhere) / bz2path
        bz2path = httpjoin(root,bz2path)

        localpath = localpath.expand()

        print ('Downloading %s (%s) from %s to %s... ' % (name, id, bz2path, localpath)),
        response, content = urlcacheopen(bz2path)
        print response.reason
        if response.ok:
            if not localpath.parent.isdir():
                localpath.parent.makedirs()

            with open(localpath, 'wb') as f:
                f.write(content)
예제 #7
0
def DownloadAllDictionaries(infodict, towhere, root=None):

    if root is None:
        root = RemoteAspellDictionary.ROOT

    for id in infodict:
        name = infodict[id]['name_english']
        bz2path = infodict[id]['location']

        localpath = path(towhere) / bz2path
        bz2path = httpjoin(root, bz2path)

        localpath = localpath.expand()

        print('Downloading %s (%s) from %s to %s... ' %
              (name, id, bz2path, localpath)),
        response, content = urlcacheopen(bz2path)
        print response.reason
        if response.ok:
            if not localpath.parent.isdir():
                localpath.parent.makedirs()

            with open(localpath, 'wb') as f:
                f.write(content)