当前位置: 首页>>代码示例>>Python>>正文


Python buffer.Buffer类代码示例

本文整理汇总了Python中buffer.Buffer的典型用法代码示例。如果您正苦于以下问题:Python Buffer类的具体用法?Python Buffer怎么用?Python Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PseudoStreamDecoder

class PseudoStreamDecoder(Stream):
    def __init__(self, transport_class, transport_kwargs):
        self.bufin=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
        self.bufout=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
        self.upstream=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
        self.downstream=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
        self.transport=transport_class(self, **transport_kwargs)
        self.lockin=threading.Lock()
        self.lockout=threading.Lock()

    def decode_data(self, data):
        with self.lockin:
            #print "decoding %s"%repr(data)
            self.bufin.drain()
            self.bufin.write(data)
            self.transport.downstream_recv(self.bufin)
            cookie=self.bufin.cookie
            self.bufin.cookie=None
            return self.upstream.read(), cookie

    def encode_data(self, data, cookie):
        with self.lockout:
            #print "encoding %s"%repr(data)
            self.bufout.drain()
            self.bufout.write(data)
            self.bufout.cookie=cookie
            self.transport.upstream_recv(self.bufout)
            return self.downstream.read()
开发者ID:matanmaz,项目名称:pupy,代码行数:28,代码来源:servers.py

示例2: I18nFileAccessor

class I18nFileAccessor(object):
	def __init__(self, path):
		self.b = Buffer()
  
		with open(path, 'r') as f:
			self.b.addInfos(f.read())

		self._indexes = dict()
    
		self.b.setCursor(self.b.readInt())
		nbValues = self.b.readInt() / 8;
		for i in range(0, nbValues):
			key = self.b.readInt()
			val = self.b.readInt()

			self._indexes[key] = val

	def getText(self, arg1):
		pos = self._indexes[arg1]
  
		self.b.setCursor(pos)

		return self.b.readUTF()

	def hasText(self, arg1):
		return self._indexes[arg1]
开发者ID:alucas,项目名称:dsniff,代码行数:26,代码来源:i18nfileaccessor.py

示例3: VertexStream

class VertexStream(object):
    """
    VertexFormat must be set for this class to render correctly.
    And before vertexformat is set, you have to bind the vbo.
    """
    def __init__(self, fmt, which=GL_TRIANGLES, maxCount=4096):
        self.fmt      = fmt
        self.fmt_ctype_p = POINTER(self.fmt.ctype)
        self.which    = which
        self.maxCount = 4096
        self.vbo = Buffer(usage=GL_STREAM_DRAW)
        self.vbo.setSize(sizeof(fmt.ctype) * self.maxCount)
        self.data = None
        self.count = 0

    def vertex(self, *data):
        if self.count == 0:
            address = self.vbo.map(GL_WRITE_ONLY)
            assert address != 0
            self.data = cast(address, self.fmt_ctype_p)
        self.data[self.count] = data
        self.count += 1
        if self.count >= self.maxCount:
            self.flush()

    def flush(self):
        if self.count > 0:
            self.data = None
            self.vbo.unmap()
            glDrawArrays(self.which, 0, self.count)
            self.count = 0
开发者ID:cheery,项目名称:essence,代码行数:31,代码来源:vertexstream.py

示例4: __init__

 def __init__(self, transport_class, transport_kwargs):
     self.bufin=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
     self.bufout=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
     self.upstream=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
     self.downstream=Buffer(transport_func=addGetPeer(("127.0.0.1", 443)))
     self.transport=transport_class(self, **transport_kwargs)
     self.lockin=threading.Lock()
     self.lockout=threading.Lock()
开发者ID:matanmaz,项目名称:pupy,代码行数:8,代码来源:servers.py

示例5: test_buffer_resize

 def test_buffer_resize(self):
     data = np.zeros(10)
     B = Buffer(data=data)
     data = np.zeros(20)
     B._need_resize == False
     B.set_data(data)
     assert B.nbytes == data.nbytes
     assert B._need_resize == True
