Return protobuf class types from an imported generated module.
775413
def types_from_module(pb_module):
    '''
    
    '''
    types = pb_module.DESCRIPTOR.message_types_by_name
    return [getattr(pb_module, name) for name in types]
702892
def cast(attrs, inputs, proto_obj):
    
    try:
        from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE
    except ImportError:
        raise ImportError("Onnx and protobuf need to be installed. "
                          + "Instructions to install - https://github.com/onnx/onnx")
    new_attrs = translation_utils._fix_attribute_names(attrs, {'to' : 'dtype'})
    new_attrs['dtype'] = TENSOR_TYPE_TO_NP_TYPE[int(new_attrs['dtype'])]
    return 'cast', new_attrs, inputs
391918
def resolve_type(type_name, pyobject):
    
    if '.' not in type_name:
        try:
            return pyobject.get_module().get_scope().get_name(type_name).get_object()
        except Exception:
            pass
    else:
        mod_name, attr_name = type_name.rsplit('.', 1)
        try:
            mod_finder = ScopeNameFinder(pyobject.get_module())
            mod = mod_finder._find_module(mod_name).get_object()
            return mod.get_attribute(attr_name).get_object()
        except Exception:
            pass
133476
def setUpImports(self):
        '''
        '''
        i = self.imports
        print >>i, 'from pyremotevbox.ZSI.schema import GED, GTD'
        print >>i, 'from pyremotevbox.ZSI.TCcompound import ComplexType, Struct'

        module = self.getTypesModuleName()
        package = self.getTypesModulePath()
        if package:
            module = '%s.%s' %(package, module)
            
        print >>i, 'from %s import *' %(module)
            
        print >>i, 'from %s import %s' %(self.base_module_name, self.base_class_name)
262107
def _GetNestedDict(self, value):
    """"""
    row = {}
    for type_info in value.__class__.type_infos:
      # We only expect the metadata proto to be included as ProtoEmbedded.
      if type_info.__class__.__name__ == "ProtoEmbedded":
        row[type_info.name] = self._GetNestedDict(value.Get(type_info.name))
      else:
        row[type_info.name] = utils.SmartStr(value.Get(type_info.name))

    return row
30053
def import_class(import_str):
    """"""
    mod_str, _sep, class_str = import_str.rpartition('.')
    try:
        __import__(mod_str)
        return getattr(sys.modules[mod_str], class_str)
    except (ValueError, AttributeError):
        raise ImportError('Class %s cannot be found (%s)' %
                          (class_str,
                           traceback.format_exception(*sys.exc_info())))
441154
def to_protobuf(self):
        """"""
        self._validate()
        kwargs = {k: _convert(getattr(self, k), 'to_protobuf')
                  for k in self._get_params()}
        return self._protobuf_cls(**kwargs)
758240
def __decl_types(decl):
        """"""
        types = []
        bases = list(decl.__class__.__bases__)
        if 'pygccxml' in decl.__class__.__module__:
            types.append(decl.__class__)
        while bases:
            base = bases.pop()
            if base is declaration.declaration_t:
                continue
            if base is byte_info.byte_info:
                continue
            if base is elaborated_info.elaborated_info:
                continue
            if 'pygccxml' not in base.__module__:
                continue
            types.append(base)
            bases.extend(base.__bases__)
        return types
178417
def _to_protobuf(self):
        
        projection = self._normalize_projection(self._projection)
        orders = self._normalize_orders()
        start_at = self._normalize_cursor(self._start_at, orders)
        end_at = self._normalize_cursor(self._end_at, orders)

        query_kwargs = {
            "select": projection,
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(
                    collection_id=self._parent.id
                )
            ],
            "where": self._filters_pb(),
            "order_by": orders,
            "start_at": _cursor_pb(start_at),
            "end_at": _cursor_pb(end_at),
        }
        if self._offset is not None:
            query_kwargs["offset"] = self._offset
        if self._limit is not None:
            query_kwargs["limit"] = wrappers_pb2.Int32Value(value=self._limit)

        return query_pb2.StructuredQuery(**query_kwargs)
604512
def get_types(func):
    
    return _get_types(func, util.is_classmethod(func), util.is_method(func))
664947
def to_protobuf(self):
        
        key = _entity_pb2.Key()
        key.partition_id.project_id = self.project

        if self.namespace:
            key.partition_id.namespace_id = self.namespace

        for item in self.path:
            element = key.path.add()
            if "kind" in item:
                element.kind = item["kind"]
            if "id" in item:
                element.id = item["id"]
            if "name" in item:
                element.name = item["name"]

        return key
615965
def parse_protobuf(self, proto_type):
        """"""
        if 'protobuf' not in self.environ.get('CONTENT_TYPE', ''):
            raise BadRequest('Not a Protobuf request')

        obj = proto_type()
        try:
            obj.ParseFromString(self.data)
        except Exception:
            raise BadRequest("Unable to parse Protobuf request")

        # Fail if not all required fields are set
        if self.protobuf_check_initialization and not obj.IsInitialized():
            raise BadRequest("Partial Protobuf request")

        return obj
46270
def get_injected_modules(classname):
    
    """
    modname_list = __CLASSNAME_CLASSKEY_REGISTER__[classname]

    injected_modules = []
    for modstr in modname_list:
        parts = modstr.split('.')
        pkgname = '.'.join(parts[:-1])
        modname = parts[-1]
        try:
            exec('from %s import %s' % (pkgname, modname, ), globals(), locals())
            module = eval(modname)
            injected_modules.append(module)
        except ImportError as ex:
            ut.printex(ex, 'Cannot load package=%r, module=%r' % (pkgname, modname, ))
    return injected_modules
1037840
def get_type(name, library):
        
        if name == None:
            raise Exception("Class name cannot be null")
        if library == None:
            raise Exception("Module name cannot be null")

        try:
            module = importlib.import_module(library)
            return getattr(module, name)
        except:
           return None
860904
def _collect_from_package(self, module,
                              type_checker: Optional[FunctionType] = None,
                              ) -> Dict[str, Any]:
        
        type_checker = type_checker or self.type_check
        members = dict(self._get_members(module, type_checker))

        if pkgutil.get_loader(module).is_package(module.__name__):
            for loader, name, is_pkg in pkgutil.walk_packages(module.__path__):
                child_module_name = f'{module.__package__}.{name}'
                child_module = importlib.import_module(child_module_name)
                for key, obj in self._get_members(child_module, type_checker):
                    if key not in members:
                        members[key] = obj

        return members
1242729
def get_import_for_type(t):
    """"""
    t_as_string = to_str(t)
    if not is_identifier(t_as_string):
        # this class expanded into something other than a single identifier
        # we can ignore it.  This is the case when we encounter something
        # like the configman.converter.str_to_classes_in_namespaces
        # InnerClassList.  We can safely ignore these things here.
        return (None, None)
    if '.' in t_as_string:
        parts = t_as_string.split('.')
        return ('.'.join(parts[:-1]), parts[-1])
    else:
        if t_as_string in known_mapping_str_to_type:
            return (None, None)
        return (None, t_as_string)
259653
def db_type(cls, dtype):
        """"""
        if isinstance(dtype, ExtensionDtype):
            return cls.type_map.get(dtype.kind)
        elif hasattr(dtype, 'char'):
            return cls.type_map.get(dtype.char)