def rowsBetween(self, start, end):
"""
Defines the frame boundaries, from `start` (inclusive) to `end` (inclusive).
Both `start` and `end` are relative positions from the current row.
For example, "0" means "current row", while "-1" means the row before
the current row, and "5" means the fifth row after the current row.
We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,
and ``Window.currentRow`` to specify special boundary values, rather than using integral
values directly.
:param start: boundary start, inclusive.
The frame is unbounded if this is ``Window.unboundedPreceding``, or
any value less than or equal to max(-sys.maxsize, -9223372036854775808).
:param end: boundary end, inclusive.
The frame is unbounded if this is ``Window.unboundedFollowing``, or
any value greater than or equal to min(sys.maxsize, 9223372036854775807).
"""
if start <= Window._PRECEDING_THRESHOLD:
start = Window.unboundedPreceding
if end >= Window._FOLLOWING_THRESHOLD:
end = Window.unboundedFollowing
return WindowSpec(self._jspec.rowsBetween(start, end))
python类maxsize()的实例源码
def rangeBetween(self, start, end):
"""
Defines the frame boundaries, from `start` (inclusive) to `end` (inclusive).
Both `start` and `end` are relative from the current row. For example,
"0" means "current row", while "-1" means one off before the current row,
and "5" means the five off after the current row.
We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,
and ``Window.currentRow`` to specify special boundary values, rather than using integral
values directly.
:param start: boundary start, inclusive.
The frame is unbounded if this is ``Window.unboundedPreceding``, or
any value less than or equal to max(-sys.maxsize, -9223372036854775808).
:param end: boundary end, inclusive.
The frame is unbounded if this is ``Window.unboundedFollowing``, or
any value greater than or equal to min(sys.maxsize, 9223372036854775807).
"""
if start <= Window._PRECEDING_THRESHOLD:
start = Window.unboundedPreceding
if end >= Window._FOLLOWING_THRESHOLD:
end = Window.unboundedFollowing
return WindowSpec(self._jspec.rangeBetween(start, end))
def simplepip(data, k, distance_function=vertical_distance):
ret = []
for (idx, value) in enumerate(data):
ret.append(value)
if len(ret) <= k:
continue
miniv = sys.maxsize
minij = 0
for j in range(1, len(ret) - 1):
d = distance_function(ret[j - 1], ret[j], ret[j + 1])
if d < miniv:
miniv = d
minij = j
del ret[minij]
return ret
def create_pdfs(self):
'''
generate PDF files based on Help Center articles and metadata
'''
# make PDFs for each category except blacklisted categories
self.blacklist_categories = DATA_CONFIG['category_blacklist_for_pdfs']
# set these to 1 or 2 for testing
self.max_section_count = sys.maxsize
self.max_article_count = sys.maxsize
self.json_packager = ZendeskJsonPackager()
self.json_packager.make_directory("gen")
self.json_packager.make_directory("gen/pdf")
self.json_packager.package_zendesk_for_gengo_localization()
self.create_pdf_files()
def __getitem__(self, i):
if isinstance(i, slice):
start = i.start or 0
stop = i.stop
db = self.db
if start < 0:
pos0 = '(%s - %d)' % (self.len(), abs(start) - 1)
else:
pos0 = start + 1
maxint = sys.maxint if PY2 else sys.maxsize
if stop is None or stop == maxint:
length = self.len()
elif stop < 0:
length = '(%s - %d - %s)' % (self.len(), abs(stop) - 1, pos0)
else:
length = '(%s - %s)' % (stop + 1, pos0)
return Expression(db, self._dialect.substring,
self, (pos0, length), self.type)
else:
return self[i:i + 1]
def __getitem__(self, item):
if self._cache_complete:
return self._cache[item]
elif isinstance(item, slice):
if item.step and item.step < 0:
return list(iter(self))[item]
else:
return list(itertools.islice(self,
item.start or 0,
item.stop or sys.maxsize,
item.step or 1))
elif item >= 0:
gen = iter(self)
try:
for i in range(item+1):
res = advance_iterator(gen)
except StopIteration:
raise IndexError
return res
else:
return list(iter(self))[item]
def test_uint64(self):
if sys.maxsize != (1 << 63)-1:
py.test.skip('64 bit only')
if IS_PYPY and sys.pypy_version_info < (5, 6):
py.test.skip('Broken on PyPy<5.6')
#
buf = struct.pack('Q', sys.maxsize)
val = unpack_primitive(ord('Q'), buf, 0)
assert val == sys.maxsize
assert type(val) is int
#
buf = struct.pack('Q', sys.maxsize+1)
val = unpack_primitive(ord('Q'), buf, 0)
assert val == sys.maxsize+1
if six.PY3:
assert type(val) is int
else:
assert type(val) is long
def test_uint64(self):
if sys.maxsize != (1 << 63)-1:
pytest.skip('64 bit only')
if IS_PYPY and sys.pypy_version_info < (5, 6):
pytest.skip('Broken on PyPy<5.6')
#
buf = struct.pack('QQ', sys.maxsize, sys.maxsize+1)
s = BaseSegment(buf)
#
val = s.read_uint64_magic(0)
assert val == sys.maxsize == s.read_uint64(0)
assert type(val) is int
#
val = s.read_primitive(0, ord('Q'))
assert val == sys.maxsize == s.read_uint64(0)
assert type(val) is int
#
val = s.read_uint64_magic(8)
assert val == sys.maxsize+1 == s.read_uint64(8)
if PY3:
assert type(val) is int
else:
assert type(val) is long
def __getitem__(self, item):
if self._cache_complete:
return self._cache[item]
elif isinstance(item, slice):
if item.step and item.step < 0:
return list(iter(self))[item]
else:
return list(itertools.islice(self,
item.start or 0,
item.stop or sys.maxsize,
item.step or 1))
elif item >= 0:
gen = iter(self)
try:
for i in range(item+1):
res = advance_iterator(gen)
except StopIteration:
raise IndexError
return res
else:
return list(iter(self))[item]
def typeoffsetof(self, BType, fieldname, num=0):
if isinstance(fieldname, str):
if num == 0 and issubclass(BType, CTypesGenericPtr):
BType = BType._BItem
if not issubclass(BType, CTypesBaseStructOrUnion):
raise TypeError("expected a struct or union ctype")
BField = BType._bfield_types[fieldname]
if BField is Ellipsis:
raise TypeError("not supported for bitfields")
return (BField, BType._offsetof(fieldname))
elif isinstance(fieldname, (int, long)):
if issubclass(BType, CTypesGenericArray):
BType = BType._CTPtr
if not issubclass(BType, CTypesGenericPtr):
raise TypeError("expected an array or ptr ctype")
BItem = BType._BItem
offset = BItem._get_size() * fieldname
if offset > sys.maxsize:
raise OverflowError
return (BItem, offset)
else:
raise TypeError(type(fieldname))
def cgfloat():
''' Get the appropriate value for a float. '''
return c_double if maxsize > 2 ** 32 else c_float
def arch():
''' Detect OS architecture.
Returns an int: 32 or 64
'''
return 64 if maxsize > 2 ** 32 else 32
def test_add_offset(self):
topic_1 = uuidutils.generate_uuid()
partition_1 = random.randint(0, 1024)
until_offset_1 = random.randint(0, sys.maxsize)
from_offset_1 = random.randint(0, sys.maxsize)
app_name_1 = uuidutils.generate_uuid()
offset_key_1 = "%s_%s_%s" % (app_name_1, topic_1, partition_1)
my_batch_time = self.get_dummy_batch_time()
used_values = {}
self.kafka_offset_specs.add(topic=topic_1, partition=partition_1,
app_name=app_name_1,
from_offset=from_offset_1,
until_offset=until_offset_1,
batch_time_info=my_batch_time)
used_values[offset_key_1] = {
"topic": topic_1, "partition": partition_1, "app_name": app_name_1,
"from_offset": from_offset_1, "until_offset": until_offset_1
}
kafka_offset_specs = self.kafka_offset_specs.get_kafka_offsets(
app_name_1)
offset_value_1 = kafka_offset_specs.get(offset_key_1)
self.assertions_on_offset(used_value=used_values.get(offset_key_1),
offset_value=offset_value_1)
def test_update_offset_values(self):
topic_1 = uuidutils.generate_uuid()
partition_1 = random.randint(0, 1024)
until_offset_1 = random.randint(0, sys.maxsize)
from_offset_1 = random.randint(0, sys.maxsize)
app_name_1 = uuidutils.generate_uuid()
offset_key_1 = "%s_%s_%s" % (app_name_1, topic_1, partition_1)
my_batch_time = self.get_dummy_batch_time()
self.kafka_offset_specs.add(topic=topic_1, partition=partition_1,
app_name=app_name_1,
from_offset=from_offset_1,
until_offset=until_offset_1,
batch_time_info=my_batch_time)
until_offset_2 = random.randint(0, sys.maxsize)
while until_offset_2 == until_offset_1:
until_offset_2 = random.randint(0, sys.maxsize)
from_offset_2 = random.randint(0, sys.maxsize)
while from_offset_2 == from_offset_1:
from_offset_2 = random.randint(0, sys.maxsize)
self.kafka_offset_specs.add(topic=topic_1, partition=partition_1,
app_name=app_name_1,
from_offset=from_offset_2,
until_offset=until_offset_2,
batch_time_info=my_batch_time)
kafka_offset_specs = self.kafka_offset_specs.get_kafka_offsets(
app_name_1)
updated_offset_value = kafka_offset_specs.get(offset_key_1)
self.assertEqual(from_offset_2, updated_offset_value.get_from_offset())
self.assertEqual(until_offset_2,
updated_offset_value.get_until_offset())
def test_get_most_recent_batch_time(self):
filename = '%s.json' % str(uuid.uuid4())
file_path = os.path.join(self.test_resources_path, filename)
json_offset_specs = JSONOffsetSpecs(
path=self.test_resources_path,
filename=filename
)
app_name = "mon_metrics_kafka"
topic_1 = str(uuid.uuid4())
partition_1 = 0
until_offset_1 = random.randint(0, sys.maxsize)
from_offset_1 = random.randint(0, sys.maxsize)
my_batch_time = self.get_dummy_batch_time()
json_offset_specs.add(topic=topic_1, partition=partition_1,
app_name=app_name,
from_offset=from_offset_1,
until_offset=until_offset_1,
batch_time_info=my_batch_time)
most_recent_batch_time = (
json_offset_specs.get_most_recent_batch_time_from_offsets(
app_name, topic_1))
self.assertEqual(most_recent_batch_time, my_batch_time)
os.remove(file_path)
def _is_running_32bit():
return sys.maxsize == 2147483647
def pseudo_tempname(self):
"""Return a pseudo-tempname base in the install directory.
This code is intentionally naive; if a malicious party can write to
the target directory you're already in deep doodoo.
"""
try:
pid = os.getpid()
except Exception:
pid = random.randint(0, sys.maxsize)
return os.path.join(self.install_dir, "test-easy-install-%s" % pid)
def _hash(self):
"""Compute the hash value of a set.
Note that we don't define __hash__: not all sets are hashable.
But if you define a hashable set type, its __hash__ should
call this function.
This must be compatible __eq__.
All sets ought to compare equal if they contain the same
elements, regardless of how they are implemented, and
regardless of the order of the elements; so there's not much
freedom for __eq__ or __hash__. We match the algorithm used
by the built-in frozenset type.
"""
MAX = sys.maxsize
MASK = 2 * MAX + 1
n = len(self)
h = 1927868237 * (n + 1)
h &= MASK
for x in self:
hx = hash(x)
h ^= (hx ^ (hx << 16) ^ 89869747) * 3644798167
h &= MASK
h = h * 69069 + 907133923
h &= MASK
if h > MAX:
h -= MASK + 1
if h == -1:
h = 590923713
return h
def count(self, sub, start=0, end=_sys.maxsize):
if isinstance(sub, UserString):
sub = sub.data
return self.data.count(sub, start, end)
def endswith(self, suffix, start=0, end=_sys.maxsize):
return self.data.endswith(suffix, start, end)