Specify a class invariant described by `description` and tested
    by `predicate`.
342578
def invariant(arg1, arg2=None):
    

    desc = ""
    predicate = lambda x: x

    if isinstance(arg1, str):
        desc = arg1
        predicate = arg2
    else:
        desc = get_function_source(arg1)
        predicate = arg1

    def invariant(c):
        def check(name, func):
            exceptions = ("__getitem__", "__setitem__", "__lt__", "__le__", "__eq__",
                          "__ne__", "__gt__", "__ge__", "__init__")

            if name.startswith("__") and name.endswith("__") and name not in exceptions:
                return False

            if not ismethod(func) and not isfunction(func):
                return False

            if getattr(func, "__self__", None) is c:
                return False

            return True

        class InvariantContractor(c):
            pass

        for name, value in [(name, getattr(c, name)) for name in dir(c)]:
            if check(name, value):
                setattr(InvariantContractor, name,
                        condition(desc, predicate, name != "__init__", True, True)(value))
        return InvariantContractor
    return invariant
1040559
def description(self):
        """"""
        for e in self:
            if isinstance(e, Description):
                return e.value
        raise NoSuchAnnotation
859704
def description(self, description):
        

        if description is None:
            raise ValueError("Invalid value for `description`, must not be `None`")
        if len(description) > 100:
            raise ValueError("Invalid value for `description`, length must be less than `100`")
        if len(description) < 1:
            raise ValueError("Invalid value for `description`, length must be greater than or equal to `1`")

        self._description = description
233235
def describe(self):
        
        result = {}
        #Because we created an Instance object, we already know that this object
        #is not one of the regular built-in types (except, perhaps, for list,
        #dict and set objects that can have their tracking turned on).

        #For objects that are instantiated by the user in __main__, we will
        #already have a paper trail that shows exactly how it was done; but for
        #these, we have to rely on human-specified descriptions.
        from acorn.logging.descriptors import describe
        return describe(self.obj)
499623
def preformat_plain_description(testcase):
    """"""
    description = testcase.get("description")

    if not description:
        return

    # naive approach to removing indent from pytest docstrings
    nodeid = testcase.get("nodeid") or ""
    indent = None
    if "::Test" in nodeid:
        indent = 8 * " "
    elif "::test_" in nodeid:
        indent = 4 * " "

    if indent:
        orig_lines = description.split("\n")
        new_lines = []
        for line in orig_lines:
            if line.startswith(indent):
                line = line.replace(indent, "", 1)
            new_lines.append(line)
        description = "\n".join(new_lines)

    testcase["description"] = "<pre>\n{}\n</pre>".format(description)
1251562
def describe(cls) -> None:
        
        max_lengths = []
        for attr_name in cls.attr_names():
            attr_func = "%ss" % attr_name
            attr_list = list(map(str, getattr(cls, attr_func)())) + [attr_name]
            max_lengths.append(max(list(map(len, attr_list))))
        row_format = "{:>%d} | {:>%d} | {:>%d}" % tuple(max_lengths)
        headers = [attr_name.capitalize() for attr_name in cls.attr_names()]
        header_line = row_format.format(*headers)
        output = "Class: %s\n" % cls.__name__
        output += header_line + "\n"
        output += "-"*(len(header_line)) + "\n"
        for item in cls:
            format_list = [str(getattr(item, attr_name))
                           for attr_name in cls.attr_names()]
            output += row_format.format(*format_list) + "\n"
        print(output)
563298
def make_definition_classes(mod):
    """"""
    rootpath = "oandapyV20"
    PTH = "{}.definitions.{}".format(rootpath, mod)

    M = import_module(PTH)
    __ALL__ = []  # construct the __all__ variable
    for cls, cldef in M.definitions.items():

        orig, fiV = next(six.iteritems(cldef))
        fiK = orig.replace('-', '_')
        # create the docstring dynamically
        clsdoc = dyndoc.format(cls=cls,
                               PTH=PTH,
                               mod=mod,
                               firstItem=fiK, orig=orig,
                               firstItemVal=fiV)

        # Since we can't change the docstring afterwards (it's readonly)
        # figure this out before and not during ...
        for K, V in cldef.items():
            attrName = K
            if "-" in K:
                attrName = K.replace('-', '_')
                adoc = _doc.format(K, attrName, K)
                clsdoc += adoc

        # the class
        dyncls = type(cls, (object,), {'__doc__': clsdoc})

        definitions = dict()
        for K, V in cldef.items():
            attrName = K
            if "-" in K:
                attrName = K.replace('-', '_')
            setattr(dyncls, attrName, K)  # set as class attributes
            definitions.update({K: V})    # for mapping by __getitem__

        def mkgi():
            def __getitem__(self, definitionID):
                """return description for definitionID."""
                return self._definitions[definitionID]
            return __getitem__

        def mkinit(definitions):
            def __init__(self):
                self._definitions = definitions

            return __init__

        def mkPropDefinitions():
            def definitions(self):
                """readonly property holding definition dict."""
                return self._definitions
            return property(definitions)

        setattr(dyncls, "__getitem__", mkgi())
        setattr(dyncls, "__init__", mkinit(definitions))
        setattr(dyncls, "definitions", mkPropDefinitions())
        setattr(sys.modules["{}.definitions.{}".format(rootpath, mod)],
                cls, dyncls)
        __ALL__.append(cls)

    setattr(sys.modules["{}.definitions.{}".format(rootpath, mod)],
            "__all__", tuple(__ALL__))
