def __init__(self, buf, callback, *args):
     StringIO.__init__(self, buf)
     self.seek(0, os.SEEK_END)
     self._total = self.tell()
     self.seek(0)
     self._callback = callback
     self._args = args
Example #2
0
 def __init__(self, terminal_type, capture):
     if terminal_type not in ['stdout', 'stderr']:
         raise Exception('Invalid terminal type')
     self.terminal_type = terminal_type
     self.terminal = sys.__dict__[self.terminal_type]
     self.capture = capture
     StringIO.__init__(self)
Example #3
0
File: S3IO.py Project: wbornor/pys3
 def __init__(self, conn, bucket_name, object_name, meta={}, buf=''):
     StringIO.__init__(self, buf)
     
     self.MAX_OBJECT_SIZE = 5368709120 #5GB
     self.conn = conn
     self.bucket_name = bucket_name
     self.object_name = object_name
     self.key = '%s/%s' % (self.bucket_name, self.object_name)
     self.meta = meta
     self.sent_len = 0 #num bytes that have been sent to Amazon
     self.get_complete = False #tells if the get of the object has been completed
     self.closed = False
     
     if buf:
         self.dirty = True
     else:
         self.dirty = False #any unflushed write will set dirty to true
     
     #make sure this bucket exists, otherwise create it
     response = self.conn.list_bucket(bucket_name)
     if response.http_response.status == 404:
         response = self.conn.create_bucket(bucket_name)
         check_http_response(response, 200)
     elif response.http_response.status != 200:
         raise S3ResponseError, response
Example #4
0
File: pys3.py Project: wbornor/pys3
 def __init__(self, conn, bucket_name, object_name, meta={}, buf=''):
     StringIO.__init__(self, buf)
     
     self.MAX_OBJECT_SIZE = 5368709120 #5GB
     self.conn = conn
     self.bucket_name = bucket_name
     self.object_name = object_name
     self.key = '%s/%s' % (self.bucket_name, self.object_name)
     self.meta = meta
     self.sent_len = 0 #num bytes that have been sent to Amazon
     self.get_complete = False #tells if the get of the object has been completed
     self.closed = False
     
     if buf:
         self.dirty = True
     else:
         self.dirty = False #any unflushed write will set dirty to true
     
     #make sure this bucket exists, otherwise create it
     response = self.conn.list_bucket(bucket_name)
     if response.http_response.status == 404:
         response = self.conn.create_bucket(bucket_name)
         check_http_response(response, 200)
     elif response.http_response.status != 200:
         raise S3ResponseError, response
Example #5
0
 def __init__(self,*args,**kwargs):
   self.name = args[0]
   self.mode = args[1]
   if self.mode == "r+b" or self.mode == "rb":
     StringIO.__init__(self, MC.get(self.name))
   else:
     StringIO.__init__(self)
 def __init__(self, buf, callback, *args):
     StringIO.__init__(self, buf)
     self.seek(0, os.SEEK_END)
     self._total = self.tell()
     self.seek(0)
     self._callback = callback
     self._args = args
    def __init__(self, request, stream_format = 'text/html'):
        StringIO.__init__(self)
        self.__stream_format = stream_format
        self.__request = request
	self.__open = 1
        self.__utf8 = 0
        self.__textual = stream_format.startswith("text/")
Example #8
0
 def __init__(self, *args, **kwargs):
     """
     :type self: StringIO.StringIO
     """
     StringIO.__init__(self)
     self.obd_header=[0x82, 0xf1, 0x7e]
     self.proto = 0
Example #9
0
 def __init__(self, *args, **kwargs):
     """The constructor, which passes the `*args, **kwargs` method
     to `StringIO.__init__`.
     """
     StringIO.__init__(self, *args, **kwargs)
     self.priority = 1
     self.lastMBox = None
Example #10
0
 def __init__(self, status=500, reason='Cuz I said so',
              mimetype='text/plain', content=''):
     StringIO.__init__(self, content)
     self.status = status
     self.reason = reason
     self.mimetype = mimetype
     self.msg = self # for self.msg.gettype()
