def merge_option(opts: Map, k: str, v): keys = k.split(".") new_keys = [] for value in keys: if value != "": new_keys.append(value) keys = new_keys length = len(keys) last = length - 1 if length > 1: for i in range(length): key = keys[i:i + 1][0] if i < last: if opts.get(key) == None: opts = opts.setdefault(key, Map()) else: opts = opts.get(key) if opts.contains(keys[i + 1:i + 2][0]): if i == last - 1: return else: t = type(opts.get(keys[i + 1:i + 2][0])) if t != Map and t != dict: return else: opts.setdefault(key, v) else: if opts.contains(k) == False: opts.set(k, v)
def find_list(self, query, args=[]): cursor = self.conn.cursor() cursor.execute(query.replace("?", "%s"), args) cols = cursor.description result = Map() result.set("cols", cols) result.set("data", cursor.fetchall()) return result
def new_server_codec(self, sock) -> IServerCodec: m = self.opts.macher if m == None: raise ServerLoadError("no macher!") else: b = get_codec(m) if not b: raise ServerLoadError("init codec builder error!") return b.new_server_codec(s=Channel(id=Guid().string(), sock=sock), opts=Map())
def load(self, force: bool): if self.loaded and not force: return None self.options = Map() """read env source""" self.load_source(self.env) """read file source""" srcs = self.find_file_sources() self.load_source(*srcs) """read self.srcs""" self.load_source(*self.srcs) self.loaded = True
def load(self) -> Map: opts = Map() envs = os.environ for k, v in envs.items(): opt = Option(name=k, value=v) key = opt.name.lower() if self.prefix != None and self.prefix != "": key = key.strip(self.prefix).lower() # key = opt.name.replace("_", ".").lower() # print("key=%s, value=%s" % (key, opt.value)) merge_option(opts, key, opt.value) # print(opts) return opts
def __init__(self): self.loaded: bool = False self.autoLoad: bool = False self.env: EnvSource = EnvSource() self.options: Map = None self.profiles: List[str] = [] self.dirs: List[str] = [] self.name: str = None self.srcs: List[Source] = [] self.defaults: Map = Map()
def __init__( self, name: str = None, provider: str = "mysql" # , address: str="" , max_open_conns: int = 100, max_idle_conns: int = 5, trace=Map(), options=Map()): self.name = name self.provider = provider # self.address = address self.max_open_conns = max_open_conns self.max_idle_conns = max_idle_conns # self.conn_lifetime = conn_lifetime, self.trace = trace self.options = options self.host = "127.0.0.1" self.port = 3306 self.database = "test" self.user = "******" self.password = "******" self.charset = "utf8mb4"
def __init__(self, opts: ServerOptions, registry: Registry = None): self.opts = opts if registry == None: self.registry = DirectRegistry(url=opts.address.url) else: self.registry = registry # 初始化service管理容器 self.services = Map() # 初始化session管理容器 self.sessions = SessionMap() # 初始化编解码器 self.init_codec_builder()
def cover_option(opts: Map, k: str, v): # print("opts=%s, k=%s, v=%s" % (opts, k, v)) # keys = k.split(".") # length = len(keys) # last = length -1 # for i in range(length): # key = keys[i] # if opts.contains(key): # opt = opts.get(key) # t = type(opt) # if t == Map: # pass # elif t == map: # pass # else: # return # if i == last: # opts[key] = v # else: # opts = opts.setdefault(key, Map()) keys = k.split(".") new_keys = [] for value in keys: if value != "": new_keys.append(value) keys = new_keys length = len(keys) last = length - 1 if length > 1: for i in range(length): key = keys[i:i + 1][0] if i < last: if opts.get(key) == None: opts = opts.setdefault(key, Map()) else: opts = opts.get(key) print(opts) else: opts.setdefault(key, v) else: opts.set(k, v)
from typing import List from bee.data.option import Options from bee.data.map import Map from bee.data import const const.codecs = Map() class ReadPeeker(): def read(self, p: bytes) -> int: pass def peek(self, n: int) -> bytes: pass class Stream(ReadPeeker): def id(self) -> str: pass def reader(self): pass def peek(self, n: int) -> bytes: pass def read(self, n: int) -> bytes: pass def read_bytes(self, separator=b'\n') -> bytes:
from bee.data.map import Map m1 = Map(('a', 'b', 'c'), (1, 2, 3)) print(m1.keys()) print(m1.values()) print(m1.items()) print(hasattr(m1, 'a')) print(m1.contains('a')) # m1.remove("a") delattr(m1, "a") print(m1.keys()) m1.empty() print(m1.values()) # print(m1.get(1)) m2 = Map(a=1, b=2) print(m2) # m3 = Map({"a" : 1}) # # print(m3)
def __init__(self): self.sem = BoundedSemaphore(1) self.clients = Map()
def __init__(self, ): self.options = {} self.dbMap = Map()
def set_aliases(self, alias: str = None, key: str = None): if self.aliases == None: self.aliases = Map() self.aliases.set(alias, key)
def call(self, service: str, method: str, args=[]) -> Result: """ class remote method :param service: :param method: :param args: :return: """ print("Node.call(service={}, method={}, args={})".format(service, method, str(args))) try: with self.pool.connection() as client: if not client.is_connected(): client.open() sock = client.socket rh = RequestHead() rh.id = self.count self.count += 1 rh.service = service rh.method = method rh.labels = [] r = Request(head=rh, args=args) cc = self._cb.new_client_codec(s=Channel(id=Guid().string(), sock=sock), opts=Map()) cc.encode(req=r) rh = ResponseHead() cc.decode_head(rh) rt = Result() cc.decode_result(rt) return rt except Exception as e: self.error_count +=1 if (self.error_count >= default_max_error_count): self.report_error() raise CodedError(code=-1, message=e.__str__(), detail=e.__str__())
def __init__(self): self.channels = Map()
from bee.net.rpc.codecs.proto.proto import Builder id = 1 sock = socket.create_connection(address=("127.0.0.1", 8080)); print(sock.closed) while id<5: rh = RequestHead() rh.id = id rh.service = "Test" rh.method = "hello" rh.labels = [Option(name="test", value="test")] r = Request(head=rh, args=["Mr. " + str(id)]) cc = Builder().new_client_codec(s=Channel(id="", sock=sock), opts=Map()) cc.encode(req=r) rh = ResponseHead() cc.decode_head(rh) rt = Result() cc.decode_result(rt) print(rt.value) # length_data = sock.recv(4) # length = int.from_bytes(length_data, byteorder="little") # if length > 0: # data = sock.recv(length) # print(data) id +=1