Example #1
0
def privmsg(serv, usr, n, m, *_):
    try:
        chan = serv.get_channel(n)
        us = serv.get_channel_users(chan)

        targets = us[:]
        targets.remove(usr)

        for t in targets:
            t.send(Message(usr.hostmask, Command.PRIVMSG, [n, m]))

    except BadChannelError:
        try:
            target = serv.get_user(n)
            target.send(Message(usr.hostmask, Command.PRIVMSG, [n, m]))
        except NoUserError:
            usr.send(
                Message(serv.hostname, Reply.ERR.NOSUCHNICK,
                        [n, 'no such nick']))

    except NoChannelError:
        usr.send(
            Message(serv.hostname, Reply.ERR.NOSUCHCHANNEL,
                    [n, 'no such channel']))

    except ValueError:
        usr.send(
            Message(serv.hostname, Reply.ERR.CANNOTSENDTOCHAN,
                    [n, 'cannot send to channel']))
Example #2
0
def check_state(serv, usr, state, *_):
    if state == True and not usr.is_registered():
        usr.send(
            Message(serv.hostname, Reply.ERR.NOTREGISTERED,
                    ['you have not registered']))
        return False

    elif state == False and usr.is_registered():
        usr.send(
            Message(serv.hostname, Reply.ERR.ALREADYREGISTERED,
                    ['unauthorized command (already registered)']))
        return False

    else:
        return True
Example #3
0
    def _message(self, buddy, message, **options):
        '@return: True if the message was allowed'

        # Always use local time for online messages, in case user's clock is wrong.
        if not options.get('offline', True):
            options.pop('timestamp', None)

        if options.get('offline', False):
            self.autoresponded = True  # Prevent autoresponse to offline messages

        # if timestamp is None substitute it with UTC now
        timestamp = options.pop('timestamp', None)
        if timestamp is None:
            timestamp = datetime.utcnow()

        from common.message import Message
        messageobj = Message(buddy=buddy,
                             message=message,
                             timestamp=timestamp,
                             conversation=self,
                             **options)
        from plugin_manager import plugin_hub
        plugin_hub.act('digsby.im.msg.async', self, messageobj,
                       options.get('type', None))

        from common import profile
        return profile.on_message(messageobj) is not profile.on_message.VETO
Example #4
0
    def buddy_says(self, buddy, message, **options):
        '@return: True if the message was allowed'
        if not isinstance(message, unicode):
            raise TypeError, 'buddy_says needs unicode got type %r: %r' % (
                type(message), message)

        try:
            timestamp = options.get('timestamp', None)
            if timestamp is None:
                timestamp = datetime.utcnow()

            content_type = options.pop('content_type', 'text/plain')

            from common.message import Message
            messageobj = Message(buddy=buddy,
                                 message=message,
                                 timestamp=timestamp,
                                 content_type=content_type)

            from plugin_manager import plugin_hub
            msgtype = options.get('type', None)

            # Allow plugins to make changes to the messageobj
            plugin_hub.act('digsby.im.msg.pre', messageobj, msgtype)

            if messageobj.message != '':
                # TODO: pass entire (potentially) changed messageobj to self._message
                return self._message(buddy,
                                     messageobj.message,
                                     content_type=messageobj.content_type,
                                     **options)
        except Exception, e:
            log.error("Failed to parse message %r", e)
            # do what it used to do
            return self._message(buddy, message, **options)
Example #5
0
 def on_success():
     self.show_message(
         Message(buddy=frm.self_buddy,
                 message=message[:SMS_MAX_LENGTH],
                 conversation=self.convo,
                 type='outgoing'))
     self.ClearAndFocus()
Example #6
0
    def test_write_read_unicode(self):
        with self.scratch_logger() as logger:
            unicode_msg = u'\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5'

            # log a message with unicode
            msg = Message(buddy=self.buddy,
                          message=unicode_msg,
                          type='incoming',
                          conversation=self.convo,
                          timestamp=datetime(month=12,
                                             day=25,
                                             year=2000,
                                             hour=12))

            logger.on_message(msg)

            # check that the file is on disk
            logfile = os.path.join(
                logger.OutputDir, r'aim\digsby03\digsby01_aim\2000-12-25.html')
            self.assert_(os.path.isfile(logfile), logfile)

            history = logger.history_for(self.account, self.buddy)

            # assert that unicode was encoded and decoded properly
            logmsg = list(history)[0]
            self.assert_(logmsg.message == unicode_msg)
