コード例 #1
0
def run(mc):
    print('run')

    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
    print(mc.get('cnt'))
コード例 #2
0
ファイル: helpers.py プロジェクト: jpgerek/gae-common
def send_email(to, subject, body, html):
    from google.appengine.api import mail
    import mc
    sender = config.EMAIL_SENDER
    error = False
    if config.DEVELOPMENT:
        logging.info('Mail send: %s - %s - %s - %s' % (subject, to, body, html))
    else:
        count = mc.incr(constants.mc.EMAIL_COUNTER)
        logging.info('Sending email to "%s", count: %d' % (to, count))
        if (count%3) == 0:
            #- Appengine free quota is 100 emails per day -#
            msg = mail.EmailMessage()
            msg.sender = sender
            subject = config.EMAIL_SUBJECT_PREFIX + subject
            msg.subject = subject
            msg.to = to
            msg.body = body
            msg.html = html
            error = not msg.is_initialized()
            msg.send()
        else:
            #- Sendgrid free quota is 200 emails per day -#
            to = to.split(' ')[0]
            to_name = ''
            error = not send_email_using_sendgrid(to, to_name, subject, body, html)
    if error:
        logging.error('Error sending the email: %s - %s - %s - %s -%s' % ( sender, to, subject, body, html ))
コード例 #3
0
ファイル: base.py プロジェクト: jpgerek/gae-common
 def wrapper(*args, **kwargs):
     timestamp = int(time.time())
     self = args[0]
     #- Check if the ip was banned -#
     ip_ban_key_name = constants.mc.IP_BAN % self.request.remote_addr
     ban = mc.get(ip_ban_key_name)
     if ban:
         #- Renew the ban if it's going to expire in 1/3 of the banning time -#
         ban_pending_time = ban_time - (timestamp - ban)
         if ban_pending_time < (ban_time/3):
             #- Renewing the ban because the attacker insists -#
             mc.set(ip_ban_key_name, time.time(), ban_time)
         self.abort(403)
     current_minute = timestamp - (timestamp%60)
     key_name = constants.mc.REQUEST_HIT_FROM_IP % (current_minute, self.request.path, self.request.remote_addr)
     #- Increases hits from an ip to a particular url -#
     counter = mc.incr(key_name)
     if counter > limit_per_minute:
         #- Banning ip -#
         mc.set(ip_ban_key_name, time.time(), ban_time)
         self.abort(403)
     else:
         return fn(*args, **kwargs)
コード例 #4
0
def run(mc):
    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
コード例 #5
0
ファイル: udp_counter_ops.py プロジェクト: 2Fast2BCn/beats
def run(mc):
    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)