text stringlengths 0 828 |
|---|
3721,"def pclass(self, bases): |
"""""" |
Create a ``pyrsistent.PClass`` subclass representing this class. |
:param tuple bases: Additional base classes to give the resulting |
class. These will appear to the left of ``PClass``. |
"""""" |
def discard_constant_fields(cls, **kwargs): |
def ctor(): |
return super(huh, cls).__new__(cls, **kwargs) |
try: |
return ctor() |
except AttributeError: |
if u""kind"" in kwargs or u""apiVersion"" in kwargs: |
kwargs.pop(""kind"", None) |
kwargs.pop(""apiVersion"", None) |
return ctor() |
raise |
def lt_pclass(self, other): |
if isinstance(other, self.__class__): |
return sorted(self.serialize().items()) < sorted(other.serialize().items()) |
return NotImplemented |
def eq_pclass(self, other): |
if isinstance(other, self.__class__): |
return sorted(self.serialize().items()) == sorted(other.serialize().items()) |
return NotImplemented |
content = { |
attr.name: attr.pclass_field_for_attribute() |
for attr |
in self.attributes |
} |
content[""__doc__""] = nativeString(self.doc) |
content[""serialize""] = _serialize_with_omit |
content[""__new__""] = discard_constant_fields |
content[""__lt__""] = lt_pclass |
content[""__eq__""] = eq_pclass |
content[""__hash__""] = PClass.__hash__ |
content = total_ordering(content) |
huh = type(nativeString(self.name), bases + (PClass,), content) |
return huh" |
3722,"def add_behavior_for_pclass(self, cls): |
"""""" |
Define an additional base class for the Python class created for a |
particular definition. |
:param type cls: The additional base class. Its name must exactly |
match the name of a definition with a version matching this |
object's version. |
:return: ``None`` |
"""""" |
kind = cls.__name__ |
for version in sorted(self.versions): |
try: |
self.spec.add_behavior_for_pclass(self.full_name(version, kind), cls) |
except NoSuchDefinition: |
pass |
else: |
return None |
raise NoSuchDefinition(kind)" |
3723,"def dumps_bytes(obj): |
"""""" |
Serialize ``obj`` to JSON formatted ``bytes``. |
"""""" |
b = dumps(obj) |
if isinstance(b, unicode): |
b = b.encode(""ascii"") |
return b" |
3724,"def native_string_to_bytes(s, encoding=""ascii"", errors=""strict""): |
"""""" |
Ensure that the native string ``s`` is converted to ``bytes``. |
"""""" |
if not isinstance(s, str): |
raise TypeError(""{} must be type str, not {}"".format(s, type(s))) |
if str is bytes: |
# Python 2 |
return s |
else: |
# Python 3 |
return s.encode(encoding=encoding, errors=errors)" |
3725,"def native_string_to_unicode(s, encoding=""ascii"", errors=""strict""): |
"""""" |
Ensure that the native string ``s`` is converted to ``unicode``. |
"""""" |
if not isinstance(s, str): |
raise TypeError(""{} must be type str, not {}"".format(s, type(s))) |
if str is unicode: |
# Python 3 |
return s |
else: |
# Python 2 |
return s.decode(encoding=encoding, errors=errors)" |
3726,"def datetime_handler(x): |
"""""" Allow serializing datetime objects to JSON """""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.