Example #11
0
 def __init__(self, ssh_session, io_file):
     assert isinstance(ssh_session, SSHPrompt)
     self.ssh_session = ssh_session
     self.io_file = io_file
     self.io_file_open = True
     # noinspection PyTypeChecker,PyTypeChecker
     StringIO.__init__(self)
Example #12
0
 def __init__(self, name):
     """
     @param name: Name of this file.
     @type name: C{str}
     """
     self.name = name
     StringIO.__init__(self)
Example #13
0
 def __init__(self, name):
     """
     @param name: Name of this file.
     @type name: C{str}
     """
     self.name = name
     StringIO.__init__(self)
Example #14
0
 def __init__(self, mailfile, file_path, mode, metadata, *args, **kwargs):
     StringIO.__init__(self, *args, **kwargs)
     self._file_path = file_path
     self._open_mode = mode
     self._mailfile = mailfile
     self._lock = mailfile._lock
     self._metadata = metadata
Example #15
0
 def __init__(self, locq, running, replaces=None):
     #: The queue tokens will be placed in
     self.locq = locq
     #: The value indicating if the curses screen is running
     self.running = running
     #: The buffer this replaces.
     self.replaces = replaces
     StringIO.__init__(self)
Example #16
0
 def open(self, mode):
     """Recreates the StringIO base object to simulate opening."""
     StringIO.__init__(self)
     if mode == 'w' or mode == 'w+':
         return
     self.write(self._contents)
     if mode == 'r' or mode == 'r+':
         self.seek(0, 0)
Example #17
0
 def __init__(self, fileobj, charset):
     # Return to position 0
     fileobj.seek(0)
     # Put in StringIO
     StringIO.__init__(fileobj.read())
     self.filename = fileobj.filename.decode(charset)
     self.type = fileobj.type
     self.headers = fileobj.headers
Example #18
0
 def __init__(self, name, message):
     """
     Custom initialization method.
     :param str name: The filename.
     :return: Null
     """
     self.name = name
     StringIO.__init__(self, message)
 def __init__(self, response):
     #super(CachedResponse, self).__init__(response.read())
     StringIO.__init__(self, response.read())
     self.seek(0)
     self.headers = response.info()
     self.url = response.url
     self.code = response.code
     self.msg = response.msg
 def __init__(self, orig, pid=None):
     StringIO.__init__(self)
     self.orig = orig
     self._queue = Queue()
     if pid is None:
         self.pid = os.getpid()
     else:
         self.pid = pid
Example #21
0
 def __init__(self, orig, pid=None):
     StringIO.__init__(self)
     self.orig = orig
     self._queue = Queue()
     if pid is None:
         self.pid = os.getpid()
     else:
         self.pid = pid
Example #22
0
 def __init__(self, stream, **kwds):
   if type(stream) == str:
     data = stream
   else:
     data = stream.getvalue()
   self.filepath = self
   StringIO.__init__(self, data)
   MpegAudio.__init__(self, **kwds)
    def __init__(self, handler, stream_format = 'text/html'):
        # 'handler' is a RequestHandler
        StringIO.__init__(self)
        self.__stream_format = stream_format
        self.__handler = handler
	self.__open = True
        self.__utf8 = False
        self.__textual = stream_format.startswith("text/")
Example #24
0
 def __init__(self,locq,running, replaces=None):
     #: The queue tokens will be placed in
     self.locq = locq
     #: The value indicating if the curses screen is running
     self.running = running
     #: The buffer this replaces.
     self.replaces = replaces
     StringIO.__init__(self)
Example #25
0
 def __init__(self, response):
         #super(CachedResponse, self).__init__(response.read())
         StringIO.__init__(self, response.read())
         self.seek(0)
         self.headers = response.info()
         self.url = response.url
         self.code = response.code
         self.msg = response.msg
Example #26
0
 def __init__(self, max_size=None, buffer=None):
     """
     max_size is the max size of the buffer in bytes
     """
     args = []
     if buffer is not None:
         args.append(buffer)
     StringIO.__init__(self, *args)
     self.__max_size = max_size
Example #27
0
	def __init__(self, path, inode, mode):
		self.path = path
		self.inode = inode
		self.mode = mode
		if 'w' in mode:
			InodeLookupCache.delete(self.path)
			inode.put_content('')
			inode.put()
		StringIO.__init__(self, inode.get_content())