1374458
def logical_definitions(self, nid):
        
        ldefs = self.all_logical_definitions
        if ldefs is not None:
            #print("TESTING: {} AGAINST LD: {}".format(nid, str(ldefs)))
            return [x for x in ldefs if x.class_id == nid]
        else:
            return []
48622
def describe(cls, full=False):
    """"""
    divider_double = "=" * 80
    divider_single = "-" * 80
    description = cls.__doc__
    message = []
    message.append(divider_double)
    message.append(cls.__name__ + ':')
    message.append(description)
    if full and cls.post_processors(cls):
        message.append(divider_single)
        message.append("Post processors:")
        message.append(divider_single)
        for processor in cls.post_processors(cls):
            message.append(">" + " " * 3 + processor.__name__ + ':')
            message.append(" " * 4 + processor.__doc__)
            message.append('')
    message.append(divider_double)
    message.append('')
    for line in message:
        print(line)
1234903
def descriptions(cls):
        
        schema = cls.json_get('%s/status/schema' % cls.api_url, empty_key=True,
                              send_key=False)
        descs = {}
        for val in schema['fields']['status']['value']:
            descs.update(val)
        return descs
681552
def get_description(self, obj):
        """"""
        search_description = self.get_model_config_value(obj, 'search_description')

        if not search_description:
            return super().get_description(obj)

        return search_description.format(**obj.__dict__)
1255432
@PublicAPI(usage = ACCESS)
    public static <T> DescribedPredicate<T> is(DescribedPredicate<T> predicate) {
        return predicate.as("is " + predicate.getDescription());
    }
743739
function (description, since) {
			var result = description || "";

			if (since) {
				result += '<br><br><i>Since: ' + since + '.</i>';
			}

			result = this._preProcessLinksInTextBlock(result);
			return result;
		}
912213
def does_match_definition(given, main, secondary):
    """"""
    assert isinstance(secondary, tuple)
    assert len(secondary) == 2  # general solution could be provided
    types = decompose_type(given)

    if isinstance(types[0], main):
        return True

    if len(types) >= 2:
        cond1 = isinstance(types[0], main)
        cond2 = isinstance(types[1], secondary)
        cond3 = isinstance(types[1], main)
        cond4 = isinstance(types[0], secondary)
        if (cond1 and cond2) or (cond3 and cond4):
            return True

        if len(types) >= 3:
            classes = set([tp.__class__ for tp in types[:3]])
            desired = set([main] + list(secondary))
            diff = classes.symmetric_difference(desired)
            if not diff:
                return True
            if len(diff) == 2:
                items = list(diff)
                return (
                    issubclass(
                        items[0], items[1]) or issubclass(items[1], items[0]))
            return False
    else:
        return False
539365
def desc_for(self, obj: Element, doing_descs: bool) -> str:
        
        if obj.description and doing_descs:
            if isinstance(obj, SlotDefinition) and obj.is_a:
                parent = self.schema.slots[obj.is_a]
            elif isinstance(obj, ClassDefinition) and obj.is_a:
                parent = self.schema.classes[obj.is_a]
            else:
                parent = None
            return '' if parent and obj.description == parent.description else obj.description
        return ''
337780
def description(self, value):
        

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "description", value)
        self.__description = value
1022636
def prop_modifier(self, cls: ClassDefinition, slot: SlotDefinition) -> str:
        
        pk = '(pk)' if slot.primary_key else ''
        inherited = slot.name not in cls.slots
        mixin = inherited and slot.name in \
                [mslot.name for mslot in [self.schema.classes[m] for m in cls.mixins]]
        injected = cls.name in self.synopsis.applytos and \
                   slot.name in [aslot.name for aslot in
                                 [self.schema.classes[a] for a in sorted(self.synopsis.applytos[cls.name].classrefs)]]
        return pk + '(a)' if injected else '(m)' if mixin else '(i)' if inherited else ''