开发者ID:gabr1e11,项目名称:GLSL-Examples,代码行数:8,代码来源:test_buffer.py

示例6: EditorShellNotebook

class EditorShellNotebook(wx.Notebook):
    """A notebook containing an editor page and a shell page."""

    def __init__(self, parent, filename=None):
        """Create EditorShellNotebook instance."""
        wx.Notebook.__init__(self, parent, id=-1)
        usePanels = True
        if usePanels:
            editorparent = editorpanel = wx.Panel(self, -1)
            shellparent = shellpanel = wx.Panel(self, -1)
        else:
            editorparent = self
            shellparent = self
        self.buffer = Buffer()
        self.editor = Editor(parent=editorparent)
        self.buffer.addEditor(self.editor)
        self.buffer.open(filename)
        self.shell = Shell(
            parent=shellparent, locals=self.buffer.interp.locals, style=wx.CLIP_CHILDREN | wx.SUNKEN_BORDER
        )
        self.buffer.interp.locals.clear()
        if usePanels:
            self.AddPage(page=editorpanel, text="Editor", select=True)
            self.AddPage(page=shellpanel, text="Shell")
            # Setup sizers
            editorsizer = wx.BoxSizer(wx.VERTICAL)
            editorsizer.Add(self.editor.window, 1, wx.EXPAND)
            editorpanel.SetSizer(editorsizer)
            editorpanel.SetAutoLayout(True)
            shellsizer = wx.BoxSizer(wx.VERTICAL)
            shellsizer.Add(self.shell, 1, wx.EXPAND)
            shellpanel.SetSizer(shellsizer)
            shellpanel.SetAutoLayout(True)
        else:
            self.AddPage(page=self.editor.window, text="Editor", select=True)
            self.AddPage(page=self.shell, text="Shell")
        self.editor.setFocus()
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged, id=self.GetId())

    def OnPageChanged(self, event):
        """Page changed event handler."""
        selection = event.GetSelection()
        if selection == 0:
            self.editor.setFocus()
        else:
            self.shell.SetFocus()
        event.Skip()

    def SetFocus(self):
        wx.Notebook.SetFocus(self)
        selection = self.GetSelection()
        if selection == 0:
            self.editor.setFocus()
        else:
            self.shell.SetFocus()
开发者ID:czxxjtu,项目名称:wxPython,代码行数:55,代码来源:editor.py

示例7: parse

 def parse(cls,buffer):
     rname = buffer.decode_name()
     rtype,rclass,ttl,rdlength = buffer.unpack("!HHIH")
     if rtype == QTYPE.OPT:
         options = []
         option_buffer = Buffer(buffer.get(rdlength))
         while option_buffer.remaining() > 4:
             code,length = option_buffer.unpack("!HH")
             data = option_buffer.get(length)
             options.append(EDNSOption(code,data))
         rdata = options
     else:
         rdata = RDMAP.get(QTYPE[rtype],RD).parse(buffer,rdlength)
     return cls(rname,rtype,rclass,ttl,rdata)
开发者ID:0x8008135,项目名称:pymitm6,代码行数:14,代码来源:dns.py

