コード例 #1
0
def menaxhoKlientin(client):
    #Ruan emrin e klientit ne variablen emri
    emri = client.recv(BUFSIZ).decode("utf8")
    #Dergon mesazhin welcome te klienti i sapo lidhur
    welcome = '''Pershendetje %s! Nese doni te mbyllni chat-in, shtypni {quit}. 
    Nese deshironi ndihme per te pare se cilat metoda perkrah, shtyp {help}''' % emri
    client.send(welcome.encode())
    #Transmeton mesazhin te cdo klient i lidhur ne ate moment
    msg = "%s i eshte bashkangjitur chat-it!" % emri
    transmeto(bytes(msg, "utf8"))
    #Shton emrin e klientit ne objectin klientet
    klientet[client] = emri
    #Fillojm nje loop-e me te cilen presim mesazhe dhe i procesojm
    while True:
        #Pranon mesazhin nga kleinti
        msg = client.recv(BUFSIZ)
        #Kontrollon nese eshte i ndryshem nga {quit}
        if msg != bytes("{quit}", "utf8"):
            transmeto(msg, emri + ": ")
            #Dergon mesazhin ne metoden handler e cila e kontrollon mesazhin
            # se cka permban dhe varesisht se a ka ndonje pergjigje serveri e kthen ate
            msg = handler(msg, adresat[client]).encode()
            if msg != "null".encode():
                transmeto(msg, "Serveri: ")
        #Ne te kundert dergon te klienti po te njejtin mesazh
        # dhe transmeton te klientet e tjere mesazhin me emrin + eshte skycur
        else:
            client.send(bytes("{quit}", "utf8"))
            client.close()
            #Largon objektin e klientit
            del klientet[client]
            transmeto(bytes("%s eshte shkycur." % emri, "utf8"))
            break
コード例 #2
0
ファイル: beacon.py プロジェクト: bordicon/vanguard
    def __init__(self, config):
        super(Beacon, self).__init__()
        self.interval = config.beacon.interval
        self.beacon = config.beacon
        self.redis = redis.StrictRedis()
        self.radios = collections.OrderedDict({})

        self.handlers = [handler(config) for handler in self.handler_types]
        for key, radio_config in config.radios.iteritems():
            self.radios[key] = Radio(**radio_config)

        self.recv_timeout = self.interval / len(self.radios)
コード例 #3
0
ファイル: get_title.py プロジェクト: johnnybubonic/OpTools
 def _get_page(self):
     if has_req:
         self.raw = handler.get(self.url).content
     else:
         with handler(self.url) as fh:
             self.raw = fh.read()
     try:
         self.str = self.raw.decode('utf-8')
     except Exception:
         pass
     self.soup = BeautifulSoup(self.str, features=parser)
     return (None)
コード例 #4
0
def threaded(cskt, addr):
    # for each thread(client), creating a new connection to target database.
    try:
        database = sqlite3.connect('ooad.db')
    except:
        print('Database connection failed.')
        exit()
    print('Database is connected!')

    print('Thread is created.' + str(addr))

    while True:
        # receive message from client.
        data = cskt.recv(BUFSIZE)
        # transfrom to dictionary type data.
        dicData = jtod(data)

        action = dicData['Action']
        if action == 'Quit':
            print("%s Quit" % str(addr))
            break
        # call handler.
        response_msg = handler(dicData, database)
        # save response message as history (log).
        history = response_msg
        # transform dict type to json type.
        response_msg = dtoj(response_msg)

        # print history to server screen( It can be written to server log file.).
        now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        print("[%s] FORM %s : %s" % (str(now), addr, dicData))
        print("[%s] TO   %s : %s" % (str(now), addr, history))

        # send message to client.
        cskt.send(response_msg)

        # disconnect.
        if dicData['Action'] == 'Logout':
            print("%s Logout" % str(addr))
            break

    # close database connection after client logout.
    database.close()
    # close client socket. (recycle)
    cskt.close()
    print('Thread is abort.' + str(addr))
コード例 #5
0
def spawn(argv, handler=BaseHandler, options=None):
    with handler(options) as h:
        return h.spawn(argv)
