示例#1
0
    def get_remarks(self, time, known_prefixes, new_prefixes):
        self.trans.execute(
            """
			SELECT 
				remark.content, remark.server_id, prefix.prefix, remark.id
			FROM
				remark 
			JOIN
				prefix
			ON	
				(remark.prefix_id = prefix.id)
			WHERE 
					(		
						post_time >= %(t)s
					AND
						prefix_id IN %(known_prefixes)s

					)
				OR 
					prefix_id IN %(new_prefixes)s
			""", {
                't': time,
                'known_prefixes': known_prefixes,
                'new_prefixes': new_prefixes
            })

        ret = []
        row = self.trans.fetchone()
        while row:
            ret.append((xmlrpc.Binary(row[0]), row[1], row[2], row[3]))
            row = self.trans.fetchone()
        return ret
 def handle_result(result):
     if self.is_binary:
         return xmlrpc.Binary(data=result)
     else:
         if result is None:
             return 0
         else:
             return result
示例#3
0
 def xmlrpc_renderCaptcha(self, id):
     """Renders a (value, type) tuple containing a rendered version of
        the CAPTCHA test with the given ID. Currently the type will
        always be image/jpeg.
        """
     io = StringIO()
     self.getCaptchaFromID(id).render().save(io, "JPEG")
     return (xmlrpc.Binary(io.getvalue()), "image/jpeg")
示例#4
0
 def wrapTuple(self, t):
     """Wrap the value in a (value, type) tuple in an xmlrpc.Binary
        if the type doesn't start with text/.
        """
     if t and not t[1].startswith("text/"):
         return (xmlrpc.Binary(t[0]), t[1])
     else:
         return t
示例#5
0
 def xmlrpc_get(self, name, readLevel=0):
     """Client frontend for the `get()` method.
     Security check with `readLevel`.
     Only read values from memory if no acquisition isRunning.
     Pickle or otherwise xmlrpc-sanitize values for network transmission"""
     r = self.desc.getattr(name, 'readLevel')
     if readLevel < r:
         self.log.critical('Not authorized get', name)
         raise ReadNotAuthorized('Option: %s Required: %i Level: %i' %
                                 (name, r, readLevel))
     p = self.desc.gete(name)
     if 'Hot' in p['attr']:
         if self.root_obj.get('isRunning'):
             r = self.desc.get(name)
         else:
             r = self.get(name)
     else:
         r = self.get(name)
     if p['type'] in ['Binary', 'Profile', 'Image']:
         return xmlrpc.Binary(dumps(r))
     if p['type'] == 'Meta':
         return r.copy()
     return csutil.xmlrpcSanitize(r)
示例#6
0
    def handle_outbound_message(self, message):
        xmlrpc_payload = self.default_values.copy()
        metadata = message["transport_metadata"]

        delivery = metadata.get('deliver_at', datetime.utcnow())
        expiry = metadata.get('expire_at', (delivery + timedelta(days=1)))
        priority = metadata.get('priority', 'standard')
        receipt = metadata.get('receipt', 'Y')

        # check for non-ascii chars
        content = message["content"]
        if any(ord(c) > 127 for c in content):
            content = xmlrpc.Binary(content.encode('utf-8'))

        xmlrpc_payload['Numbers'] = message['to_addr']
        xmlrpc_payload['SMSText'] = content
        xmlrpc_payload['Delivery'] = delivery
        xmlrpc_payload['Expiry'] = expiry
        xmlrpc_payload['Priority'] = priority
        xmlrpc_payload['Receipt'] = receipt
        xmlrpc_payload['MaxSegments'] = self.max_segments

        log.msg("Sending SMS via Opera: %s" % xmlrpc_payload)

        d = self.proxy.callRemote('EAPIGateway.SendSMS', xmlrpc_payload)
        d.addErrback(self.handle_outbound_message_failure, message)

        proxy_response = yield d

        log.msg("Proxy response: %s" % proxy_response)
        transport_message_id = proxy_response['Identifier']

        yield self.set_message_id_for_identifier(transport_message_id,
                                                 message['message_id'])

        yield self.publish_ack(user_message_id=message['message_id'],
                               sent_message_id=transport_message_id)
示例#7
0
 def _send_snapshot(self, data, result):
     action_id, redCut = result
     return (action_id.encode(), redCut, xmlrpc.Binary(data))
示例#8
0
 def _cb(method_called, xmlrpc_payload):
     self.assertEqual(xmlrpc_payload['SMSText'],
                      xmlrpc.Binary(content.encode('utf-8')))
     return {'Identifier': '1'}