Example #1
0
def guesstype(url):
    '''
    Return a filetype associated to the url "url"
    '''
    path = urlparse(url).path
    ext = os.path.splitext(path)[-1].lstrip('.')
    for p in blocks.parsers():
        if ext in p.extensions:
            return p.extensions[ext]
    return 'unknown'
Example #2
0
def gethandler(filetype, mode='r'):
    '''
    Return a gicdat.Parser subclass that claims it can handle files of filetype (a mimetype-like string) in mode ('r' or 'w' for read or write)

    '''
    for p in blocks.parsers():
        if mode == 'r' and filetype in p.canread:
            return p
        elif mode == 'w' and filetype in p.canwrite:
            return p
    raise IOError('No known handler for file type %s in mode %s' % (filetype, mode))