示例8: __init__

 def __init__(self, parent, filename=None):
     """Create EditorShellNotebook instance."""
     wx.Notebook.__init__(self, parent, id=-1)
     usePanels = True
     if usePanels:
         editorparent = editorpanel = wx.Panel(self, -1)
         shellparent = shellpanel = wx.Panel(self, -1)
     else:
         editorparent = self
         shellparent = self
     self.buffer = Buffer()
     self.editor = Editor(parent=editorparent)
     self.buffer.addEditor(self.editor)
     self.buffer.open(filename)
     self.shell = Shell(parent=shellparent, locals=self.buffer.interp.locals,
                        style=wx.CLIP_CHILDREN | wx.SUNKEN_BORDER)
     self.buffer.interp.locals.clear()
     if usePanels:
         self.AddPage(page=editorpanel, text='Editor', select=True)
         self.AddPage(page=shellpanel, text='Shell')
         # Setup sizers
         editorsizer = wx.BoxSizer(wx.VERTICAL)
         editorsizer.Add(self.editor.window, 1, wx.EXPAND)
         editorpanel.SetSizer(editorsizer)
         editorpanel.SetAutoLayout(True)
         shellsizer = wx.BoxSizer(wx.VERTICAL)
         shellsizer.Add(self.shell, 1, wx.EXPAND)
         shellpanel.SetSizer(shellsizer)
         shellpanel.SetAutoLayout(True)
     else:
         self.AddPage(page=self.editor.window, text='Editor', select=True)
         self.AddPage(page=self.shell, text='Shell')
     self.editor.setFocus()
     self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged, id=self.GetId())
开发者ID:ktan2020,项目名称:legacy-automation,代码行数:34,代码来源:editor.py

示例9: __init__

    def __init__(self, parent, filename=None):
        """Create EditorShellNotebook instance."""
        if DEBUG : print "EditorShellNotebook"

        self.parent=parent
        wx.Notebook.__init__(self, parent, id=-1)
        editorparent = editorpanel = wx.Panel(self, -1)
        logparent = logpanel = wx.Panel(self, -1)
        plotparent = plotpanel = wx.Panel(self, -1)
        self.buffer = Buffer()
        
        self.editor = Editor(parent=editorparent)
        self.buffer.addEditor(self.editor)
        self.buffer.open(filename)
        self.log= ViewLog(parent=logparent)
        self.editor.log = self.log
        
        self.plot = PlotFigure(parent=plotparent,filename=filename)
        self.editor.plot = self.plot
        
        # Set the log target to be this textctrl using our own class
        wx.Log_SetActiveTarget(MyLog(self.log, 0))
        
        # for serious debugging
        if SERIOUSDEBUG:
            wx.Log_SetActiveTarget(wx.LogStderr())
            wx.Log_SetTraceMask(wx.TraceMessages)

        self.AddPage(page=editorpanel, text='Editor', select=True)
        self.AddPage(page=logpanel, text='Log')
        self.AddPage(page=plotpanel, text='Plot')

        # Setup sizers

        editorsizer = wx.BoxSizer(wx.VERTICAL)
        editorsizer.Add(self.editor.window, 1, wx.EXPAND)
        editorpanel.SetSizer(editorsizer)
        editorpanel.SetAutoLayout(True)

        logsizer = wx.BoxSizer(wx.VERTICAL)
        logsizer.Add(self.log.window, 1, wx.EXPAND)
        logpanel.SetSizer(logsizer)
        logpanel.SetAutoLayout(True)

        plotsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        plotsizer1.Add(self.plot.canvas, 1, wx.EXPAND)
        plotsizer1.Add(self.plot.choice, 0, wx.EXPAND)
        plotsizer = wx.BoxSizer(wx.VERTICAL)
        plotsizer.Add(plotsizer1, 1, wx.EXPAND)
        plotsizer.Add(self.plot.toolbar, 0, wx.GROW)
        plotpanel.SetSizer(plotsizer)

        self.plot.Fit()

        # Plot the spectra read from filename
        if  self.plot.plot_data() :
            self.SetSelection(2)
            self.plot.Show()
        
        wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
开发者ID:BackupTheBerlios,项目名称:pulsar-svn,代码行数:60,代码来源:editor.py

