Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'example:': 0.03; 'syntax': 0.04; 'string': 0.09; 'falls': 0.09; 'subject:language': 0.09; 'subject:string': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'language.': 0.14; 'random': 0.14; 'template': 0.14; 'expressions?': 0.16; 'subject:generation': 0.16; 'subject:random': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'pfxlen:0': 0.19; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'paul': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'class': 0.32; 'probably': 0.32; 'regular': 0.32; 'fri,': 0.33; "can't": 0.35; 'skip:s 30': 0.35; 'skip:u 20': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'generating': 0.39; 'skip:u 10': 0.60; 'back': 0.62; 'kind': 0.63; 'choose': 0.64; 'to:addr:gmail.com': 0.65; 'secure': 0.71; 'regexp': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=U54v8MvAfYJi2CFf4hwGER48BNEjJCbLO6b3FWBWbuA=; b=d6mGiuPp0sRoiLUsQfc15VAGLUTlvgVJ0JFiKYk4LxEddfPTphqwiUJYC45191Y8yq GiP5wZo84Ro+VUkQ04r0B7Vc9M9g0ASSNsjZa3C5hoCXTD0+eNx+hL0fTKYTapSDVFaQ 4G3K3ZgV4I3ECztFB/1gZpk6FCBe2zaGCLyBkG1/HiwH7XgyWetBYfBcsX0xgSBXD/EY 2NXBJM/Pyy2PkoVKTOnikGqYTjsXWhOWpEC+GfKhvCgJFJXVPDJudmYTudzLBiVldOHZ 10t2Pm72J6x/ziKnJSxhhxv/X58CPwEaXv6X8leonxiK7Erge9O22C7GAOHrTaGqbnrr uC+Q== X-Received: by 10.224.128.9 with SMTP id i9mr55736144qas.50.1407674624687; Sun, 10 Aug 2014 05:43:44 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> From: Devin Jeanpierre Date: Sun, 10 Aug 2014 05:43:04 -0700 Subject: Re: Template language for random string generation To: Paul Wolf Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407674628 news.xs4all.nl 2832 [2001:888:2000:d::a6]:53210 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75981 On Fri, Aug 8, 2014 at 2:01 AM, Paul Wolf wrote: > This is a proposal with a working implementation for a random string generation template syntax for Python. `strgen` is a module for generating random strings in Python using a regex-like template language. Example: > > >>> from strgen import StringGenerator as SG > >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() > u'F0vghTjKalf4^mGLk' Why aren't you using regular expressions? I am all for conciseness, but using an existing format is so helpful... Unfortunately, the equivalent regexp probably looks like r'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9]{8:15}' (I've been working on this kind of thing with regexps, but it's still incomplete.) > * Uses SystemRandom class (if available, or falls back to Random) This sounds cryptographically weak. Isn't the normal thing to do to use a cryptographic hash function to generate a pseudorandom sequence? Someone should write a cryptographically secure pseudorandom number generator library for Python. :( (I think OpenSSL comes with one, but then you can't choose the seed.) -- Devin