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


Python bitmath.Byte方法代码示例

本文整理汇总了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) 
开发者ID:tbielawa,项目名称:bitmath,代码行数:22,代码来源:test_to_Type_conversion.py

示例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)) 
开发者ID:tbielawa,项目名称:bitmath,代码行数:19,代码来源:test_init.py

示例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...) 
开发者ID:tbielawa,项目名称:bitmath,代码行数:18,代码来源:test_best_prefix_BASE.py

示例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())) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:test_api.py

示例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(), []) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_ebs.py

示例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,
            ) 
开发者ID:quay,项目名称:quay,代码行数:19,代码来源:errors.py

示例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)) 
开发者ID:LeastAuthority,项目名称:kubetop,代码行数:22,代码来源:_textrenderer.py

示例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,
        ) 
开发者ID:LeastAuthority,项目名称:kubetop,代码行数:26,代码来源:test_textrenderer.py

示例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 
开发者ID:tbielawa,项目名称:bitmath,代码行数:28,代码来源:__init__.py

示例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 
开发者ID:tbielawa,项目名称:bitmath,代码行数:14,代码来源:__init__.py

示例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 
开发者ID:tbielawa,项目名称:bitmath,代码行数:15,代码来源:__init__.py

示例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 
开发者ID:tbielawa,项目名称:bitmath,代码行数:6,代码来源:__init__.py

示例13: _setup

# 需要导入模块: import bitmath [as 别名]
# 或者: from bitmath import Byte [as 别名]
def _setup(self):
        return (2, 0, 'Byte', 'Bytes')

######################################################################
# NIST Prefixes for Byte based types 
开发者ID:tbielawa,项目名称:bitmath,代码行数:7,代码来源:__init__.py

示例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) 
开发者ID:tbielawa,项目名称:bitmath,代码行数:17,代码来源:__init__.py

示例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)) 
开发者ID:tbielawa,项目名称:bitmath,代码行数:43,代码来源:__init__.py


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