コード例 #6
0
ファイル: main.py プロジェクト: iAgentsCS/SentiConceptNet
def main():
    parser = ArgumentParser()
    subparsers = parser.add_subparsers()

    parser_sp = subparsers.add_parser('split')
    parser_sp.set_defaults(handler=handle_split)
    parser_sp.add_argument('--graph',
                           dest='graph_paths',
                           nargs='+',
                           required=True)
    parser_sp.add_argument('--nodes', dest='nodes_path', required=True)
    parser_sp.add_argument('--edges', dest='edges_path', required=True)
    parser_sp.add_argument('--rels', dest='rels_path', required=True)

    parser_sd = subparsers.add_parser('seeds')
    parser_sd.set_defaults(handler=handle_seeds)
    parser_sd.add_argument('source', choices=('anew', 'sn'))
    parser_sd.add_argument('--raw', dest='raw_path', required=True)
    parser_sd.add_argument('--seed', dest='seed_path', required=True)
    parser_sd.add_argument('--nodes', dest='nodes_path', required=True)

    parser_ir = subparsers.add_parser('iterreg')
    parser_ir.set_defaults(handler=handle_iterreg)
    parser_ir.add_argument('--anew', dest='anew_path', required=True)
    parser_ir.add_argument('--sn', dest='sn_path', required=True)
    parser_ir.add_argument('--edges', dest='edges_path', required=True)
    parser_ir.add_argument('--pis', dest='pis_path')
    parser_ir.add_argument('--pred', dest='pred_path', required=True)
    parser_ir.add_argument('--param')

    parser_irc = subparsers.add_parser('ircert')
    parser_irc.set_defaults(handler=handle_ircert)
    parser_irc.add_argument('--preds',
                            dest='pred_paths',
                            nargs='+',
                            required=True)
    parser_irc.add_argument('--cert', dest='cert_path', required=True)

    parser_rw = subparsers.add_parser('randwalk')
    parser_rw.set_defaults(handler=handle_randwalk)
    parser_rw.add_argument('--edges', dest='edges_path', required=True)
    parser_rw.add_argument('--seed', dest='seed_path', required=True)
    parser_rw.add_argument('--pred', dest='pred_path', required=True)
    parser_rw.add_argument('--cin', dest='cert_in_path', required=True)
    parser_rw.add_argument('--cout', dest='cert_out_path', required=True)
    parser_rw.add_argument('--alpha', default=0.1, type=float)
    parser_rw.add_argument('--axis', default=1, type=int)

    parser_sh = subparsers.add_parser('shift')
    parser_sh.set_defaults(handler=handle_shift)
    parser_sh.add_argument('strategy', choices=('za', 'mva'))
    parser_sh.add_argument('--seed', dest='seed_path', required=True)
    parser_sh.add_argument('--pred_in', dest='pred_in_path', required=True)
    parser_sh.add_argument('--pred_out', dest='pred_out_path', required=True)

    parser_ip = subparsers.add_parser('impact')
    parser_ip.set_defaults(handler=handle_impact)
    parser_ip.add_argument('--edges', dest='edges_path', required=True)
    parser_ip.add_argument('--impact', dest='impact_path', required=True)
    parser_ip.add_argument('--alpha', default=0.1, type=float)
    parser_ip.add_argument('--axis', default=1, type=int)

    parser_lk = subparsers.add_parser('lookup')
    parser_lk.set_defaults(handler=handle_lookup)
    parser_lk.add_argument('--nodes', dest='nodes_path', required=True)
    parser_lk.add_argument('--edges', dest='edges_path', required=True)
    parser_lk.add_argument('--rels', dest='rels_path', required=True)
    parser_lk.add_argument('--anew', dest='anew_path', required=True)
    parser_lk.add_argument('--sn', dest='sn_path', required=True)
    parser_lk.add_argument('--pred', dest='pred_path', required=True)

    parser_ev = subparsers.add_parser('eval')
    parser_ev.set_defaults(handler=handle_eval)
    parser_ev.add_argument('metric', choices=('polarity', 'kendall'))
    parser_ev.add_argument('--pred', dest='pred_path', required=True)
    parser_ev.add_argument('--truth', dest='truth_path', required=True)

    args = vars(parser.parse_args())
    handler = args.pop('handler')
    handler(**args)
コード例 #7
0
 def test_handler(self):
     """Test handler returns True."""
     self.assertEqual(handler(None, None), True)
コード例 #8
0
from arduino_pin_mapping import *
from hardware_interface import *
from handler import *
import global_var
import time

hardwareInterfaceObject = hardware_interface()
handlerObject = handler()


##This class defines methods for switching ON/OFF coils and pin mapping with the micro-controller
class switching():

    ##Initializing function
    def __init__(self):
        print("In the init of _switching")
        self.type = None

    ##This method implements
    #@param self The object pointer
    #@param coil Is the coil number for which the Power Management feedback is requested
    #@param type Defines the type of device for which we need the PM feedback
    #@param status Defines whether the @param coil needs to be ON/OFF -> 1/0
    def coilPinMapping(self, coil, type, status):
        print("----------------------*************-------------------")
        print("In the coil pins mapping ")
        print("Data received: coil no.--> ", coil, " Device --> ", type)
        print("Status received --> ", status)
        self.type = type
        try:
            if (type == "Laptop"):
コード例 #9
0
ファイル: test_webstates.py プロジェクト: psorus/gradeopt
    def available(s):
        return s.iseitherstate(["available", "full"])


