Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81207

Re: Using Python for date calculations

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'operator': 0.03; 'irc': 0.05; 'tree': 0.05; 'subject:Python': 0.06; '21,': 0.07; 'attribute': 0.07; '22,': 0.09; 'function,': 0.09; 'to)': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'accepting': 0.14; '"enter': 0.16; '(written': 0.16; 'ast': 0.16; 'calculator': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'limiting': 0.16; 'literal.': 0.16; 'parse,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'not,': 0.20; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'node': 0.31; 'pickle': 0.31; '(i.e.': 0.33; 'fri,': 0.33; 'not.': 0.33; 'sense': 0.34; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'classes': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'acceptable': 0.36; 'done': 0.36; 'possible': 0.36; 'clear': 0.37; 'sometimes': 0.38; 'nov': 0.38; 'process,': 0.38; 'work?': 0.38; 'anything': 0.39; 'channel': 0.39; 'access,': 0.60; 'removing': 0.60; 'entire': 0.61; 'strictly': 0.61; "you're": 0.61; 'times': 0.62; 'act': 0.63; 'more': 0.64; 'number:': 0.66; 'walk': 0.74; '2014,': 0.84; 'ever.': 0.84; 'fine...': 0.84; 'subject:Using': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=xnawHB6jyntvVqRZF/01ZYw17a7jvMUq0dseYa6E/0Y=; b=RLRKCsCsjAF67Li/FkwJ1/CFtKePcN+7XeVBlFA4M5L21iXA5/KeiH/0zpFR+kaV75 9Sa9+U1yU9Kn4s7Rr1mnfTRjgTV+veB17xbLaup9GgBKA3ulWNgOXSF4FmhO0V8A+Pgw 6tULL3MjtV6v6xjVpAj9FL5mKw/g0ZV67t4PFU+vk46pToxGfq2VOj9KqAK54J8tnzNG 6+dB4jQdavbvY0zbyY1bbh35j9ss+64hc41Y6ZBPNIzODSrT98HnbRKflh60hRor6gd+ Ot/eaxQ5zZowuXN1ZDqU31UodheSp94eA6gcxaXAz3fgdbYHxyKQ/sWZxjksb9zMTcWO aR+A==
MIME-Version 1.0
X-Received by 10.42.110.195 with SMTP id r3mr12904985icp.12.1416578887618; Fri, 21 Nov 2014 06:08:07 -0800 (PST)
In-Reply-To <1416578293.597072.193784725.1C8E5BD1@webmail.messagingengine.com>
References <k7tt6aheccqv06enkume0vs0v6kvvhns45@4ax.com> <mailman.16088.1416559225.18130.python-list@python.org> <e44u6a121qs79midbsfeotejdde9vbs2n9@4ax.com> <0yEbw.852077$KL.733426@fx19.am4> <CAPTjJmpYBRa06+gwJiwjiEmGk0MOtX049Zx73ikEdzx0p59Rcg@mail.gmail.com> <1416578293.597072.193784725.1C8E5BD1@webmail.messagingengine.com>
Date Sat, 22 Nov 2014 01:08:07 +1100
Subject Re: Using Python for date calculations
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16102.1416578890.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416578890 news.xs4all.nl 2897 [2001:888:2000:d::a6]:35927
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81207

Show key headers only | View raw


On Sat, Nov 22, 2014 at 12:58 AM,  <random832@fastmail.us> wrote:
> On Fri, Nov 21, 2014, at 05:47, Chris Angelico wrote:
>> Now, maybe you want it to eval. There are times when I conceptually
>> want "enter an integer", but it makes good sense to be able to type
>> "1+2" and have it act as if I typed "3". That's fine... but if you
>> want eval, write eval into your code. Be explicit:
>> eval(raw_input("Enter a number: ")) makes it very clear that you're
>> accepting code at the console.
>
> Out of curiosity, is there a way to use eval "safely" (i.e. strictly
> limiting what it has access to) across a privilege boundary? This also
> comes up for pickle and other serialization formats that can store
> arbitrary classes (i.e. call arbitrary constructors).

No, there is not. Not in Python. You can sandbox the entire process,
but you can't eval less-privileged code in a more-privileged process,
ever.

> I remember an IRC channel I sometimes go in has a chatbot (written in
> perl) which has a calculator function, it goes with the low-tech
> solution of removing via regex anything that isn't an operator or a
> number literal.

Would ast.literal_eval work? If not, it would at least be possible to
do an AST parse, then walk the tree and see if there's anything that
isn't an acceptable node type. There'd have to be draconian rules (no
attribute access, for instance), but it could be done more
intelligently than regex.

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 10:35 +0200
  Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 19:40 +1100
    Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 12:15 +0200
      Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:18 +1100
      Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:33 +0000
        Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:47 +1100
        Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:54 -0500
          Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 14:54 +0000
        Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:58 -0500
          Re: Using Python for date calculations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-22 01:55 +1100
            Re: Using Python for date calculations Ned Batchelder <ned@nedbatchelder.com> - 2014-11-21 10:25 -0500
        Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 01:08 +1100
      Re: Using Python for date calculations Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-21 14:50 -0500
        Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:07 +0200
          Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 16:13 +1100
  Re: Using Python for date calculations Gary Herron <gary.herron@islandtraining.com> - 2014-11-21 00:50 -0800
  Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 10:20 +0000
    Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:38 +0000
    Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 17:50 +0200
      Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 16:01 +0000
  Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:27 +1100
  Re: Using Python for date calculations duncan smith <buzzard@invalid.invalid> - 2014-11-21 17:03 +0000
    Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 21:48 +0200
      Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 15:32 -0500
  Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 14:35 -0500
    Re: Using Python for date calculations Paul Blair <p.blair@internode.on.net> - 2014-11-22 06:51 +1100
      Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:31 +0200
    Re: Using Python for date calculations Denis Beauregard <denis.b-at-francogene.com@fr.invalid> - 2014-11-21 15:07 -0500
      Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:34 +0200

csiph-web