Example #28
0
    def __init__(self, file_object=None, fd=1):
        if file_object:
            self.buffer = file_object
        else:
            self.buffer = self

        self.fd = fd

        StringIO.__init__(self)
Example #29
0
    def __init__(self,
                 uri,
                 data='',
                 filename='',
                 mimeType='',
                 format='',
                 accept=''):
        self.uri = uri
        if data:
            self.data = data
        elif filename:
            if os.path.exists(filename):
                fh = file(filename)
                self.data = fh.read()
                fh.close()
        else:
            # try to fetch uri
            try:
                req = urllib2.Request(uri)
                if accept:
                    # add custom accept header
                    req.add_header('Accept', accept)
                else:
                    # otherwise add default
                    req.add_header('Accept', accept_header)
                fh = urllib2.urlopen(req)
                self.data = fh.read()
                self.info = fh.info()
                mimeType = self.info.dict.get('content-type', mimeType)
                self.uri = fh.geturl()
                fh.close()
            except:
                raise OreException(
                    'ReMDocument must either have data or filename')

            if not format:
                try:
                    mt = conneg.parse(mimeType)
                    if mt:
                        mimeType = mt[0].mimetype1 + '/' + mt[0].mimetype2
                except:
                    pass
                mimeHash = {
                    'application/atom+xml': 'atom',
                    'application/xhtml+xml': 'rdfa',
                    'application/rdf+xml': 'xml',
                    'text/plain': 'nt',  # yes, really
                    'text/rdf+n3': 'n3',
                    'application/x-turtle': 'turtle',
                    'application/rdf+nt': 'nt'
                }
                format = mimeHash.get(mimeType, '')

        self.mimeType = mimeType
        self.format = format
        StringIO.__init__(self, self.data)
    def __init__(self, filename=None):
        if filename != None:
            self.filename = filename
        else:
            self.filename = None

        if self.filename != None:
            StringIO.__init__(self, open(self.filename).read())
        else:
            StringIO.__init__(self)
Example #31
0
 def __init__(self,
              status=500,
              reason='Cuz I said so',
              mimetype='text/plain',
              content=''):
     StringIO.__init__(self, content)
     self.status = status
     self.reason = reason
     self.mimetype = mimetype
     self.msg = self  # for self.msg.gettype()
Example #32
0
    def __init__(self, data='', code=200):
        """Create a new mock object for the objects returned by
        url_open.

        Args:
            data: str. Response data.
            code: int. HTTP response code.
        """
        StringIO.__init__(self, data)
        self.code = code
Example #33
0
    def __init__(self, filename=None):
        if filename != None:
            self.filename = filename
        else:
            self.filename = None

        if self.filename != None:
            StringIO.__init__(self, open(self.filename).read())
        else:
            StringIO.__init__(self)
Example #34
0
 def __init__(self, buffer='', writers=None):
     """If ``writers`` is given and is a file-like object or an
     iterable of same, it/they will be written to whenever this
     StringIO instance is written to.
     """
     StringIO.__init__(self, buffer)
     if writers is None:
         writers = []
     elif hasattr(writers, 'write'):
         writers = [writers]
     self.writers = writers
Example #35
0
 def __init__(self, buffer='', writers=None):
     """If ``writers`` is given and is a file-like object or an
     iterable of same, it/they will be written to whenever this
     StringIO instance is written to.
     """
     StringIO.__init__(self, buffer)
     if writers is None:
         writers = []
     elif hasattr(writers, 'write'):
         writers = [writers]
     self.writers = writers
Example #36
0
 def __init__(self, buffer='', cc=None):
     """
     If ``cc`` is given and is a file-like object or an iterable of same,
     it/they will be written to whenever this StringIO instance is written
     to.
     """
     StringIO.__init__(self, buffer)
     if cc is None:
         cc = []
     elif hasattr(cc, 'write'):
         cc = [cc]
     self.cc = cc
