import collections from extend_me import (ExtensibleType, ExtensibleByHashType) __all__ = ( 'Record', 'RecordRelations', 'ObjectRecords', 'RecordList', 'get_record', 'get_record_list', ) RecordMeta = ExtensibleByHashType._('Record', hashattr='object_name') def get_record(obj, rid, cache=None, context=None): """ Creates new Record instance Use this method to create new records, because of standard object creation bypasses extension's magic. :param Object obj: instance of Object this record is related to :param int rid: ID of database record to fetch data from :param cache: Cache instance. (usualy generated by function empty_cache() :type cache: Cache :param dict context: if specified, then cache's context will be updated
""" self.__services = {} def clean_service_caches(self): """ Clean caches of all services handled by this mananger usualy this should be called on module update, when list of available objects or reports changed """ for service in self.__services.values(): service.clean_cache() def __str__(self): return "<ServiceManager for %s>" % self.client ServiceType = ExtensibleByHashType._('Service', hashattr='name') def get_service_class(name): """ Return service class specified by it's name """ return ServiceType.get_class(name, default=True) @six.python_2_unicode_compatible class ServiceBase(six.with_metaclass(ServiceType, object)): """ Base class for all Services :param service: instance of original service class. must support folowing syntax ``service.service_method(args)``
import six from extend_me import ExtensibleByHashType __all__ = ("get_connector", "get_connector_names", "ConnectorBase") ConnectorType = ExtensibleByHashType._("Connector", hashattr="name") def get_connector(name): """ Return connector specified by it's name """ return ConnectorType.get_class(name) def get_connector_names(): """ Returns list of connector names registered in system """ return ConnectorType.get_registered_names() class ConnectorBase(six.with_metaclass(ConnectorType)): """ Base class for all connectors :param str host: hostname to connect to :param int port: port to connect to :param dict extra_args: extra arguments for specific connector. """ def __init__(self, host, port, extra_args=None): self._host = host self._port = port
# Copyright © 2014-2018 Dmytro Katyukha <*****@*****.**> ####################################################################### # This Source Code Form is subject to the terms of the Mozilla Public # # License, v. 2.0. If a copy of the MPL was not distributed with this # # file, You can obtain one at http://mozilla.org/MPL/2.0/. # ####################################################################### import six from extend_me import ExtensibleByHashType DEFAULT_TIMEOUT = None __all__ = ('get_connector', 'get_connector_names', 'ConnectorBase') ConnectorType = ExtensibleByHashType._('Connector', hashattr='name') def get_connector(name): """ Return connector specified by it's name """ return ConnectorType.get_class(name) def get_connector_names(): """ Returns list of connector names registered in system """ return ConnectorType.get_registered_names() class ConnectorBase(six.with_metaclass(ConnectorType)):
import six from extend_me import ExtensibleByHashType from ..utils import (AttrDict, DirMixIn, preprocess_args, stdcall) __all__ = ('Object', 'get_object') ObjectType = ExtensibleByHashType._('Object', hashattr='name') def get_object(client, name): """ Create new Object instance. :param client: Client instance to bind this object to :type client: Client :param name: name of object. Ex. 'sale.order' :type name: str :return: Created Object instance :rtype: Object """ cls = ObjectType.get_class(name, default=True) return cls(client, name) # TODO: implement clean caches new columns may be defined, when new addon was # installed @six.python_2_unicode_compatible class Object(six.with_metaclass(ObjectType, DirMixIn)): """ Base class for all Objects Provides simple interface to remote osv.osv objects::
import six import abc import numbers import functools import collections from extend_me import (ExtensibleType, ExtensibleByHashType) __all__ = ( 'Record', 'ObjectRecords', 'RecordList', 'get_record', 'get_record_list', ) RecordMeta = ExtensibleByHashType._('Record', hashattr='object_name') def get_record(obj, rid, cache=None, context=None): """ Creates new Record instance Use this method to create new records, because of standard object creation bypasses extension's magic. :param Object obj: instance of Object this record is related to :param int rid: ID of database record to fetch data from :param cache: Cache instance. (usualy generated by function empty_cache() :type cache: Cache :param dict context: if specified, then cache's context will be updated
import six from extend_me import ExtensibleByHashType from ..utils import (AttrDict, DirMixIn) __all__ = ('Object', 'get_object') ObjectType = ExtensibleByHashType._('Object', hashattr='name') def get_object(client, name): """ Create new Object instance. :param client: Client instance to bind this object to :type client: Client :param name: name of object. Ex. 'sale.order' :type name: str :return: Created Object instance :rtype: Object """ cls = ObjectType.get_class(name, default=True) return cls(client, name) @six.python_2_unicode_compatible class Object(six.with_metaclass(ObjectType, DirMixIn)): """ Base class for all Objects
# this class is created. Such classes will be created each time, # service instance is accessed first time. For example, when connecting # we use 'common' service to login to database, and when we access this # service first time, new *_generated* service class created, when next # we access 'object' service, then again new *_generated* class is # created for this 'object' service. But no new user defined classes # created, thus it is possibly leads to dubling of some rpc requests, # such as 'registered_objects'. if not getattr(cls, '_generated', False): ServiceManager.clean_caches() return cls ServiceType = ExtensibleByHashType._('Service', hashattr='name', with_meta=ServiceMetaMixIn) def get_service_class(name): """ Return service class specified by it's name """ return ServiceType.get_class(name, default=True) @six.python_2_unicode_compatible class ServiceBase(six.with_metaclass(ServiceType, object)): """ Base class for all Services :param service: instance of original service class. must support folowing syntax
import six from extend_me import ExtensibleByHashType __all__ = ('get_connector', 'get_connector_names', 'ConnectorBase') ConnectorType = ExtensibleByHashType._('Connector', hashattr='name') def get_connector(name): """ Return connector specified by it's name """ return ConnectorType.get_class(name) def get_connector_names(): """ Returns lisnt of connector names registered in system """ return ConnectorType.get_registered_names() class ConnectorBase(six.with_metaclass(ConnectorType)): """ Base class for all connectors """ def __init__(self, host, port, verbose=False): self.host = host self.port = port self.verbose = verbose def _get_service(self, name): # pragma: no cover raise NotImplementedError