本文整理汇总了Python中pulp_rpm.common.version_utils.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __cmp__
def __cmp__(self, other):
"""
Compare a Requirement to any other object that has at least these attributes: name, epoch,
version, and release. This method will return a negative value if self is "less than" other,
0 if they are equal, and a positive value if self is "greater than" other. For example,
a Requirement that references Firefox-23.0 compared to a Unit that references Firefox-23.1
would return a negative value.
The other object must have the same name as the Requirement, as it
doesn't make sense to ask whether an object is greater or less than a Requirement when it
has a different name. For example, a Requirement might reference Firefox-23.0, and other
might be the package openssh-server-6.2. If this Requirement is asked to compare itself with
openssh-server, it will raise ValueError.
:param other: Any object that has the following attributes: name, epoch, version, and
release. An RPM Unit is an example of such an object.
:type other: object
:return: A negative value if self is less than other, 0 if self is equal to other, and
a positive value if self is greater than other.
:rtype: int
"""
mine = [self.epoch, self.version, self.release]
theirs = [other.epoch, other.version, other.release]
# the encode function is rather picky about the type and length of its
# argument, so we only call it for values that we know it will accept
for i, value in enumerate(mine):
if value:
mine[i] = version_utils.encode(str(value))
for i, value in enumerate(theirs):
if value:
theirs[i] = version_utils.encode(str(value))
return cmp(mine, theirs)
示例2: __eq__
def __eq__(self, other):
"""
Return True if self effectively "equals" other, False otherwise. This equality
check will take into account name, epoch, version, and release, allowing the
release to be omitted from either object.
:param other: Any object that has the following attributes: name, epoch, version, and
release. An RPM Unit is an example of such an object.
:type other: object
:return: True if self and other are equal, False otherwise
:rtype: bool
"""
# Simple case, they are entirely different
if self.name != other.name:
return False
# Attempt to compare the version information
mine_version = version_utils.encode(self.version)
mine_release = version_utils.encode(self.release) if self.release else None
mine = [self.epoch, mine_version, mine_release]
theirs_version = version_utils.encode(other.version)
theirs_release = version_utils.encode(other.release) if other.release else None
theirs = [other.epoch, theirs_version, theirs_release]
# Release is optional, so if it's omitted in either case, remove it entirely
# from the check.
if mine[2] is None or theirs[2] is None:
mine = mine[:2]
theirs = theirs[:2]
return mine == theirs
示例3: __init__
def __init__(self, local_vars):
self.metadata = local_vars.get('metadata', {})
for name in self.UNIT_KEY_NAMES:
setattr(self, name, local_vars[name])
# Add the serialized version and release if available
if name == 'version':
self.metadata['version_sort_index'] = version_utils.encode(local_vars[name])
elif name == 'release':
self.metadata['release_sort_index'] = version_utils.encode(local_vars[name])
示例4: _update_type
def _update_type(type_id):
collection = types_db.type_units_collection(type_id)
# Both indexes should be set at the same time, so this single check should be safe
fix_us = collection.find({'version_sort_index' : None})
for package in fix_us:
package['version_sort_index'] = version_utils.encode(package['version'])
package['release_sort_index'] = version_utils.encode(package['release'])
collection.save(package, safe=True)
示例5: pre_save_signal
def pre_save_signal(cls, sender, document, **kwargs):
"""
Generate the version & Release sort index before saving
:param sender: sender class
:type sender: object
:param document: Document that sent the signal
:type document: pulp_rpm.plugins.db.models.NonMetadataPackage
"""
super(NonMetadataPackage, cls).pre_save_signal(sender, document, **kwargs)
document.version_sort_index = version_utils.encode(document.version)
document.release_sort_index = version_utils.encode(document.release)
示例6: assert_greater_than_or_equal
def assert_greater_than_or_equal(self, version1, version2):
encoded1 = encode(version1)
encoded2 = encode(version2)
self.db.insert({'version' : version1, 'version_sort_index' : encoded1}, safe=True)
self.db.insert({'version' : version2, 'version_sort_index' : encoded2}, safe=True)
sorted_versions = self.db.find({}).sort([('version_sort_index', pymongo.DESCENDING)])
msg = '[%s, %s] was less than [%s, %s]' % (version1, encoded1, version2, encoded2)
self.assertEqual(sorted_versions[0]['version'], version1, msg=msg)
self.db.remove() # clean up for multiple calls to this in a single test
示例7: test_non_letter_removal
def test_non_letter_removal(self):
# Each label is separated into a list of maximal alphabetic or numeric sections, with separators
# (non-alphanumeric characters) ignored. So, '2.0.1' becomes ('2', '0', '1'), while
# ('2xFg33.+f.5') becomes ('2', 'xFg', '33', 'f', '5').
#
# Test: Notice that the + is removed, in addition to the splitting apart of numbers and letters.
self.assertEqual(encode('2xFg33.+f.5'), '01-2.$xFg.02-33.$f.01-5')
示例8: test_parse
def test_parse(self):
# Setup
user_input = ['name=foo', 'version=1.0', 'release=2', 'license=GPL']
# Test
parsed = criteria_utils.parse_key_value(user_input)
# Verify
self.assertEqual(4, len(parsed))
parsed.sort(key=lambda x : x[0])
self.assertEqual(parsed[0][0], 'license')
self.assertEqual(parsed[0][1], 'GPL')
self.assertEqual(parsed[1][0], 'name')
self.assertEqual(parsed[1][1], 'foo')
self.assertEqual(parsed[2][0], version_utils.RELEASE_INDEX)
self.assertEqual(parsed[2][1], version_utils.encode('2'))
self.assertEqual(parsed[3][0], version_utils.VERSION_INDEX)
self.assertEqual(parsed[3][1], version_utils.encode('1.0'))
示例9: test_mixed
def test_mixed(self):
# Each label is separated into a list of maximal alphabetic or numeric sections, with separators
# (non-alphanumeric characters) ignored. If there is any extra non-alphanumeric character at the
# end, that. So, '2.0.1' becomes ('2', '0', '1'), while ('2xFg33.+f.5') becomes
# ('2', 'xFg', '33', 'f', '5').
#
# Test: the int segments still need to be encoded as ints as well, hence the 1-1 in the second
# segment.
self.assertEqual(encode('2.1alpha'), '01-2.01-1.$alpha')
示例10: translate
def translate(key_value_tuple):
"""
:param key_value_tuple: single key/value tuple to translate
:return: new key-value tuple to use
"""
for orig_key, translated_key in TRANSLATIONS.items():
if key_value_tuple[0] == orig_key:
encoded_value = version_utils.encode(key_value_tuple[1])
return translated_key, encoded_value
return key_value_tuple
示例11: test_migrate
def test_migrate(self):
# Setup
for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
self.add_sample_data(type_id)
# Test
migration = _import_all_the_way('pulp_rpm.plugins.migrations.0008_version_sort_index')
migration.migrate()
# Verify
# The migration should cover these three types, so make sure they were all included
for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
collection = types_db.type_units_collection(type_id)
test_me = collection.find_one({'version': '1.1'})
self.assertEqual(test_me['version_sort_index'], version_utils.encode('1.1'))
self.assertEqual(test_me['release_sort_index'], version_utils.encode('1.1'))
# Make sure the script didn't run on units that already have the indexes
test_me = collection.find_one({'version': '3.1'})
self.assertEqual(test_me['version_sort_index'], 'fake')
self.assertEqual(test_me['release_sort_index'], 'fake')
示例12: complete_version_serialized
def complete_version_serialized(self):
return tuple(version_utils.encode(field) for field in self.complete_version)
示例13: test_numbers
def test_numbers(self):
self.assertEqual(encode('1.1'), '01-1.01-1')
self.assertEqual(encode('2.3'), '01-2.01-3')
self.assertEqual(encode('3.10'), '01-3.02-10')
self.assertEqual(encode('127.0.0.1'), '03-127.01-0.01-0.01-1')
示例14: test_both
def test_both(self):
self.assertEqual(encode('1.alpha'), '01-1.$alpha')
self.assertEqual(encode('0.2.beta.1'), '01-0.01-2.$beta.01-1')
示例15: test_letters
def test_letters(self):
self.assertEqual(encode('alpha'), '$alpha')
self.assertEqual(encode('beta.gamma'), '$beta.$gamma')