本文整理汇总了Python中monte.runtime.base.typecheck函数的典型用法代码示例。如果您正苦于以下问题:Python typecheck函数的具体用法?Python typecheck怎么用?Python typecheck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typecheck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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")
示例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()
示例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()
示例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)
示例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))
示例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)
示例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)
示例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'))