Example #7
0
def parse_html_slow(html):
    'Uses Beautiful Soup to parse messages out of a log file.'

    html = html.decode('utf-8', 'ignore')

    soup = soupify(html, markupMassage=((br_re, lambda m: '<br />'), ))
    messages = []
    strptime = datetime.strptime

    for div in soup.findAll(message_divs):
        try:
            buddyname = div.findAll('span',
                                    class_buddy)[0].renderContents(None)
            timestamp = parse_timestamp(div['timestamp'])
            message = div.findAll('span',
                                  class_msgcontent)[0].renderContents(None)
            type = div['class'].replace('message', '').strip()
            auto = boolify(div.get('auto', 'false'))
        except Exception:
            print_exc()
        else:
            messages.append(
                Message(buddy=S(name=buddyname),
                        timestamp=timestamp,
                        message=message,
                        type=type,
                        auto=auto))

    log_info('parse_html_slow with %d bytes returning %d messages', len(html),
             len(messages))
    return messages
Example #8
0
def user(serv, usr, n, h, s, r, *_):
    usr.update(username=n)
    if usr.can_register():
        usr.register()
        usr.send(
            Message(serv.hostname, Reply.RPL.WELCOME,
                    ['welcome to pylay IRC ' + format(usr.hostmask)]))
Example #9
0
 def setUpClass(cls):
     serino = "MDEVICE"
     serino = "a541c694"
     if len(sys.argv)>1:         
         serino = sys.argv[1] 
     cls.mod = Message(serino, "Message")
     cls.set = Settings(cls.mod.device, "Settings")
Example #10
0
    def test_html_entities(self):
        with self.scratch_logger() as logger:

            message = u'foo bar <b>meep</b>'.encode('xml')

            msg = Message(buddy=self.buddy,
                          message=message,
                          type='incoming',
                          conversation=self.convo,
                          timestamp=datetime(month=12,
                                             day=25,
                                             year=2000,
                                             hour=12))

            logger.on_message(msg)

            # check that the file is on disk
            logfile = os.path.join(
                logger.OutputDir, r'aim\digsby03\digsby01_aim\2000-12-25.html')
            self.assert_(os.path.isfile(logfile), logfile)
            print open(logfile, 'rb').read()

            history = list(logger.history_for(self.account, self.buddy))
            self.assert_equal(1, len(history))
            self.assert_('<' not in history[0].message)
    def __init__(self, request, client_address, server):
        self.keep_alive = True
        self.handshake_done = False

        self.is_master = False  # 是否是控制机
        self.is_client = True  # 是否是用户机

        self.xid = None  # 绑定的编号
        self.pwd = None  # 绑定的密码

        self.master_xid = None  # 控制机的编号
        self.master_pwd = None  # 控制机的密码

        self.json_type = True  # 默认以JSON类型传输数据,False: 接收到的数据不能解析为json数据了。

        self.last_send_message = None  # 上次发送的数据

        self.selector = selectors.DefaultSelector()
        self.selector.register(request, selectors.EVENT_READ)
        self.server = server  # type: WebSocketServer
        self.message = Message()

        self.queue = queue.Queue()  # 默认队列

        self.request = request
        self.master_request = None  # type: socket.socket
        self.master_handler = None  # type: WebSocketServerRequestHandler
        self.client_requests = []  # 所有用户机的socket

        super().__init__(request, client_address, server)
Example #12
0
def join(serv, usr, n, *_):
    try:
        chan = serv.get_channel(n, True)
        serv.join_channel(chan, usr)

        us = serv.get_channel_users(chan)

        targets = us[:]
        targets.remove(usr)

        for t in targets:
            t.send(Message(usr.hostmask, Command.JOIN, [n]))

    except BadChannelError:
        usr.send(
            Message(serv.hostname, Reply.ERR.NOSUCHCHANNEL,
                    [n, 'no such channel']))
Example #13
0
def part(serv, usr, n, *_):
    try:
        chan = serv.get_channel(n)
        serv.part_channel(chan, usr)

        targets = serv.get_channel_users(chan)
        for t in targets:
            t.send(Message(usr.hostmask, Command.PART, [n]))

    except (BadChannelError, NoChannelError):
        usr.send(
            Message(serv.hostname, Reply.ERR.NOSUCHCHANNEL,
                    [n, 'no such channel']))

    except NotInChannelError:
        usr.send(
            Message(serv.hostname, Reply.ERR.NOTONCHANNEL,
                    [n, 'you\'re not on that channel']))
