本文整理汇总了Python中monte.runtime.base.typecheck函数的典型用法代码示例。如果您正苦于以下问题:Python typecheck函数的具体用法?Python typecheck怎么用?Python typecheck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typecheck函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: removeSlice
def removeSlice(self, start, bound):
start = typecheck(start, Integer)
bound = typecheck(bound, Integer)
if not 0 <= start.n < len(self.l):
raise IndexError(start)
if not 0 <= bound.n <= len(self.l):
raise IndexError(bound)
del self.l[start.n:bound.n]
return null
开发者ID:geraldstanje,项目名称:monte,代码行数:9,代码来源:tables.py
示例2: __init__
def __init__(self, uri, isOneToOne, startLine, startCol,
endLine, endCol):
if (startLine != endLine and isOneToOne):
raise RuntimeError("one-to-one spans must be on a line")
self.uri = uri
self._isOneToOne = isOneToOne
self.startLine = typecheck(startLine, Integer)
self.startCol = typecheck(startCol, Integer)
self.endLine = typecheck(endLine, Integer)
self.endCol = typecheck(endCol, Integer)
开发者ID:geraldstanje,项目名称:monte,代码行数:10,代码来源:data.py
示例3: setSlice
def setSlice(self, start, bound, other):
other = typecheck(other, (ConstList, FlexList))
start = typecheck(start, Integer)
bound = typecheck(bound, Integer)
if not 0 <= start.n < len(self.l):
raise IndexError(start)
if not 0 <= bound.n <= len(self.l):
raise IndexError(bound)
contents = other.l
if self.valueGuard is not None:
contents = [self.valueGuard.coerce(x, null) for x in contents]
self.l[start.n:bound.n] = contents
return null
开发者ID:geraldstanje,项目名称:monte,代码行数:13,代码来源:tables.py
示例4: extend
def extend(self, other):
contents = typecheck(other, (ConstList, FlexList)).l
contents = other.l
if self.valueGuard is not None:
contents = [self.valueGuard.coerce(x, null) for x in contents]
self.l.extend(contents)
return null
开发者ID:geraldstanje,项目名称:monte,代码行数:7,代码来源:tables.py
示例5: slice
def slice(self, start, end=None):
from monte.runtime.tables import ConstList
start = typecheck(start, Integer)
startn = start.n
if end is not None and not isinstance(end, Integer):
raise RuntimeError("%r is not an integer" % (end,))
elif end is not None:
endn = end.n
else:
endn = self.size().n
if startn < 0:
raise RuntimeError("Slice indices must be positive")
if end is not None and endn < 0:
raise RuntimeError("Slice indices must be positive")
if (startn == endn):
return theEmptyTwine
leftIdx, leftOffset = self.getPartAt(start).l
rightIdx, rightOffset = self.getPartAt(Integer(endn - 1)).l
if leftIdx.n == rightIdx.n:
return self.parts.l[leftIdx.n].slice(leftOffset,
Integer(rightOffset.n + 1))
left = self.parts.l[leftIdx.n]
middle = self.parts.l[leftIdx.n + 1:rightIdx.n]
right = self.parts.l[rightIdx.n].slice(Integer(0),
Integer(rightOffset.n + 1))
result = (left.slice(leftOffset, left.size())
.add(theTwineMaker.fromParts(ConstList(middle)))
.add(right))
return result
开发者ID:geraldstanje,项目名称:monte,代码行数:29,代码来源:data.py
示例6: replace
def replace(self, old, new):
old = typecheck(old, Twine)
new = typecheck(new, Twine)
result = theEmptyTwine
oldLen = old.size().n
if oldLen == 0:
raise RuntimeError("can't replace the null string")
p1 = 0
p2 = self.indexOf(old).n
while p2 != -1:
left = self.slice(Integer(p1), Integer(p2))
chunk = self.slice(Integer(p2), Integer(p2 + oldLen))
result = result.add(left).add(chunk.infect(new, false))
p1 = p2 + oldLen
p2 = self.indexOf(old, Integer(p1)).n
result = result.add(self.slice(Integer(p1), self.size()))
return result
开发者ID:geraldstanje,项目名称:monte,代码行数:17,代码来源:data.py
示例7: insert
def insert(self, idx, value):
idx = typecheck(idx, Integer)
if not 0 <= idx.n < len(self.l):
raise IndexError(idx)
if self.valueGuard is not None:
value = self.valueGuard.coerce(value, null)
self.l.insert(idx, value)
return null
开发者ID:geraldstanje,项目名称:monte,代码行数:8,代码来源:tables.py
示例8: _m_with
def _m_with(self, *a):
if len(a) == 1:
return ConstList(tuple(self.l) + (a[0],))
elif len(a) == 2:
i = typecheck(a[0], Integer).n
return ConstList(tuple(self.l[:i]) + (a[1],) + tuple(self.l[i:]))
else:
raise RuntimeError("with() takes 1 or 2 arguments")
开发者ID:geraldstanje,项目名称:monte,代码行数:8,代码来源:tables.py
示例9: _m_or
def _m_or(self, behind):
behind = typecheck(behind, (ConstMap, FlexMap))
if len(self.d) == 0:
return behind.snapshot()
elif len(behind.d) == 0:
return self.snapshot()
flex = behind.diverge()
flex.putAll(self)
return flex.snapshot()
开发者ID:geraldstanje,项目名称:monte,代码行数:9,代码来源:tables.py
示例10: butNot
def butNot(self, mask):
mask = typecheck(mask, (ConstMap, FlexMap))
if len(self.d) == 0:
return ConstMap({})
elif len(mask.d) == 0:
return self.snapshot()
flex = self.diverge()
flex.removeKeys(mask)
return flex.snapshot()
开发者ID:geraldstanje,项目名称:monte,代码行数:9,代码来源:tables.py
示例11: listSplitter
def listSplitter(specimen, ej):
specimen = typecheck(specimen, (ConstList, FlexList))
if len(specimen.l) < cut:
throw.eject(
ej, "A %s size list doesn't match a >= %s size list pattern"
% (len(specimen), cut))
vals = list(specimen.l[:cut])
vals.append(ConstList(specimen.l[cut:]))
return ConstList(vals)
开发者ID:froztbyte,项目名称:monte,代码行数:9,代码来源:helpers.py
示例12: add
def add(self, other):
from monte.runtime.tables import ConstList
other = typecheck(other, Twine)
mine = self.getParts().l
his = other.getParts().l
if len(mine) > 1 and len(his) > 1:
# Smush the last and first segments together, if they'll fit.
mine = mine[:-1] + mine[-1]._m_mergedParts(his[0]).l
his = his[1:]
return theTwineMaker.fromParts(ConstList(mine + his))
开发者ID:geraldstanje,项目名称:monte,代码行数:10,代码来源:data.py
示例13: spanCover
def spanCover(a, b):
"""
Create a new SourceSpan that covers spans `a` and `b`.
"""
if a is null or b is null:
return null
a = typecheck(a, SourceSpan)
b = typecheck(b, SourceSpan)
if a.uri != b.uri:
return null
if (a._isOneToOne is true and b._isOneToOne is true
and a.endLine == b.startLine
and a.endCol.add(Integer(1)) == b.startCol):
# These spans are adjacent.
return SourceSpan(a.uri, true,
a.startLine, a.startCol,
b.endLine, b.endCol)
# find the earlier start point
if a.startLine < b.startLine:
startLine = a.startLine
startCol = a.startCol
elif a.startLine == b.startLine:
startLine = a.startLine
startCol = min(a.startCol, b.startCol)
else:
startLine = b.startLine
startCol = b.startCol
#find the later end point
if b.endLine > a.endLine:
endLine = b.endLine
endCol = b.endCol
elif a.endLine == b.endLine:
endLine = a.endLine
endCol = max(a.endCol, b.endCol)
else:
endLine = a.endLine
endCol = a.endCol
return SourceSpan(a.uri, false, startLine, startCol, endLine, endCol)
开发者ID:geraldstanje,项目名称:monte,代码行数:42,代码来源:data.py
示例14: fromParts
def fromParts(self, parts):
from monte.runtime.tables import ConstList, FlexList
parts = typecheck(parts, (ConstList, FlexList))
if len(parts.l) == 0:
return theEmptyTwine
elif len(parts.l) == 1:
return parts.l[0]
elif all(isinstance(p, String) for p in parts):
return String(u''.join(p.s for p in parts))
else:
return CompositeTwine(parts)
开发者ID:geraldstanje,项目名称:monte,代码行数:11,代码来源:data.py
示例15: op__cmp
def op__cmp(self, other):
other = typecheck(other, (Integer, Float))
#cmp doesn't do NaNs, so
if self.n < other.n:
return Float(-1.0)
elif self.n == other.n:
return Float(0.0)
elif self.n > other.n:
return Float(1.0)
else:
return Float(float('nan'))
开发者ID:geraldstanje,项目名称:monte,代码行数:11,代码来源:data.py
示例16: asFrom
def asFrom(self, origin, startLine=Integer(1), startCol=Integer(0)):
from monte.runtime.tables import ConstList
startLine = typecheck(startLine, Integer)
startCol = typecheck(startCol, Integer)
parts = []
s = self.bare().s
end = len(s)
i = 0
j = s.find(u'\n')
while i < end:
if j == -1:
j = end - 1
endCol = Integer(startCol.n + j - i)
span = SourceSpan(origin, true, startLine, startCol,
startLine, endCol)
parts.append(LocatedTwine(s[i:j + 1], span))
startLine = Integer(startLine.n + 1)
startCol = Integer(0)
i = j + 1
j = s.find(u'\n', i)
return theTwineMaker.fromParts(ConstList(parts))
开发者ID:geraldstanje,项目名称:monte,代码行数:21,代码来源:data.py
示例17: _slice
def _slice(self, start, end=None):
start = typecheck(start, Integer)
start = start.n
if end is not None and not isinstance(end, Integer):
raise RuntimeError("%r is not an integer" % (end,))
elif end is not None:
end = end.n
if start < 0:
raise RuntimeError("Slice indices must be positive")
if end is not None and end < 0:
raise RuntimeError("Slice indices must be positive")
return self.s[start:end]
开发者ID:geraldstanje,项目名称:monte,代码行数:12,代码来源:data.py
示例18: matchBind
def matchBind(self, values, specimen, ej):
#XXX maybe put this on a different object?
specimen = typecheck(specimen, Twine).bare().s
values = typecheck(values, (ConstList, FlexList))
values = values.l
i = 0
bindings = []
for n in range(len(self.segments)):
typ, val = self.segments[n]
if typ is LITERAL:
j = i + len(val)
if specimen[i:j] != val:
throw.eject(ej, "expected %r..., found %r" % (
val, specimen[i:j]))
elif typ is VALUE_HOLE:
s = values[val]
s = typecheck(s, String).bare().s
j = i + len(s)
if specimen[i:j] != s:
throw.eject(ej, "expected %r... ($-hole %s), found %r" % (
s, val, specimen[i:j]))
elif typ is PATTERN_HOLE:
nextVal = None
if n == len(self.segments) - 1:
bindings.append(String(specimen[i:]))
continue
nextType, nextVal = self.segments[n + 1]
if nextType is VALUE_HOLE:
nextVal = typecheck(values[nextVal], Twine).bare().s
elif nextType is PATTERN_HOLE:
bindings.append(String(u""))
continue
j = specimen.find(nextVal, i)
if j == -1:
throw.eject(ej, "expected %r..., found %r" % (
nextVal,
specimen[i:]))
bindings.append(String(specimen[i:j]))
i = j
return ConstList(bindings)
开发者ID:froztbyte,项目名称:monte,代码行数:40,代码来源:text.py
示例19: infect
def infect(self, other, oneToOne=false):
other = typecheck(other, Twine)
if oneToOne is true:
if self.size() == other.size():
return self._m_infectOneToOne(other)
else:
raise RuntimeError("%r and %r must be the same size" %
(other, self))
else:
span = self.getSpan()
if span is not null:
span = span.notOneToOne()
return theTwineMaker.fromString(other, span)
开发者ID:geraldstanje,项目名称:monte,代码行数:13,代码来源:data.py
示例20: getPartAt
def getPartAt(self, pos):
from monte.runtime.tables import ConstList
pos = typecheck(pos, Integer)
if pos.n < 0:
raise RuntimeError("Index out of bounds")
parts = self.getParts().l
sofar = 0
for (i, atom) in enumerate(parts):
siz = atom.size()
if pos.n < sofar + siz.n:
return ConstList([Integer(i), Integer(pos.n - sofar)])
sofar += siz.n
raise RuntimeError("%s not in 0..!%s" % (pos.n, sofar))
开发者ID:geraldstanje,项目名称:monte,代码行数:13,代码来源:data.py
注:本文中的monte.runtime.base.typecheck函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论