示例10: __init__

    def __init__(self, game):
        self.game = game

        # core variables
        # self.running = False  # no point, is there? we have is_connected() and is_alive()
        # self.thread = None  # instances are updated by their Game or Server if no game has been found yet
        self.session = Session()
        self.buffer = Buffer()

        # game information
        self.name = 'Test'  #''.join([random.choice('0123456789abcdefghijlkmnopqrstuvwxyz') for i in range(8)])
        self.last_x = 0  # last sent mouse X coordinate
        self.last_y = 0  # last sent mouse Y coordinate
        self.view_x = 0  # viewport x
        self.view_y = 0  # viewport y
        self.view_w = 0  # viewport width
        self.view_h = 0  # viewport height

        # our state
        self.has_sent_init = False
        self.last_sent_spawn = 0
        self.last_update = 0

        # cell information
        self.ids = []  # list of ids (to get cell, query id in all_cells)
        # no longer track cell ids
        self.ladder = []
        self.mode = 'ffa'
开发者ID:Raeon,项目名称:pygar,代码行数:28,代码来源:bot.py

示例11: __init__

    def __init__(self, loop, socket, remote = None):
        self.__sock = socket
        self.__sock.setblocking(False)
        self.__peeraddr = remote

        self.__loop = loop

        self.__recvbuf = Buffer()
        self.__sendbuf = Buffer()
        self.__shouldPollWrite = False

        self.__onConnectCallback = None
        self.__onDisconnectCallback = None

        self.__msgCallback = None
        self.__futures = []
开发者ID:loveyacper,项目名称:pyredis,代码行数:16,代码来源:connection.py

示例12: bufferCreate

 def bufferCreate(self, filename=None):
     """Create new buffer."""
     buffer = Buffer()
     panel = wx.Panel(parent=self.notebook, id=-1)
     panel.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: x)        
     editor = Editor(parent=panel)
     panel.editor = editor
     sizer = wx.BoxSizer(wx.VERTICAL)
     sizer.Add(editor.window, 1, wx.EXPAND)
     panel.SetSizer(sizer)
     panel.SetAutoLayout(True)
     sizer.Layout()
     buffer.addEditor(editor)
     buffer.open(filename)
     self.setEditor(editor)
     self.notebook.AddPage(page=panel, text=self.buffer.name, select=True)
     self.editor.setFocus()
开发者ID:ktan2020,项目名称:legacy-automation,代码行数:17,代码来源:editor.py

示例13: __init__

 def __init__(self, filename):
     self.debug = True
     self.filename = filename
     self.buf = Buffer(filename, False)
     self.read_header()
     self.buf.close()
     self.read_matrix()
     self.num_rows = len(self.trace)
开发者ID:ApatheticsAnonymous,项目名称:panda,代码行数:8,代码来源:tubtf.py

示例14: parse_line

def parse_line(line, chars=None, depth=0):
    """Convert a single line of Logo into a list of tokens or lists.

    >>> parse_line('print sum 10 difference 7 3')
    ['print', 'sum', '10', 'difference', '7', '3']
    >>> parse_line('print "this [is a [deep] list]')
    ['print', '"this', ['is', 'a', ['deep'], 'list']]
    """
    if chars == None:
        chars = Buffer(line.strip()[:])

    tokens = []
    while True:
        if chars.current == None: # End of the line
            if depth != 0:
                raise SyntaxError('Unmatched "[" at ' + str(chars))
            return tokens
        elif chars.current == ' ': # Skip over spaces
            chars.pop()
        elif chars.current == '[':
            chars.pop()
            tokens.append(parse_line(line, chars, depth + 1))
        elif chars.current == ']':
            if depth == 0:
                raise SyntaxError('Unexpected "]" at ' + str(chars))
            else:
                chars.pop()
                return tokens
        else:
            tokens.append(parse_token(chars))
开发者ID:PMX10,项目名称:projects,代码行数:30,代码来源:logo_parser.py

示例15: lose

 def lose(self):
   for period in self._periods:
     period.stop()
     del period
   
   del self.buffer
   self.buffer = Buffer()
   
   return self.loseConnection()
开发者ID:udoprog,项目名称:metap2p,代码行数:9,代码来源:session.py


注:本文中的buffer.Buffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。