Пример #1
0
 def handle(self, *args, **options):
     for x in range(100):
         print(x)
         Article.objects.create(title=random_word(5),
                                body=random_word(10),
                                author_id=1)
     print('Done')
Пример #2
0
    def get_random(valid: bool = True) -> dict:
        """Returns a random Verdict with it's corresponding private key"""

        id_info = ID.get_random(valid=valid)
        key, userid = id_info["private_key"], id_info["id"]
        accusation = Accusation.get_random(valid=valid)["accusation"]

        verdict = Verdict(
            userid, accusation,
            random_word(random.randint(1, SENTECE_CHAR_LIMIT)),
            random_word(random.randint(1, DESCRIPTION_CHAR_LIMIT)))

        verdict.sign(import_key(key))

        return {"private_key": key, "verdict": verdict}
Пример #3
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """
        # move these someplace sensible?
        form_id = "acctmgr_registerform" # id of the registration form
        msg = "Please enter the text below to prove you're not a machine."

        if filename == "register.html":
            word = random_word(self.dict_file)
            req.session['captcha'] = word
            req.session.save()
            if self.captcha_type == 'png':
                captcha = '<img src="%s"/>' % req.href('captcha.png')
            else:
                captcha = skimpyAPI.Pre(word).data()
            content = "<p>%s</p><p>%s</p>" % (msg, captcha)
            content += '<label>Confirm: <input type="text" name="captcha" class="textwidget" size="20"/></label>'
            stream |= Transformer('//form[@id="%s"]/fieldset[1]' % form_id).append(tag.div(Markup(content)))

        return stream
Пример #4
0
    def get_random(valid: bool = True) -> dict:
        """Returns a random ID with it's corresponding private key"""

        key = create_key()
        pubkey = parse_key(key.publickey())
        username = random_word(random.randint(1, USERNAME_LIMIT))

        if valid is False:
            username = "******" * (USERNAME_LIMIT + 1)

        return {"private_key": parse_key(key), "id": ID(username, pubkey)}
Пример #5
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """

        # only show CAPTCHAs for anonymous users
        if req.authname != 'anonymous':
            return stream

        # only put CAPTCHAs in the realms specified
        realm = self.realm(req)
        if realm not in self.realms:
            return stream

        # add the CAPTCHA to the stream
        if filename in self.xpath:

            # store CAPTCHA in DB and session
            word = random_word(self.dict_file)
            insert_update(self.env, 'captcha', 'id', req.session.sid,
                          dict(word=word))
            req.session['captcha'] = word
            req.session.save()

            # render the template
            chrome = Chrome(self.env)
            template = chrome.load_template('captcha.html')
            _data = {}

            # CAPTCHA type
            if self.captcha_type == 'png':
                captcha = tag.img(None, src=req.href('captcha.png'))
            else:
                captcha = Markup(skimpyAPI.Pre(word).data())

            _data['captcha'] = captcha
            _data['email'] = req.session.get('email', '')
            _data['name'] = req.session.get('name', '')
            _data['captchaid'] = req.session.sid
            xpath = self.xpath[filename]
            stream |= Transformer(xpath).before(template.generate(**_data))
            if filename in self.delete:
                stream |= Transformer(self.delete[filename]).remove()

        return stream
Пример #6
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """

        # only show CAPTCHAs for anonymous users
        if req.authname != 'anonymous':
            return stream

        # only put CAPTCHAs in the realms specified
        realm = self.realm(req)
        if realm not in self.realms:
            return stream

        # add the CAPTCHA to the stream
        if filename in self.xpath:

            # store CAPTCHA in DB and session
            word = random_word(self.dict_file)
            insert_update(self.env, 'captcha', 'id', req.session.sid, dict(word=word))
            req.session['captcha'] = word
            req.session.save()

            # render the template
            chrome = Chrome(self.env)
            template = chrome.load_template('captcha.html')
            _data = {}

            # CAPTCHA type
            if self.captcha_type == 'png':
                captcha = tag.img(None, src=req.href('captcha.png'))
            else:
                captcha = Markup(skimpyAPI.Pre(word).data())

            _data['captcha'] = captcha
            _data['email'] = req.session.get('email', '')
            _data['name'] = req.session.get('name', '')
            _data['captchaid'] = req.session.sid
            xpath = self.xpath[filename]
            stream |= Transformer(xpath).before(template.generate(**_data))
            if filename in self.delete:
                stream |= Transformer(self.delete[filename]).remove()

        return stream