####

    def buttonbuy(s):
        return f'<br><a href="/buy">Buy item</a>'

    def buttonrestock(s):
        return f'<br><a href="/restock">Restock an item</a>'

    def vis_full(s):
        return f'Currently a full stock of {s["stock"]}' + s.buttonbuy()

    def vis_available(s):
        return f'Currently able to sell {s["stock"]} items' + s.buttonbuy(
        ) + s.buttonrestock()

    def vis_soldout(s):
        return 'Sadly, there are currently no more things to buy' + s.buttonrestock(
        )

    def vis(s, state):
        return f"visualising for state {state} not yet implemented. This should go away by reloading the page (obviously ignoring that this should not be possible at all)"

k = handler(lambda: shop())
k.run()

#notice that this shop is kind of useless, since everybody has his own shop
コード例 #10
0
ファイル: main.py プロジェクト: Folk19/SentiConceptNet
def main():
    parser = ArgumentParser()
    subparsers = parser.add_subparsers()

    parser_sp = subparsers.add_parser('split')
    parser_sp.set_defaults(handler=handle_split)
    parser_sp.add_argument('--graph', dest='graph_paths', nargs='+', required=True)
    parser_sp.add_argument('--nodes', dest='nodes_path', required=True)
    parser_sp.add_argument('--edges', dest='edges_path', required=True)
    parser_sp.add_argument('--rels', dest='rels_path', required=True)

    parser_sd = subparsers.add_parser('seeds')
    parser_sd.set_defaults(handler=handle_seeds)
    parser_sd.add_argument('source', choices=('anew', 'sn'))
    parser_sd.add_argument('--raw', dest='raw_path', required=True)
    parser_sd.add_argument('--seed', dest='seed_path', required=True)
    parser_sd.add_argument('--nodes', dest='nodes_path', required=True)

    parser_ir = subparsers.add_parser('iterreg')
    parser_ir.set_defaults(handler=handle_iterreg)
    parser_ir.add_argument('--anew', dest='anew_path', required=True)
    parser_ir.add_argument('--sn', dest='sn_path', required=True)
    parser_ir.add_argument('--edges', dest='edges_path', required=True)
    parser_ir.add_argument('--pis', dest='pis_path')
    parser_ir.add_argument('--pred', dest='pred_path', required=True)
    parser_ir.add_argument('--param')

    parser_irc = subparsers.add_parser('ircert')
    parser_irc.set_defaults(handler=handle_ircert)
    parser_irc.add_argument('--preds', dest='pred_paths', nargs='+', required=True)
    parser_irc.add_argument('--cert', dest='cert_path', required=True)

    parser_rw = subparsers.add_parser('randwalk')
    parser_rw.set_defaults(handler=handle_randwalk)
    parser_rw.add_argument('--edges', dest='edges_path', required=True)
    parser_rw.add_argument('--seed', dest='seed_path', required=True)
    parser_rw.add_argument('--pred', dest='pred_path', required=True)
    parser_rw.add_argument('--cin', dest='cert_in_path', required=True)
    parser_rw.add_argument('--cout', dest='cert_out_path', required=True)
    parser_rw.add_argument('--alpha', default=0.1, type=float)
    parser_rw.add_argument('--axis', default=1, type=int)

    parser_sh = subparsers.add_parser('shift')
    parser_sh.set_defaults(handler=handle_shift)
    parser_sh.add_argument('strategy', choices=('za', 'mva'))
    parser_sh.add_argument('--seed', dest='seed_path', required=True)
    parser_sh.add_argument('--pred_in', dest='pred_in_path', required=True)
    parser_sh.add_argument('--pred_out', dest='pred_out_path', required=True)

    parser_ip = subparsers.add_parser('impact')
    parser_ip.set_defaults(handler=handle_impact)
    parser_ip.add_argument('--edges', dest='edges_path', required=True)
    parser_ip.add_argument('--impact', dest='impact_path', required=True)
    parser_ip.add_argument('--alpha', default=0.1, type=float)
    parser_ip.add_argument('--axis', default=1, type=int)

    parser_lk = subparsers.add_parser('lookup')
    parser_lk.set_defaults(handler=handle_lookup)
    parser_lk.add_argument('--nodes', dest='nodes_path', required=True)
    parser_lk.add_argument('--edges', dest='edges_path', required=True)
    parser_lk.add_argument('--rels', dest='rels_path', required=True)
    parser_lk.add_argument('--anew', dest='anew_path', required=True)
    parser_lk.add_argument('--sn', dest='sn_path', required=True)
    parser_lk.add_argument('--pred', dest='pred_path', required=True)

    parser_ev = subparsers.add_parser('eval')
    parser_ev.set_defaults(handler=handle_eval)
    parser_ev.add_argument('metric', choices=('polarity', 'kendall'))
    parser_ev.add_argument('--pred', dest='pred_path', required=True)
    parser_ev.add_argument('--truth', dest='truth_path', required=True)

    args = vars(parser.parse_args())
    handler = args.pop('handler')
    handler(**args)
コード例 #11
0
ファイル: main.py プロジェクト: solimy/L2JTcpProxy
async def new_client(host, port, handler):
    reader, writer = await asyncio.open_connection(
        host=host,
        port=port,
    )
    await asyncio.create_task(handler(reader, writer))