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


Python Buffer.pop方法代码示例

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


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

示例1: parse_line

# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import pop [as 别名]
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,代码行数:32,代码来源:logo_parser.py

示例2: __init__

# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import pop [as 别名]

#.........这里部分代码省略.........

    def get(self, vnode, boff):
        """Returns a bytes object for the specified data fragment.
        KeyError if vnode is invalid.
        IndexError if boff is invalid.
        None if the data is inaccessible for some other reason.
        """
        with self.rlock:
            res = self.buf.get(vnode, boff)
            if res is None:
                res = self._fetch_backend(vnode, boff)
        if DEBUG: print("wooram: get: buf[{}:{}]=>len({})".format(vnode,boff,len(res) if res else None), file=sys.stderr)
        return res

    def set(self, vnode, boff, data):
        if len(data) == 0:
            raise ValueError("can't set fragment to empty. Use resize instead.")

        with self.wlock:
            if self.syncing: self.recent.add((vnode, boff))
            self.vtable.change_inode(vnode, boff, len(data))
            self.buf.set(vnode, boff, data)

        if DEBUG: print("wooram: set: buf[{}:{}]<=len({})".format(vnode,boff,len(data) if data else None), file=sys.stderr)

    def new(self):
        return self.vtable.new()

    def delete(self, vnode):
        with self.wlock:
            size = self.num_blocks(vnode)
            if self.syncing:
                self.recent.update((vnode, boff) for boff in range(size))
            self.buf.pop((vnode, boff) for boff in range(size))
            del self.vtable[vnode]

    def resize(self, vnode, size):
        """sets the length in bytes of vnode to the given value."""
        num = math.ceil(size / self.fbsize)
        lbsize = size - self.fbsize*(num-1)
        with self.wlock:
            info = self.vtable.get_info(vnode)
            curnum = len(info.inodes)
            curlbs = info.lbsize
            if num < curnum:
                # truncating
                self.vtable.trunc_inodes(vnode, num)
                if lbsize < self.fbsize:
                    data = self.get(vnode, num-1)[:lbsize]
                    self.set(vnode, num-1, data)
            elif num > curnum:
                # growing
                if curlbs < self.fbsize:
                    # need to pad last block with null bytes
                    data = self.get(vnode, curnum-1) + b'\0'*(self.fbsize - curlbs)
                    assert len(data) == self.fbsize
                    self.set(vnode, curnum-1, data)
                for boff in range(curnum, num-1):
                    self.set(vnode, boff, b'\0'*self.fbsize)
                self.set(vnode, num-1, b'\0'*lbsize)
            elif lbsize != curlbs:
                data = self.get(vnode, num-1)
                if lbsize < curlbs:
                    # truncating last block
                    self.set(vnode, num-1, data[:lbsize])
                else:
开发者ID:oblivisync,项目名称:oblivisync,代码行数:70,代码来源:wooram.py


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