Пример #7
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """
        # move these someplace sensible?
        form_id = "acctmgr_loginform"  # id of the login form
        msg = "Please enter the text below to prove you're not a machine."

        if filename == "login.html":

            #Check whether to display capcha.
            db = self.env.get_db_cnx()
            cursor = db.cursor()
            cursor.execute("""SELECT * FROM login_attempts WHERE ip= '%s' """ %
                           req.remote_addr)
            row1 = cursor.fetchone()
            db.close()
            self.should_display_capcha[req.remote_addr] = False
            if row1:
                if row1[1] > 2:
                    self.should_display_capcha[req.remote_addr] = True

            if self.should_display_capcha[req.remote_addr] == True:
                word = random_word(self.dict_file)
                req.session['captcha'] = word
                req.session.save()
                self.last_capcha[req.remote_addr] = word
                if self.captcha_type == 'png':
                    captcha = '<img src="%s"/>' % req.href('captcha.png')
                else:
                    captcha = skimpyAPI.Pre(word).data()
                content = "<p>%s</p><p>%s</p>" % (msg, captcha)
                content += '<label>Confirm: <input type="text" name="captcha" class="textwidget" size="20"/></label>'
                stream |= Transformer('//form[@id="%s"]' % form_id).append(
                    tag.div(Markup(content)))
                #DEBUG
                #stream |= Transformer('//form[@id="%s"]' % form_id).append(tag.div(Markup(word)))

        return stream
Пример #8
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """
        # move these someplace sensible?
        form_id = "acctmgr_loginform" # id of the login form
        msg = "Please enter the text below to prove you're not a machine."
        
               
        if filename == "login.html":
        
             #Check whether to display capcha.
            db = self.env.get_db_cnx()
            cursor = db.cursor()
            cursor.execute("""SELECT * FROM login_attempts WHERE ip= '%s' """ % req.remote_addr)
            row1 = cursor.fetchone()
            db.close()
            self.should_display_capcha[req.remote_addr] = False
            if row1:
                if row1[1] > 2:
                    self.should_display_capcha[req.remote_addr] = True                

            if self.should_display_capcha[req.remote_addr]==True:
                word = random_word(self.dict_file)
                req.session['captcha'] = word
                req.session.save()
                self.last_capcha[req.remote_addr] = word
                if self.captcha_type == 'png':
                    captcha = '<img src="%s"/>' % req.href('captcha.png')
                else:
                    captcha = skimpyAPI.Pre(word).data()
                content = "<p>%s</p><p>%s</p>" % (msg, captcha)
                content += '<label>Confirm: <input type="text" name="captcha" class="textwidget" size="20"/></label>'
                stream |= Transformer('//form[@id="%s"]' % form_id).append(tag.div(Markup(content)))
                #DEBUG
                #stream |= Transformer('//form[@id="%s"]' % form_id).append(tag.div(Markup(word)))

        return stream
Пример #9
0
import sys
import random

from utils import random_word

try:
    _, name, days_num, max_lots_num, investor_sum = sys.argv
except ValueError:
    print(
        'Incorrect parameters, use: python generate.py [file name] [days number] [max lots number] [investor sum]'
    )
    sys.exit()

days_num = int(days_num)
max_lots_num = int(max_lots_num)
investor_sum = int(investor_sum)

if days_num < 1 or max_lots_num < 1 or investor_sum < 1:
    print('Incorrect parameters, number cannot be negative or zero')
    sys.exit()

with open(name, 'w') as file:
    file.write('{} {} {}\n'.format(days_num, max_lots_num, investor_sum))

    for i in range(days_num):
        slots_num = random.randint(1, max_lots_num)
        for k in range(slots_num):
            file.write('{} {} {:.1f} {}\n'.format(i + 1, random_word(10),
                                                  random.uniform(50.0, 150.0),
                                                  random.randint(1, 5)))
Пример #10
0
def start(_button):
    model.game.word = utils.random_word()
    model.game.display = '*' * len(model.game.word)
    s_game()
Пример #11
0
 def _make_objects(self, n):
     templates = self._templates(n)
     objects = map(
         lambda t: t.format(astring=random_word(randint(1, n * 2))),
         templates)
     return ''.join(objects)