Ejemplo n.º 1
0
    def testGetInnerZipData(self):

        try:
            fd, filename = tempfile.mkstemp()
            os.write(fd, self.zipContents)
            os.close(fd)

            zipReader = ZipReader(filename)

            mibinfo, data = zipReader.getData('testC')

            assert data == 'C\n'

        finally:
            try:
                os.remove(filename)

            except:
                pass
Ejemplo n.º 2
0
    def testGetInnerZipData(self):
        filename = None

        try:
            fd, filename = tempfile.mkstemp()
            os.write(fd, self.zipContents)
            os.close(fd)

            zipReader = ZipReader(filename)

            mibinfo, data = zipReader.getData('testC')

            assert data == 'C\n'

        except Exception:
            pass

        if filename:
            try:
                os.remove(filename)

            except Exception:
                pass
Ejemplo n.º 3
0
    def testGetDataFromFile(self):

        filename = None

        try:
            fd, filename = tempfile.mkstemp()
            os.write(fd, self.zipContents)
            os.close(fd)

            zipReader = ZipReader(filename)

            mibinfo, data = zipReader.getData('testA')

            assert data == 'A\n'

        except Exception:
            pass

        if filename:
            try:
                os.remove(filename)

            except Exception:
                pass
Ejemplo n.º 4
0
Archivo: url.py Proyecto: mr-sven/pysmi
def getReadersFromUrls(*sourceUrls, **options):
    readers = []
    for sourceUrl in sourceUrls:
        mibSource = urlparse.urlparse(sourceUrl)

        if sys.version_info[0:2] < (2, 5):

            class ParseResult(tuple):
                pass

            mibSource = ParseResult(mibSource)

            for k, v in zip(
                ('scheme', 'netloc', 'path', 'params', 'query', 'fragment',
                 'username', 'password', 'hostname', 'port'),
                    mibSource + ('', '', '', None)):
                if k == 'scheme':
                    if not mibSource[0] or mibSource[0] == 'file':
                        if mibSource[2].endswith(
                                '.zip') or mibSource[2].endswith('.ZIP'):
                            v = 'zip'

                setattr(mibSource, k, v)

        if mibSource.scheme in ('', 'file', 'zip'):
            scheme = mibSource.scheme
            filePath = urlrequest.url2pathname(mibSource.path)
            if scheme != 'file' and (filePath.endswith('.zip')
                                     or filePath.endswith('.ZIP')):
                scheme = 'zip'

            else:
                scheme = 'file'

            if scheme == 'file':
                readers.append(FileReader(filePath).setOptions(**options))
            else:
                readers.append(ZipReader(filePath).setOptions(**options))

        elif mibSource.scheme in ('http', 'https'):
            readers.append(
                HttpReader(
                    mibSource.hostname or mibSource.netloc,
                    mibSource.port or 80,
                    mibSource.path,
                    ssl=mibSource.scheme == 'https').setOptions(**options))

        elif mibSource.scheme in ('ftp', 'sftp'):
            readers.append(
                FtpReader(mibSource.hostname or mibSource.netloc,
                          mibSource.path,
                          ssl=mibSource.scheme == 'sftp',
                          port=mibSource.port or 21,
                          user=mibSource.username or 'anonymous',
                          password=mibSource.password
                          or 'anonymous@').setOptions(**options))

        else:
            raise error.PySmiError('Unsupported URL scheme %s' % sourceUrl)

    return readers