Example #14
0
def nick(serv, usr, n, *_):
    try:
        serv.get_user(n)
        usr.send(
            Message(serv.hostname, Reply.ERR.NICKNAMEINUSE,
                    [n, 'nickname is already in use']))
    except NoUserError:
        try:
            usr.update(nickname=n)
            if usr.can_register():
                usr.register()
                usr.send(
                    Message(serv.hostname, Reply.RPL.WELCOME,
                            ['welcome to pylay IRC ' + format(usr.hostmask)]))
        except BadNicknameError:
            usr.send(
                Message(serv.hostname, Reply.ERR.ERRONEUSNICKNAME,
                        [n, 'erroneous nickname']))
Example #15
0
def setup(serino):
    chrome = Chrome(serino, "Chrome")
    message = Message(serino, "Message")
    email = Email(serino, "Email")
    call = Telephony(serino, "call")

    #     chrome.setup()
    message.setup()
    email.setup("*****@*****.**", "Password001", "exchange")
    call.setup_contacts()
Example #16
0
def quit(serv, usr, m=None, *_):
    hm = usr.hostmask
    if not hm.is_valid():
        return

    us = (u for u in serv.users if u != usr)
    for u in us:
        u.send(Message(hm, Command.QUIT, [m if m else hm.nickname]))

    serv.remove_user(usr)
Example #17
0
 def __init__(self, device, mod):
     self.device = connect_device(device)
     self.logger = createlogger(mod)
     self.log_path = create_folder()
     self.camera = Camera(self.device, "task_camera")
     self.product = Configs("common").get("product", "Info")
     if self.product == "Sprints":
         from common.chrome import Chrome
         self.browser = Chrome(self.device, "task_browser")
     else:
         self.browser = Browser(self.device, "Browser")
     self.tel = Telephony(self.device, "task_tel")
     self.message = Message(self.device, "task_message")
     self.settings = Settings(self.device, "switch_nw")
     self.suc_times = 0
     self.mod_cfg = GetConfigs(mod)
     self.test_times = 0
     self.dicttesttimes = self.mod_cfg.get_test_times()
     for test_time in self.dicttesttimes:
         self.test_times += int(self.dicttesttimes[test_time])
     self.test_times = self.test_times * 2 + 4
     self.logger.info("Trace Total Times " + str(self.test_times))
Example #18
0
def parse_html_lxml(html):
    'parses a logfile with lxml'

    messages = []

    doc = lxml.html.document_fromstring(html, parser=lxmlparser())
    for div in doc.xpath('//html/body/div'):
        try:
            message_type = div.attrib.get('class', '')
            if not 'message' in message_type:
                continue

            message_type = message_type.replace('message', '').strip()
            if not message_type in ('incoming', 'outgoing'):
                continue

            buddyname = div.find_class('buddy')[0].text
            timestamp = div.attrib.get('timestamp')
            if timestamp is not None:
                timestamp = parse_timestamp(timestamp)
            message = render_contents(div.find_class('msgcontent')[0])
            auto = boolify(div.attrib.get('auto', 'false'))
        except Exception:
            print_exc()
        else:
            messages.append(
                Message(
                    buddy=S(name=buddyname),
                    timestamp=timestamp,
                    message=message,
                    type=message_type,
                    auto=auto,
                    has_autotext=auto,
                ))

    return messages
Example #19
0
def unknown_handler(serv, usr, cmd):
    usr.send(
        Message(serv.hostname, Reply.ERR.UNKNOWNCOMMAND,
                [cmd, 'unknown command']))
Example #20
0
File: tests.py Project: jchmura/PiE
 def test_payload(self):
     obj = object()
     message = Message(obj)
     self.assertIs(obj, message.payload)
Example #21
0
def invalid_handler(serv, usr, cmd):
    usr.send(
        Message(serv.hostname, Reply.ERR.NEEDMOREPARAMS,
                [cmd, 'not enough parameters']))
Example #22
0
File: tests.py Project: jchmura/PiE
 def test_str(self):
     payload = 'some payload'
     message = Message(payload)
     self.assertIn(payload, str(message))