Example #37
0
    def __init__(self, *args, **kwargs):
        """Summary

        Args:
            *args: Description
            **kwargs: Description
        """
        if 'logger' in kwargs:
            self.log = kwargs['logger'] or logging.getLogger(__name__ + '.' +
                                                             self.__class__.__name__)
        self.managers = weakref.WeakValueDictionary()
        StringIO.__init__(self, *args, **kwargs)
Example #38
0
 def __init__(self, buffer='', cc=None):
     """
     If ``cc`` is given and is a file-like object or an iterable of same,
     it/they will be written to whenever this StringIO instance is written
     to.
     """
     StringIO.__init__(self, buffer)
     if cc is None:
         cc = []
     elif hasattr(cc, 'write'):
         cc = [cc]
     self.cc = cc
Example #39
0
    def __init__(self, old_stdout, old_stderr, useold):
        """ Initializes the Logger object
		Extends StringIO in order to capture stdout and stderr
		
		@param old_stdout
		@param old_stderr
		@param useold
		"""
        StringIO.__init__(self)  #overriding object must implement StringIO
        self.output = Tkinter.StringVar()
        self.useold = useold
        self.old_stdout = old_stdout
        self.old_stderr = old_stderr
Example #40
0
    def __init__(self, filename):
        """
        constructor

        @param      filename        filename
        """
        StringIO.__init__(self)
        self.filename = filename
        if os.path.exists(filename):
            os.remove(filename)
        self.handle = None
        self.redirect = {}
        self.to = None
Example #41
0
    def __init__(self, name='', **kw):
        StringIO.__init__(self)
        self.name = name
        self.is_sub = False
        self.is_main = False
        self.duration = 0
        self.settings = deepcopy(self.DEFAULT_PARA)
        for key in kw:
            self.settings[key] = kw[key]
        self.seq = []

        self.stats = [0, 0]

        self.write('MAGIC 3004\r\nLINES ')
        self.update(trailer=True)
Example #42
0
File: dbfs.py Project: mitjat/dbfs
	def __init__(self, data, path, mode, filemgr):
		"""
		@param data: initial contents. Ignored if opened in write mode.
		@param path: path to the file
		@param mode: e.g. 'r', 'r+', 'w', 'a'
		@param filemgr: a filesystem (DatabaseFS instance) with at least the following funcitons:
			- flush_callback(path,data): called every time file is flushed
			- close_callback(path): called when file is closed
		"""
		StringIO.__init__(self, data if 'w' not in mode else '')
		if mode=='r' or '+' in mode: self.seek(0)
		self.filemgr = filemgr
		self.path = path
		self.mode = mode
		self.modified = False
Example #43
0
    def __init__(self, data, path, mode, filemgr):
        """
		@param data: initial contents. Ignored if opened in write mode.
		@param path: path to the file
		@param mode: e.g. 'r', 'r+', 'w', 'a'
		@param filemgr: a filesystem (DatabaseFS instance) with at least the following funcitons:
			- flush_callback(path,data): called every time file is flushed
			- close_callback(path): called when file is closed
		"""
        StringIO.__init__(self, data if 'w' not in mode else '')
        if mode == 'r' or '+' in mode: self.seek(0)
        self.filemgr = filemgr
        self.path = path
        self.mode = mode
        self.modified = False
    def __init__(self, old_stdout, old_stderr, logpath, useold=True):
        """ Initializes the Logger object
		Extends StringIO in order to capture stdout and stderr
		
		@param parent
		@param gui
		@param options
		"""
        StringIO.__init__(self)  #overriding object must implement StringIO
        self.logpath = logpath
        if (not os.path.exists(self.logpath)):
            os.makedirs(self.logpath)
        self.logfile = os.path.join(self.logpath, 'output.log')
        self.useold = useold
        self.old_stdout = old_stdout
        self.old_stderr = old_stderr
Example #45
0
    def __init__(self, num, thread, download, buf=''):
        StringIO.__init__(self)

        # Force self.buf to be a string or unicode
        if not isinstance(buf, basestring):
            buf = str(buf)

        self.buf = buf
        self.len = len(buf)
        self.buflist = []
        self.pos = 0
        self.closed = False
        self.softspace = 0
        self.thread = thread
        self.num = num
        self.download = download
        self.total = self.len * self.thread
