本文整理匯總了Python中bitmath.Byte方法的典型用法代碼示例。如果您正苦於以下問題:Python bitmath.Byte方法的具體用法?Python bitmath.Byte怎麽用?Python bitmath.Byte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitmath
的用法示例。
在下文中一共展示了bitmath.Byte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def setUp(self):
self.bit = bitmath.Bit(1)
self.byte = bitmath.Byte(1)
# NIST units
self.kib = bitmath.KiB(1)
self.mib = bitmath.MiB(1)
self.gib = bitmath.GiB(1)
self.tib = bitmath.TiB(1)
self.pib = bitmath.PiB(1)
self.eib = bitmath.EiB(1)
# SI units
self.kb = bitmath.kB(1)
self.mb = bitmath.MB(1)
self.gb = bitmath.GB(1)
self.tb = bitmath.TB(1)
self.pb = bitmath.PB(1)
self.eb = bitmath.EB(1)
self.zb = bitmath.ZB(1)
self.yb = bitmath.YB(1)
示例2: test___init__valid_inputs
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def test___init__valid_inputs(self):
"""__init__: accepts valid inputs"""
inputs = [
# Comments illustrate what the initialization calls look
# like after the interpreter expands all the *arg/**kwarg
# parameters.
#
# All pairs are equivalent to Byte(100) (used in the test
# assertion, below)
((100,), dict()), # Byte(100)
(tuple(), {"value": 100}), # Byte(value=100)
(tuple(), {"bytes": 100}), # Byte(bytes=100)
(tuple(), {"bits": 800}) # Byte(bits=800)
]
for args, kwargs in inputs:
self.assertEqual(bitmath.Byte(*args, **kwargs), bitmath.Byte(100))
示例3: test_best_prefix_negative_less_than_a_byte
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def test_best_prefix_negative_less_than_a_byte(self):
"""best_prefix_base: negative values less than a byte stay as bits"""
# assert that a Byte of -4 bits yields Bit(-4)
bm1 = bitmath.Byte(bits=-4)
expected = bitmath.Bit(-4)
res = bitmath.best_prefix(bm1)
# Verify that best prefix math works for negative numbers
self.assertEqual(res, expected)
# Verify that best prefix guessed the correct type
self.assertIs(type(res), bitmath.Bit)
# For instances where x in set { b | b >= 8 } where b is number of
# bits in an instance:
#
# * bitmath.best_prefix(-10**8) -> MiB(-95.367...)
# * bitmath.best_prefix(10**8) -> MiB(95.367...)
示例4: test_parsenum_all_sizes
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def test_parsenum_all_sizes(self, expr, size):
"""
Send standard size expressions to ``parse_num`` in
many sizes, we expect to get correct size results.
:param expr str: A string representing the size expression
:param size int: A string representing the volume size
"""
if expr is "KB":
expected_size = int(KiB(size).to_Byte())
elif expr is "MB":
expected_size = int(MiB(size).to_Byte())
elif expr is "GB":
expected_size = int(GiB(size).to_Byte())
elif expr is "TB":
expected_size = int(TiB(size).to_Byte())
else:
expected_size = int(Byte(size).to_Byte())
return self.assertEqual(expected_size,
int(parse_num(str(size)+expr).to_Byte()))
示例5: test_foreign_volume
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def test_foreign_volume(self):
"""
``list_volumes`` lists only those volumes
belonging to the current Flocker cluster.
"""
try:
config = get_blockdevice_config()
except InvalidConfig as e:
self.skipTest(str(e))
ec2_client = get_ec2_client_for_test(config)
meta_client = ec2_client.connection.meta.client
requested_volume = meta_client.create_volume(
Size=int(Byte(self.minimum_allocatable_size).to_GiB().value),
AvailabilityZone=ec2_client.zone)
created_volume = ec2_client.connection.Volume(
requested_volume['VolumeId'])
self.addCleanup(created_volume.delete)
_wait_for_volume_state_change(VolumeOperations.CREATE,
created_volume)
self.assertEqual(self.api.list_volumes(), [])
示例6: __init__
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def __init__(self, uploaded=None, max_allowed=None):
detail = {}
message = "Uploaded blob is larger than allowed by this registry"
if uploaded is not None and max_allowed is not None:
detail = {
"reason": "%s is greater than maximum allowed size %s" % (uploaded, max_allowed),
"max_allowed": max_allowed,
"uploaded": uploaded,
}
up_str = bitmath.Byte(uploaded).best_prefix().format("{value:.2f} {unit}")
max_str = bitmath.Byte(max_allowed).best_prefix().format("{value:.2f} {unit}")
message = "Uploaded blob of %s is larger than %s allowed by this registry" % (
up_str,
max_str,
)
示例7: _pod_stats
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def _pod_stats(pod):
cpu = sum(
map(
parse_cpu, (
container["usage"]["cpu"]
for container
in pod["containers"]
),
), 0,
)
mem = sum(
map(
lambda s: parse_memory(s).amount, (
container["usage"]["memory"]
for container
in pod["containers"]
),
), Byte(0),
)
return (_CPU(cpu), _Memory(mem))
示例8: test_render_pod
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def test_render_pod(self):
pod_usage = {
"metadata": {
"name": "foo",
"namespace": "default",
"creationTimestamp": "2017-04-07T15:21:22Z"
},
"timestamp": "2017-04-07T15:21:00Z",
"window": "1m0s",
"containers": [
{
"name": "foo-a",
"usage": {
"cpu": "100m",
"memory": "128Ki"
}
},
]
}
fields = _render_pod(pod_usage, _Memory(Byte(1024 * 1024))).split()
self.assertEqual(
[u'foo', u'10.0', u'128.00', u'KiB', u'12.50'],
fields,
)
示例9: unit
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def unit(self):
"""The string that is this instances prefix unit name in agreement
with this instance value (singular or plural). Following the
convention that only 1 is singular. This will always be the singular
form when :attr:`bitmath.format_plural` is ``False`` (default value).
For example:
>>> KiB(1).unit == 'KiB'
>>> Byte(0).unit == 'Bytes'
>>> Byte(1).unit == 'Byte'
>>> Byte(1.1).unit == 'Bytes'
>>> Gb(2).unit == 'Gbs'
"""
global format_plural
if self.prefix_value == 1:
# If it's a '1', return it singular, no matter what
return self._name_singular
elif format_plural:
# Pluralization requested
return self._name_plural
else:
# Pluralization NOT requested, and the value is not 1
return self._name_singular
示例10: unit_plural
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def unit_plural(self):
"""The string that is an instances prefix unit name in the plural
form.
For example:
>>> KiB(1).unit_plural == 'KiB'
>>> Byte(1024).unit_plural == 'Bytes'
>>> Gb(1).unit_plural == 'Gb'
"""
return self._name_plural
示例11: unit_singular
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def unit_singular(self):
"""The string that is an instances prefix unit name in the singular
form.
For example:
>>> KiB(1).unit_singular == 'KiB'
>>> Byte(1024).unit == 'B'
>>> Gb(1).unit_singular == 'Gb'
"""
return self._name_singular
#: The "prefix" value of an instance
示例12: to_Byte
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def to_Byte(self):
return Byte(self._byte_value / float(NIST_STEPS['Byte']))
# Properties
示例13: _setup
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def _setup(self):
return (2, 0, 'Byte', 'Bytes')
######################################################################
# NIST Prefixes for Byte based types
示例14: getsize
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def getsize(path, bestprefix=True, system=NIST):
"""Return a bitmath instance in the best human-readable representation
of the file size at `path`. Optionally, provide a preferred unit
system by setting `system` to either `bitmath.NIST` (default) or
`bitmath.SI`.
Optionally, set ``bestprefix`` to ``False`` to get ``bitmath.Byte``
instances back.
"""
_path = os.path.realpath(path)
size_bytes = os.path.getsize(_path)
if bestprefix:
return Byte(size_bytes).best_prefix(system=system)
else:
return Byte(size_bytes)
示例15: listdir
# 需要導入模塊: import bitmath [as 別名]
# 或者: from bitmath import Byte [as 別名]
def listdir(search_base, followlinks=False, filter='*',
relpath=False, bestprefix=False, system=NIST):
"""This is a generator which recurses the directory tree
`search_base`, yielding 2-tuples of:
* The absolute/relative path to a discovered file
* A bitmath instance representing the "apparent size" of the file.
- `search_base` - The directory to begin walking down.
- `followlinks` - Whether or not to follow symbolic links to directories
- `filter` - A glob (see :py:mod:`fnmatch`) to filter results with
(default: ``*``, everything)
- `relpath` - ``True`` to return the relative path from `pwd` or
``False`` (default) to return the fully qualified path
- ``bestprefix`` - set to ``False`` to get ``bitmath.Byte``
instances back instead.
- `system` - Provide a preferred unit system by setting `system`
to either ``bitmath.NIST`` (default) or ``bitmath.SI``.
.. note:: This function does NOT return tuples for directory entities.
.. note:: Symlinks to **files** are followed automatically
"""
for root, dirs, files in os.walk(search_base, followlinks=followlinks):
for name in fnmatch.filter(files, filter):
_path = os.path.join(root, name)
if relpath:
# RELATIVE path
_return_path = os.path.relpath(_path, '.')
else:
# REAL path
_return_path = os.path.realpath(_path)
if followlinks:
yield (_return_path, getsize(_path, bestprefix=bestprefix, system=system))
else:
if os.path.isdir(_path) or os.path.islink(_path):
pass
else:
yield (_return_path, getsize(_path, bestprefix=bestprefix, system=system))