Python types.TypeType() Examples

The following are code examples for showing how to use types.TypeType(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: qgis-wps4server   Author: 3liz   File: __init__.py    GNU General Public License v3.0 6 votes vote down vote up
def addLiteralOutput(self, identifier, title, abstract=None, metadata=[],
                         uoms=(), type=types.IntType, default=None, asReference=False):
        """
        Add new output item of type LiteralValue to this process

        :param identifier: input identifier
        :param title: input title
        :param abstract: input description.
        :param uoms: List of string  value units
        :param type: :class:`types.TypeType` value type, e.g. Integer, String, etc. you
                    can uses the :mod:`types` module of python.
        :param default: default value, if any
        :param metadata: List of additional metadata references. See http://www.opengeospatial.org/standards/common, table 32 on page 65, http://schemas.opengis.net/xlink/1.0.0/xlinks.xsd
        :param asReference: output default asReference
        :returns: :class:`pywps.Process.InAndOutputs.LiteralOutput`
        """

        self.outputs[identifier] = InAndOutputs.LiteralOutput(identifier=identifier,
                                                              title=title, abstract=abstract, metadata=metadata, dataType=type, uoms=uoms, asReference=asReference)

        return self.outputs[identifier] 
Example 2
Project: scanomatic   Author: Scan-o-Matic   File: rpc_client.py    GNU General Public License v3.0 6 votes vote down vote up
def sanitize_communication(obj):

    if isinstance(obj, dict):
        return {str(k): sanitize_communication(v) for k, v in obj.iteritems() if v is not None}
    elif isinstance(obj, list) or isinstance(obj, tuple) or isinstance(obj, set):
        return type(obj)(False if v is None else sanitize_communication(v) for v in obj)
    elif isinstance(obj, enum.Enum):
        return obj.name
    elif isinstance(obj, GeneratorType):
        return tuple(False if v is None else sanitize_communication(v) for v in obj)
    elif obj is None:
        return False
    elif isinstance(obj, TypeType):
        return str(obj)
    else:
        return obj 
Example 3
Project: clues   Author: grycap   File: helpers.py    GNU General Public License v3.0 6 votes vote down vote up
def str_to_class(field):
    container_module = field.strip().split(".")
    module_name = ".".join(container_module[0:-1])
    if module_name == "":
        raise NameError("The class is empty. The format should be <module>.<class>.")

    import importlib
    module = importlib.import_module(module_name)

    class_name = container_module[-1]
    try:
        # identifier = getattr(sys.modules[module_name], class_name)
        identifier = getattr(module, class_name)
    except AttributeError:
        raise NameError("%s doesn't exist." % field)
    if isinstance(identifier, (types.ClassType, types.TypeType)):
        return identifier
    raise TypeError("%s is not a class." % field) 
Example 4
Project: pyebpf   Author: dany74q   File: ebpf_wrapper.py    MIT License 6 votes vote down vote up
def _generate_data_class(self, syscall_args):
        # type: (types.ListType) -> types.TypeType

        """
        Generates a ctypes data-class given the syscall arguments

        :param syscall_args: list - A list of NativeArgument objects, representing syscall arguments
                                    that are passed to our ebpf routine
        :return: ctypes class that the members to copy from our ebpf routine back to user-space
        :rtype: type
        """
        assert_type(types.ListType, syscall_args=syscall_args)
        fields = [(arg.name, arg.ctypes_type) for arg in (self.DEFAULT_DATA_STRUCTURE_MEMBERS + syscall_args)]

        # noinspection PyUnresolvedReferences
        class Data(ct.Structure):
            _fields_ = fields

        self.logger.debug('Generated data class fields: {}'.format(fields))

        return Data

    # noinspection PyTypeChecker 
Example 5
Project: pyebpf   Author: dany74q   File: ebpf_wrapper.py    MIT License 6 votes vote down vote up
def _resolve_ctype(self, type_as_string, type_size):
        # type: (types.StringTypes, types.IntType) -> types.TypeType

        """
        Given a string representing a type, and the type size - resolve a ctypes type

        :param type_as_string: str - A string representing a native type
        :param type_size: The size of the underlying native type
        :return: A ctypes type representing the native type
        :rtype: type
        """
        assert_type(types.StringTypes, type_as_string=type_as_string)
        assert_type(types.IntType, type_size=type_size)

        # Qualifiers are irrelevant
        type_as_string = type_as_string.replace('const', '').strip()

        if NativeArgument.is_native_type_a_string(type_as_string):
            self.logger.debug('Spotted a string - will use an array instead')
            return ct.c_char * self.MAX_ARRAY_SIZE
        else:
            return self.C_TYPE_MAPPING.get(
                type_as_string,
                self.C_TYPE_MAPPING.get(type_size, ct.c_int)
            ) 
Example 6
Project: csh-asterisk   Author: stevenmirabito   File: ami.py    Apache License 2.0 6 votes vote down vote up
def _compile_callback_definition(self, event, function):
        """
        Provides a triple of type, match-criteria, and callback for the given event-identifier and
        function.
        """
        if isinstance(event, types.StringTypes):
            if not event:
                return (_CALLBACK_TYPE_UNIVERSAL, None, function)
            return (_CALLBACK_TYPE_REFERENCE, event, function)
        elif isinstance(event, types.TypeType):
            event_name = _EVENT_REGISTRY_REV.get(event)
            if event_name:
                return (_CALLBACK_TYPE_REFERENCE, event_name, function)
        elif event is None:
            return (_CALLBACK_TYPE_ORPHANED, None, function)
            
        raise ValueError("Attempted to build callback definition using an unsupported identifier") 
Example 7
Project: Project-Altis-Copyright-Proof-Source   Author: CodeAnGo   File: ToonPythonUtil.py    Apache License 2.0 6 votes vote down vote up
def getClassLineage(obj):
    """
    print object inheritance list
    """
    if type(obj) == types.DictionaryType:
        # Just a dictionary, return dictionary
        return [obj]
    elif (type(obj) == types.InstanceType):
        # Instance, make a list with the instance and its class interitance
        return [obj] + getClassLineage(obj.__class__)
    elif ((type(obj) == types.ClassType) or
          (type(obj) == types.TypeType)):
        # Class or type, see what it derives from
        lineage = [obj]
        for c in obj.__bases__:
            lineage = lineage + getClassLineage(c)
        return lineage
    # New FFI objects are types that are not defined.
    # but they still act like classes
    elif hasattr(obj, '__class__'):
        # Instance, make a list with the instance and its class interitance
        return [obj] + getClassLineage(obj.__class__)
    else:
        # Not what I'm looking for
        return [] 
Example 8
Project: pyblish-win   Author: pyblish   File: optparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 9
Project: ngo-addons-backport   Author: camptocamp   File: ir_model.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _get_fields_type(self, cr, uid, context=None):
    # Avoid too many nested `if`s below, as RedHat's Python 2.6
    # break on it. See bug 939653.
    return sorted([(k,k) for k,v in fields.__dict__.iteritems()
                      if type(v) == types.TypeType and \
                         issubclass(v, fields._column) and \
                         v != fields._column and \
                         not v._deprecated and \
                         not issubclass(v, fields.function)]) 
Example 10
Project: LaserTOF   Author: kyleuckert   File: numerictypes.py    MIT License 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 11
Project: octopuscloud   Author: christianbaun   File: xmlmanager.py    Apache License 2.0 5 votes vote down vote up
def _build_query(self, cls, filters, limit, order_by):
        import types
        if len(filters) > 4:
            raise Exception('Too many filters, max is 4')
        parts = []
        properties = cls.properties(hidden=False)
        for filter, value in filters:
            name, op = filter.strip().split()
            found = False
            for property in properties:
                if property.name == name:
                    found = True
                    if types.TypeType(value) == types.ListType:
                        filter_parts = []
                        for val in value:
                            val = self.encode_value(property, val)
                            filter_parts.append("'%s' %s '%s'" % (name, op, val))
                        parts.append("[%s]" % " OR ".join(filter_parts))
                    else:
                        value = self.encode_value(property, value)
                        parts.append("['%s' %s '%s']" % (name, op, value))
            if not found:
                raise Exception('%s is not a valid field' % name)
        if order_by:
            if order_by.startswith("-"):
                key = order_by[1:]
                type = "desc"
            else:
                key = order_by
                type = "asc"
            parts.append("['%s' starts-with ''] sort '%s' %s" % (key, key, type))
        return ' intersection '.join(parts) 
Example 12
Project: Lyff   Author: akashlevy   File: xmlmanager.py    MIT License 5 votes vote down vote up
def _build_query(self, cls, filters, limit, order_by):
        import types
        if len(filters) > 4:
            raise Exception('Too many filters, max is 4')
        parts = []
        properties = cls.properties(hidden=False)
        for filter, value in filters:
            name, op = filter.strip().split()
            found = False
            for property in properties:
                if property.name == name:
                    found = True
                    if types.TypeType(value) == list:
                        filter_parts = []
                        for val in value:
                            val = self.encode_value(property, val)
                            filter_parts.append("'%s' %s '%s'" % (name, op, val))
                        parts.append("[%s]" % " OR ".join(filter_parts))
                    else:
                        value = self.encode_value(property, value)
                        parts.append("['%s' %s '%s']" % (name, op, value))
            if not found:
                raise Exception('%s is not a valid field' % name)
        if order_by:
            if order_by.startswith("-"):
                key = order_by[1:]
                type = "desc"
            else:
                key = order_by
                type = "asc"
            parts.append("['%s' starts-with ''] sort '%s' %s" % (key, key, type))
        return ' intersection '.join(parts) 
Example 13
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: numerictypes.py    GNU General Public License v3.0 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 14
Project: ood   Author: markrcote   File: state.py    MIT License 5 votes vote down vote up
def __init__(self, ood_instance):
        self.ood_instance = ood_instance
        self.controller = self.controller_class(self.ood_instance)
        self.state_map = {member.name: member for name, member
                          in inspect.getmembers(self.module)
                          if isinstance(member, types.TypeType)
                          and issubclass(member, State)
                          and member.name is not None}
        if self.ood_instance.state is None:
            self.go_to_state(self.unknown_state_name) 
Example 15
Project: centreon-discovery   Author: Centreon-Community   File: converters.py    GNU General Public License v2.0 5 votes vote down vote up
def Instance2Str(o, d):

    """

    Convert an Instance to a string representation.  If the __str__()
    method produces acceptable output, then you don't need to add the
    class to conversions; it will be handled by the default
    converter. If the exact class is not found in d, it will use the
    first class it can find for which o is an instance.

    """

    if d.has_key(o.__class__):
        return d[o.__class__](o, d)
    cl = filter(lambda x,o=o:
                type(x) is types.ClassType
                and isinstance(o, x), d.keys())
    if not cl and hasattr(types, 'ObjectType'):
        cl = filter(lambda x,o=o:
                    type(x) is types.TypeType
                    and isinstance(o, x)
                    and d[x] is not Instance2Str,
                    d.keys())
    if not cl:
        return d[types.StringType](o,d)
    d[o.__class__] = d[cl[0]]
    return d[cl[0]](o, d) 
Example 16
Project: rpython-lang-scheme   Author: tomoh1r   File: operation.py    MIT License 5 votes vote down vote up
def canraise(self):
        w_callable = self.args[0]
        if isinstance(w_callable, Constant):
            c = w_callable.value
            if (isinstance(c, (types.BuiltinFunctionType,
                               types.BuiltinMethodType,
                               types.ClassType,
                               types.TypeType)) and
                    c.__module__ in ['__builtin__', 'exceptions']):
                return builtins_exceptions.get(c, [])
        # *any* exception for non-builtins
        return [Exception] 
Example 17
Project: ironpython2   Author: IronLanguages   File: optparse.py    Apache License 2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 18
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: numerictypes.py    MIT License 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 19
Project: cuny-bdif   Author: aristotle-tek   File: xmlmanager.py    MIT License 5 votes vote down vote up
def _build_query(self, cls, filters, limit, order_by):
        import types
        if len(filters) > 4:
            raise Exception('Too many filters, max is 4')
        parts = []
        properties = cls.properties(hidden=False)
        for filter, value in filters:
            name, op = filter.strip().split()
            found = False
            for property in properties:
                if property.name == name:
                    found = True
                    if types.TypeType(value) == list:
                        filter_parts = []
                        for val in value:
                            val = self.encode_value(property, val)
                            filter_parts.append("'%s' %s '%s'" % (name, op, val))
                        parts.append("[%s]" % " OR ".join(filter_parts))
                    else:
                        value = self.encode_value(property, value)
                        parts.append("['%s' %s '%s']" % (name, op, value))
            if not found:
                raise Exception('%s is not a valid field' % name)
        if order_by:
            if order_by.startswith("-"):
                key = order_by[1:]
                type = "desc"
            else:
                key = order_by
                type = "asc"
            parts.append("['%s' starts-with ''] sort '%s' %s" % (key, key, type))
        return ' intersection '.join(parts) 
Example 20
Project: IronHydra   Author: microdee   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 21
Project: air-quick-fix   Author: jamesward   File: __init__.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __call__(self, *args, **kwargs):
        """
        Creates an instance of the klass.

        @return: Instance of C{self.klass}.
        """
        if hasattr(self.klass, '__setstate__') or hasattr(self.klass, '__getstate__'):
            if type(self.klass) is types.TypeType:  # new-style class
                return self.klass.__new__(self.klass)
            elif type(self.klass) is types.ClassType: # classic class
                return util.make_classic_instance(self.klass)

            raise TypeError, 'invalid class type %r' % self.klass

        return self.klass(*args, **kwargs) 
Example 22
Project: mixprint_addons   Author: jeffery9   File: ir_model.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _get_fields_type(self, cr, uid, context=None):
    # Avoid too many nested `if`s below, as RedHat's Python 2.6
    # break on it. See bug 939653.
    return sorted([(k,k) for k,v in fields.__dict__.iteritems()
                      if type(v) == types.TypeType and \
                         issubclass(v, fields._column) and \
                         v != fields._column and \
                         not v._deprecated and \
                         not issubclass(v, fields.function)]) 
Example 23
Project: PyCasper   Author: calmcl1   File: CasparObjects.py    MIT License 5 votes vote down vote up
def __init__(self, value_type, *args, **kwargs):
        self.store = dict()
        # dict.__init__(dict(), *args, **kwargs)
        self.store.update(*args, **kwargs)

        if isinstance(value_type, TypedDict):
            value_type = TypedDict
        elif not isinstance(value_type, types.TypeType):
            raise TypeError(
                "value_type is not a type, got {arg} instead".format(arg=type(value_type)))

        self._value_type = value_type 
Example 24
Project: Computable   Author: ktraunmueller   File: numerictypes.py    MIT License 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 25
Project: Computable   Author: ktraunmueller   File: wildcard.py    MIT License 5 votes vote down vote up
def is_type(obj, typestr_or_type):
    """is_type(obj, typestr_or_type) verifies if obj is of a certain type. It
    can take strings or actual python types for the second argument, i.e.
    'tuple'<->TupleType. 'all' matches all types.

    TODO: Should be extended for choosing more than one type."""
    if typestr_or_type == "all":
        return True
    if type(typestr_or_type) == types.TypeType:
        test_type = typestr_or_type
    else:
        test_type = typestr2type.get(typestr_or_type, False)
    if test_type:
        return isinstance(obj, test_type)
    return False 
Example 26
Project: Computable   Author: ktraunmueller   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 27
Project: Computable   Author: ktraunmueller   File: pyversion.py    MIT License 5 votes vote down vote up
def sort_list(l, key, reverse=False):
        return l.sort(key=key, reverse=reverse)

# In Python 3.x, all objects are "new style" objects descended from 'type', and
# thus types.ClassType and types.TypeType don't exist anymore.  For
# compatibility, we make sure they still work. 
Example 28
Project: oss-ftp   Author: aliyun   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 29
Project: poker   Author: surgebiswas   File: numerictypes.py    MIT License 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 30
Project: g3ar   Author: VillanCh   File: inspect_utils.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_classes(mod, metaclass=None):
    """"""
    if metaclass == None:
        metaclass = tuple([types.TypeType, types.ClassType])
    for i in get_callables(mod):
        if isinstance(i, metaclass):
            yield i 
Example 31
Project: g3ar   Author: VillanCh   File: inspect_utils.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_classes(mod, metaclass=None):
    """"""
    if metaclass == None:
        metaclass = tuple([types.TypeType, types.ClassType])
    for i in get_callables(mod):
        if isinstance(i, metaclass):
            yield i 
Example 32
Project: python-amazon-product-api   Author: redtoad   File: test_utils.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_load_class(txt, cls):
    loaded = utils.load_class(txt)
    assert isinstance(loaded, TypeType)
    assert loaded == cls 
Example 33
Project: hacker-scripts   Author: restran   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 34
Project: hacker-scripts   Author: restran   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 35
Project: godot-zeronet-plugin   Author: zam-org   File: optparse.py    GNU General Public License v2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 36
Project: godot-zeronet-plugin   Author: zam-org   File: optparse.py    GNU General Public License v2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 37
Project: godot-zeronet-plugin   Author: zam-org   File: optparse.py    GNU General Public License v2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 38
Project: godot-zeronet-plugin   Author: zam-org   File: optparse.py    GNU General Public License v2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 39
Project: godot-zeronet-plugin   Author: zam-org   File: optparse.py    GNU General Public License v2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 40
Project: 3dprinteros-client   Author: panasevychol   File: numerictypes.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 41
Project: 3dprinteros-client   Author: panasevychol   File: numerictypes.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 42
Project: faircoop-market   Author: sarantapichos   File: ir_model.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _get_fields_type(self, cr, uid, context=None):
    # Avoid too many nested `if`s below, as RedHat's Python 2.6
    # break on it. See bug 939653.
    return sorted([(k,k) for k,v in fields.__dict__.iteritems()
                      if type(v) == types.TypeType and \
                         issubclass(v, fields._column) and \
                         v != fields._column and \
                         not v._deprecated and \
                         not issubclass(v, fields.function)]) 
Example 43
Project: ttk   Author: tarsqi   File: make_documentation.py    Apache License 2.0 5 votes vote down vote up
def get_classes(module):
    classes = []
    for (key, val) in module.__dict__.items():
        if type(val) in (ClassType, TypeType):
            # ignore those that do not have the right module mentioned in their
            # dictionary, this also gets rid of things like ListType, which do
            # not have a value for __module__
            if val.__dict__.get('__module__') == module.__name__:
                classes.append(val)
    classes.sort(lambda x, y: cmp(str(x), str(y)))
    return classes 
Example 44
Project: nltk-on-gae   Author: sivu22   File: util.py    Apache License 2.0 5 votes vote down vote up
def usage(obj, selfname='self'):
    import inspect
    str(obj) # In case it's lazy, this will load it.

    if not isinstance(obj, (types.TypeType, types.ClassType)):
        obj = obj.__class__

    print('%s supports the following operations:' % obj.__name__)
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith('_'): continue
        if getattr(method, '__deprecated__', False): continue

        args, varargs, varkw, defaults = inspect.getargspec(method)
        if (args and args[0]=='self' and
            (defaults is None or len(args)>len(defaults))):
            args = args[1:]
            name = '%s.%s' % (selfname, name)
        argspec = inspect.formatargspec(
            args, varargs, varkw, defaults)
        print(textwrap.fill('%s%s' % (name, argspec),
                            initial_indent='  - ',
                            subsequent_indent=' '*(len(name)+5)))

##########################################################################
# IDLE
########################################################################## 
Example 45
Project: linear_neuron   Author: uglyboxer   File: numerictypes.py    MIT License 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 46
Project: KalutClient   Author: TwoUnderscorez   File: optparse.py    Apache License 2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 47
Project: Backend   Author: LockScreen   File: xmlmanager.py    MIT License 5 votes vote down vote up
def _build_query(self, cls, filters, limit, order_by):
        import types
        if len(filters) > 4:
            raise Exception('Too many filters, max is 4')
        parts = []
        properties = cls.properties(hidden=False)
        for filter, value in filters:
            name, op = filter.strip().split()
            found = False
            for property in properties:
                if property.name == name:
                    found = True
                    if types.TypeType(value) == list:
                        filter_parts = []
                        for val in value:
                            val = self.encode_value(property, val)
                            filter_parts.append("'%s' %s '%s'" % (name, op, val))
                        parts.append("[%s]" % " OR ".join(filter_parts))
                    else:
                        value = self.encode_value(property, value)
                        parts.append("['%s' %s '%s']" % (name, op, value))
            if not found:
                raise Exception('%s is not a valid field' % name)
        if order_by:
            if order_by.startswith("-"):
                key = order_by[1:]
                type = "desc"
            else:
                key = order_by
                type = "asc"
            parts.append("['%s' starts-with ''] sort '%s' %s" % (key, key, type))
        return ' intersection '.join(parts) 
Example 48
Project: kinect-2-libras   Author: inessadl   File: optparse.py    Apache License 2.0 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self) 
Example 49
Project: mxnet-lambda   Author: awslabs   File: numerictypes.py    Apache License 2.0 5 votes vote down vote up
def _python_type(t):
        """returns the type corresponding to a certain Python type"""
        if not isinstance(t, _types.TypeType):
            t = type(t)
        return allTypes[_python_types.get(t, 'object_')] 
Example 50
Project: Savethemblobs_app   Author: iApeiron   File: optparse.py    MIT License 5 votes vote down vote up
def _check_type(self):
        if self.type is None:
            if self.action in self.ALWAYS_TYPED_ACTIONS:
                if self.choices is not None:
                    # The "choices" attribute implies "choice" type.
                    self.type = "choice"
                else:
                    # No type given?  "string" is the most sensible default.
                    self.type = "string"
        else:
            # Allow type objects or builtin type conversion functions
            # (int, str, etc.) as an alternative to their names.  (The
            # complicated check of __builtin__ is only necessary for
            # Python 2.1 and earlier, and is short-circuited by the
            # first check on modern Pythons.)
            import __builtin__
            if ( type(self.type) is types.TypeType or
                 (hasattr(self.type, "__name__") and
                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
                self.type = self.type.__name__

            if self.type == "str":
                self.type = "string"

            if self.type not in self.TYPES:
                raise OptionError("invalid option type: %r" % self.type, self)
            if self.action not in self.TYPED_ACTIONS:
                raise OptionError(
                    "must not supply a type for action %r" % self.action, self)