Example #46
0
    def __init__(self, total, line_count, update_interval=.05):
        StringIO.__init__(self)
        self.container = {}
        self.counter = {}
        self.total = total
        self.columns = ['name', 'progress', 'update', 'count']
        self._make_board(line_count)

        if self._is_notebook():
            self.fmt = self._notebook_format
            self.flush = self._notebook_flush
        else:
            self.fmt = self._console_format
            self.flush = self._console_flush

        interval = int(update_interval * self.total)
        self.interval = interval if interval > 0 else 1
Example #47
0
    def __init__(self, info, parent_name):
        """
        Creates an instance of the internal file based on the data in the
        intenral file.

        :Paramters:
           - `info`: cpioarchive item from ._infos
           - `parent_name`: name of the parent file
        """
        StringIO.__init__(self, info.read())
        self.name = info.name

        class Dummy(object):
            pass

        self.fileobj = Dummy()
        self.fileobj.name = parent_name
Example #48
0
 def __init__(
     self, 
     stream = sys.stdout, 
     loglevel = info, 
     *args, 
     **kwargs
 ):
     self.stream = stream
     self.loglevel = loglevel
     return StringIO.__init__(self, *args, **kwargs)
Example #49
0
    def __init__(self, windows):
        StringIO.__init__(self)
        self.windows = windows
        self.autoscroll = {}
        self.pos = {}
        self.lines = {}
        self.maxsize = {}
        self.stdout = None
        self.logfile = None
        self.wrapper = TextWrapper(width=80, initial_indent="",
                                   subsequent_indent="         ",
                                   replace_whitespace=False)

        if NCURSES:
            for windex in windows:
                h, w = windows[windex][0].getmaxyx()
                self.maxsize[windex] = (h, w)
                self.pos[windex] = [0, 0]
                self.autoscroll[windex] = True
                self.lines[windex] = 0
Example #50
0
    def __init__(self, windows):
        StringIO.__init__(self)
        self.windows = windows
        self.autoscroll = {}
        self.pos = {}
        self.lines = {}
        self.maxsize = {}
        self.stdout = None
        self.logfile = None
        self.wrapper = TextWrapper(width=80,
                                   initial_indent="",
                                   subsequent_indent="         ",
                                   replace_whitespace=False)

        if NCURSES:
            for windex in windows:
                h, w = windows[windex][0].getmaxyx()
                self.maxsize[windex] = (h, w)
                self.pos[windex] = [0, 0]
                self.autoscroll[windex] = True
                self.lines[windex] = 0
Example #51
0
    def __init__(self, source = None, name = "data") :
        """Constructor
        
        @param source   Source data to compress (as a stream/File/Buffer - anything with a read() method)
        @param name     Name of the data within the zip file"""
        
        # Source file
        self.source = source

        # OEF reached for source ?
        self.source_eof = False

        # Buffer
        self.buffer = ""

        StringIO.__init__(self)

        # Inherited constructor

        # Init ZipFile that writes to us (the StringIO buffer)
        self.zipfile = GzipFile(name, 'wb', 9, self)
Example #52
0
    def __init__(self, source=None, name="data"):
        """Constructor
        
        @param source Source data to compress (as a stream/File/Buffer - anything with a read() method)
        @param name Name of the data within the zip file"""

        # Source file
        self.source = source

        # OEF reached for source ?
        self.source_eof = False

        # Buffer
        self.buffer = ""

        StringIO.__init__(self)

        # Inherited constructor

        # Init ZipFile that writes to us (the StringIO buffer)
        self.zipfile = GzipFile(name, 'wb', 9, self)
			def __init__(self, filename, opt=''):
				self.opt = opt
				buf = ''

				self.filename = xbmcvfs_path(filename)
				if 'r' in opt or 'a' in opt:
					exst = exists(filename)
					if not exst and 'r' in opt:
						from errno import ENOENT
						raise IOError(ENOENT, 'Not a file', filename)

					if exst:
						# read
						f = xbmcvfs.File(self.filename)
						buf = f.read()
						f.close()

				StringIO.__init__(self, buf)

				if 'a' in opt:
					self.seek(0, mode=2)
Example #54
0
    def __init__(self, parent, ira_browse, mode):
        nodes.node_descriptor.__init__(self, parent)
        self._size = 0L
        if mode.endswith('b'):
            mode = mode[:-1]

        if mode in ('r', 'r+'):
            cr = ira_browse._cr  # reuse the cursor of the browse object, just now
            cr.execute('SELECT db_datas FROM ir_attachment WHERE id = %s',
                       (ira_browse.id, ))
            data = cr.fetchone()[0]
            if data:
                self._size = len(data)
            StringIO.__init__(self, data)
        elif mode in ('w', 'w+'):
            StringIO.__init__(self, None)
            # at write, we start at 0 (= overwrite), but have the original
            # data available, in case of a seek()
        elif mode == 'a':
            StringIO.__init__(self, None)
        else:
            logging.getLogger('document.storage').error(
                "Incorrect mode %s specified", mode)
            raise IOError(errno.EINVAL, "Invalid file mode")
        self.mode = mode
Example #55
0
    def __init__(self, hosted_file, mode, content_type=None, filename=None):
        self.url = hosted_file._wadl_resource.url
        if mode == 'r':
            if content_type is not None:
                raise ValueError("Files opened for read access can't "
                                 "specify content_type.")
            if filename is not None:
                raise ValueError("Files opened for read access can't "
                                 "specify filename.")
            response, value = hosted_file._root._browser.get(
                self.url, return_response=True)
            content_type = response['content-type']
            last_modified = response.get('last-modified')

            # The Content-Location header contains the URL of the file
            # hosted by the web service. We happen to know that the
            # final component of the URL is the name of the uploaded
            # file.
            content_location = response['content-location']
            path = urlparse(content_location)[2]
            filename = urllib.unquote(path.split("/")[-1])
        elif mode == 'w':
            value = ''
            if content_type is None:
                raise ValueError("Files opened for write access must "
                                 "specify content_type.")
            if filename is None:
                raise ValueError("Files opened for write access must "
                                 "specify filename.")
            last_modified = None
        else:
            raise ValueError("Invalid mode. Supported modes are: r, w")

        self.hosted_file = hosted_file
        self.mode = mode
        self.content_type = content_type
        self.filename = filename
        self.last_modified = last_modified
        StringIO.__init__(self, value)
Example #56
0
    def __init__(self, stream, parameters):
        """
        Create a TemplatedStream by populating variables from the
        parameters mapping.  Silently passes matching strings that
        do not have a corresponding key defined in parameters as empty strings.
        """

        StringIO.__init__(self)

        def dbrace_expand(match):
            if match.group(1) in parameters:
                # we may occassionally be handed non-string object in
                # parameters.  Just convert them to string, they will
                # be re-run through the YAML parser anyway.
                return str(parameters[match.group(1)])
            else:
                return ''
        
        for line in stream:
            self.write(self.dbrace_re.sub(dbrace_expand, line))

        self.seek(0)
Example #57
0
    def __init__(self, hosted_file, mode, content_type=None, filename=None):
        self.url = hosted_file._wadl_resource.url
        if mode == 'r':
            if content_type is not None:
                raise ValueError("Files opened for read access can't "
                                 "specify content_type.")
            if filename is not None:
                raise ValueError("Files opened for read access can't "
                                 "specify filename.")
            response, value = hosted_file._root._browser.get(
                self.url, return_response=True)
            content_type = response['content-type']
            last_modified = response.get('last-modified')

            # The Content-Location header contains the URL of the file
            # hosted by the web service. We happen to know that the
            # final component of the URL is the name of the uploaded
            # file.
            content_location = response['content-location']
            path = urlparse(content_location)[2]
            filename = urllib.unquote(path.split("/")[-1])
        elif mode == 'w':
            value = ''
            if content_type is None:
                raise ValueError("Files opened for write access must "
                                 "specify content_type.")
            if filename is None:
                raise ValueError("Files opened for write access must "
                                 "specify filename.")
            last_modified = None
        else:
            raise ValueError("Invalid mode. Supported modes are: r, w")

        self.hosted_file = hosted_file
        self.mode = mode
        self.content_type = content_type
        self.filename = filename
        self.last_modified = last_modified
        StringIO.__init__(self, value)