Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81529 > unrolled thread
| Started by | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| First post | 2014-11-25 18:18 -0600 |
| Last post | 2014-11-26 10:16 -0500 |
| Articles | 20 on this page of 50 — 7 participants |
Back to article view | Back to comp.lang.python
Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 18:18 -0600
Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-25 18:40 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:18 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 12:32 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:00 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:00 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:18 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 11:44 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:20 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:20 -0600
Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-25 19:44 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:01 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:01 -0600
Re: Quotation Ugliness Ben Finney <ben+python@benfinney.id.au> - 2014-11-26 12:54 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:04 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:04 -0600
Using a password with ‘sudo’ (was: Quotation Ugliness) Ben Finney <ben+python@benfinney.id.au> - 2014-11-26 18:02 +1100
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 18:10 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:59 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:59 -0600
Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 06:56 -0600
Re: Quotation Ugliness Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-11-26 15:45 +0200
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 01:37 +1100
Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 08:26 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:07 +1100
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:09 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:36 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:36 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:48 +1100
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:55 -0600
Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 11:00 -0500
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:02 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:02 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 03:13 +1100
Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 11:16 -0500
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
Re: Quotation Ugliness alister <alister.nospam.ware@ntlworld.com> - 2014-11-26 16:45 +0000
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:55 -0600
Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 10:53 -0500
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:58 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:58 -0600
Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:06 +1100
Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 09:23 -0600
Re: Quotation Ugliness Ben Finney <ben+python@benfinney.id.au> - 2014-11-27 07:24 +1100
Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 09:12 -0500
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:02 -0600
Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:02 -0600
Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 10:16 -0500
Page 1 of 3 [1] 2 3 Next page →
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-25 18:18 -0600 |
| Subject | Quotation Ugliness |
| Message-ID | <grifkb-kpo1.ln1@ozzie.tundraware.com> |
A problem for your consideration:
We are given a tuple of delimiter string pairs to quote or comment text,
possibly over multiple lines. Something like this:
delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\), ('\\', '\n') ...)
These may be nested.
Here's the problem: Determine is the string S appears *outside* or *inside*
any such quotation.
I know lots of ugly/complicated/heavyweight ways to solve this, but I'm
wondering if any of you geniuses have a pythonic/elegant/short algo that
solves this.
TIA,
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
[toc] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-11-25 18:40 -0600 |
| Message-ID | <mailman.16297.1416962599.18130.python-list@python.org> |
| In reply to | #81529 |
On 2014-11-25 18:18, Tim Daneliuk wrote:
> A problem for your consideration:
>
> We are given a tuple of delimiter string pairs to quote or comment
> text, possibly over multiple lines. Something like this:
>
> delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\),
> ('\\', '\n') ...)
>
> These may be nested.
>
> Here's the problem: Determine is the string S appears *outside* or
> *inside* any such quotation.
You would have to define what should happen in a case where you have
more than one single/double-quote delimited items on the same line:
do("this", "and", "that")
should it return true or false when testing for 'this", "and",
"that'? (it is within double-quotes)
And what should happen with mismatched quotes?
do("th/*is", "and", "th*/at")
It would also help to have a proposed function signature for the
functionality you want. Something like
def inside_quote(s, corpus, delims=delims):
-tkc
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-25 19:18 -0600 |
| Message-ID | <54752A7C.2060800@tundraware.com> |
| In reply to | #81530 |
On 11/25/2014 06:40 PM, Tim Chase wrote:
> On 2014-11-25 18:18, Tim Daneliuk wrote:
>> A problem for your consideration:
>>
>> We are given a tuple of delimiter string pairs to quote or comment
>> text, possibly over multiple lines. Something like this:
>>
>> delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\),
>> ('\\', '\n') ...)
>>
>> These may be nested.
>>
>> Here's the problem: Determine is the string S appears *outside* or
>> *inside* any such quotation.
>
>
> You would have to define what should happen in a case where you have
> more than one single/double-quote delimited items on the same line:
>
> do("this", "and", "that")
Each of them is considered quoted and thus if S appears within
any of them it is "inside".
>
> should it return true or false when testing for 'this", "and",
> "that'? (it is within double-quotes)
False.
>
> And what should happen with mismatched quotes?
>
> do("th/*is", "and", "th*/at")
Match pairs as usual, and let the remaining unterminated quote run on.
>
> It would also help to have a proposed function signature for the
> functionality you want. Something like
>
> def inside_quote(s, corpus, delims=delims):
I'd prefer:
def quoted (s, corpus, delims=delims, domain=outside)
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-26 12:32 +1100 |
| Message-ID | <mailman.16302.1416965564.18130.python-list@python.org> |
| In reply to | #81534 |
On Wed, Nov 26, 2014 at 12:18 PM, Tim Daneliuk <tundra@tundraware.com> wrote:
>> And what should happen with mismatched quotes?
>>
>> do("th/*is", "and", "th*/at")
>
>
> Match pairs as usual, and let the remaining unterminated quote run on.
Wait, what? Where's an unterminated quote? I can imagine two ways of
reading this: one the way most programming languages would interpret
it (the /* and */ are both simply part of their respective strings,
and have no significance), and the "anything nests in anything" way,
in which the quotation marks inside /* */ are effectively inverted;
neither of those leaves an unterminated quote.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:00 -0600 |
| Message-ID | <mailman.16306.1416981654.18130.python-list@python.org> |
| In reply to | #81538 |
On 11/25/2014 07:32 PM, Chris Angelico wrote:
> On Wed, Nov 26, 2014 at 12:18 PM, Tim Daneliuk <tundra@tundraware.com> wrote:
>>> And what should happen with mismatched quotes?
>>>
>>> do("th/*is", "and", "th*/at")
>>
>>
>> Match pairs as usual, and let the remaining unterminated quote run on.
>
> Wait, what? Where's an unterminated quote? I can imagine two ways of
> reading this: one the way most programming languages would interpret
> it (the /* and */ are both simply part of their respective strings,
> and have no significance), and the "anything nests in anything" way,
> in which the quotation marks inside /* */ are effectively inverted;
> neither of those leaves an unterminated quote.
>
> ChrisA
>
But I am not designing a new programming language. I am doing straight up
text processing. I want to know all the instances of S when it is quoted
or not. In my particular application, recovering from a failure of syntax
like this isn't important.
--
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:00 -0600 |
| Message-ID | <54756C87.8090504@tundraware.com> |
| In reply to | #81538 |
On 11/25/2014 07:32 PM, Chris Angelico wrote:
> On Wed, Nov 26, 2014 at 12:18 PM, Tim Daneliuk <tundra@tundraware.com> wrote:
>>> And what should happen with mismatched quotes?
>>>
>>> do("th/*is", "and", "th*/at")
>>
>>
>> Match pairs as usual, and let the remaining unterminated quote run on.
>
> Wait, what? Where's an unterminated quote? I can imagine two ways of
> reading this: one the way most programming languages would interpret
> it (the /* and */ are both simply part of their respective strings,
> and have no significance), and the "anything nests in anything" way,
> in which the quotation marks inside /* */ are effectively inverted;
> neither of those leaves an unterminated quote.
>
> ChrisA
>
But I am not designing a new programming language. I am doing straight up
text processing. I want to know all the instances of S when it is quoted
or not. In my particular application, recovering from a failure of syntax
like this isn't important.
--
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-25 19:18 -0600 |
| Message-ID | <mailman.16301.1416964940.18130.python-list@python.org> |
| In reply to | #81530 |
On 11/25/2014 06:40 PM, Tim Chase wrote:
> On 2014-11-25 18:18, Tim Daneliuk wrote:
>> A problem for your consideration:
>>
>> We are given a tuple of delimiter string pairs to quote or comment
>> text, possibly over multiple lines. Something like this:
>>
>> delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\),
>> ('\\', '\n') ...)
>>
>> These may be nested.
>>
>> Here's the problem: Determine is the string S appears *outside* or
>> *inside* any such quotation.
>
>
> You would have to define what should happen in a case where you have
> more than one single/double-quote delimited items on the same line:
>
> do("this", "and", "that")
Each of them is considered quoted and thus if S appears within
any of them it is "inside".
>
> should it return true or false when testing for 'this", "and",
> "that'? (it is within double-quotes)
False.
>
> And what should happen with mismatched quotes?
>
> do("th/*is", "and", "th*/at")
Match pairs as usual, and let the remaining unterminated quote run on.
>
> It would also help to have a proposed function signature for the
> functionality you want. Something like
>
> def inside_quote(s, corpus, delims=delims):
I'd prefer:
def quoted (s, corpus, delims=delims, domain=outside)
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-26 11:44 +1100 |
| Message-ID | <mailman.16298.1416962702.18130.python-list@python.org> |
| In reply to | #81529 |
On Wed, Nov 26, 2014 at 11:18 AM, Tim Daneliuk <tundra@tundraware.com> wrote:
> A problem for your consideration:
>
> We are given a tuple of delimiter string pairs to quote or comment text,
> possibly over multiple lines. Something like this:
>
> delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\), ('\\', '\n')
> ...)
>
> These may be nested.
>
> Here's the problem: Determine is the string S appears *outside* or *inside*
> any such quotation.
Be aware that, according to the usual definitions, some of those don't
nest... and others may or may not. If you're talking about comment
characters, for instance, /* /* */ */ sometimes nests and sometimes
doesn't; but # # \n \n definitely doesn't nest (two hashes on a line
doesn't extend the comment to another line). Also, they're usually
slashes, not backslashes.
But if your definitions are simple and strict (any of these may be
nested and to any level) and correct (the tuple is exactly the pairs
you're after), then your best bet would be to step through the data,
building up a stack (probably in a Python list) of currently-open
delimiters. As you find open-quote markers, you add to the stack; any
time you find the top-of-stack closing delimiter, you pop it off. When
you find the string S, if the stack is empty, it's outside; otherwise,
it's inside.
You may have issues with your definition of nesting, though. For
instance, what's it mean if you have double-quotes, then a hash? In
normal programming, the hash isn't significant. If that's your
definition, then the only nesting you need worry about is /* and */,
so your parser is quite simple: when you find any opener, you seek its
corresponding closer, and then special-case /* to count any additional
/* and look for a */ for each one */ .
At the moment, the problem's a little underspecified.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-25 19:20 -0600 |
| Message-ID | <mailman.16300.1416964870.18130.python-list@python.org> |
| In reply to | #81531 |
On 11/25/2014 06:44 PM, Chris Angelico wrote: > You may have issues with your definition of nesting, though. For > instance, what's it mean if you have double-quotes, then a hash? It means that the hash is quoted as part of the literal string. > then the only nesting you need worry about is /* and */, Agreed > hen you find any opener, you seek its corresponding closer, and then special-case /* to count any additional /* and look for a */ for each one */ . That's more or less where I was headed. I just wanted something less brute force :) -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-25 19:20 -0600 |
| Message-ID | <54752AF9.70906@tundraware.com> |
| In reply to | #81531 |
On 11/25/2014 06:44 PM, Chris Angelico wrote: > You may have issues with your definition of nesting, though. For > instance, what's it mean if you have double-quotes, then a hash? It means that the hash is quoted as part of the literal string. > then the only nesting you need worry about is /* and */, Agreed > hen you find any opener, you seek its corresponding closer, and then special-case /* to count any additional /* and look for a */ for each one */ . That's more or less where I was headed. I just wanted something less brute force :) -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-11-25 19:44 -0600 |
| Message-ID | <mailman.16303.1416966502.18130.python-list@python.org> |
| In reply to | #81537 |
On 2014-11-25 19:20, Tim Daneliuk wrote: > > hen you find any opener, you seek its > corresponding closer, and then special-case /* to count any > additional /* and look for a */ for each one */ . > > That's more or less where I was headed. I just wanted something > less brute force :) This seems to directly conflict with your initial request that > These may be nested. If they can't be nested, then it simplifies the problem immensely. -tkc
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:01 -0600 |
| Message-ID | <mailman.16307.1416981702.18130.python-list@python.org> |
| In reply to | #81539 |
On 11/25/2014 07:44 PM, Tim Chase wrote: > On 2014-11-25 19:20, Tim Daneliuk wrote: >>> hen you find any opener, you seek its >> corresponding closer, and then special-case /* to count any >> additional /* and look for a */ for each one */ . >> >> That's more or less where I was headed. I just wanted something >> less brute force :) > > This seems to directly conflict with your initial request that > >> These may be nested. > > If they can't be nested, then it simplifies the problem immensely. > > -tkc What I meant was that, to handle nesting, the brute force approach is just to just to use a stack to maintain state. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:01 -0600 |
| Message-ID | <54756CB9.5030607@tundraware.com> |
| In reply to | #81539 |
On 11/25/2014 07:44 PM, Tim Chase wrote: > On 2014-11-25 19:20, Tim Daneliuk wrote: >>> hen you find any opener, you seek its >> corresponding closer, and then special-case /* to count any >> additional /* and look for a */ for each one */ . >> >> That's more or less where I was headed. I just wanted something >> less brute force :) > > This seems to directly conflict with your initial request that > >> These may be nested. > > If they can't be nested, then it simplifies the problem immensely. > > -tkc What I meant was that, to handle nesting, the brute force approach is just to just to use a stack to maintain state. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-11-26 12:54 +1100 |
| Message-ID | <mailman.16304.1416966896.18130.python-list@python.org> |
| In reply to | #81529 |
Tim Daneliuk <tundra@tundraware.com> writes: > Here's the problem: Determine is the string S appears *outside* or > *inside* any such quotation. This is a problem for parsing text. There is no general, simple solution. If someone tries to convince you they have one, be highly suspicious: it will either be not general, or not simple, or neither simple nor general. > I know lots of ugly/complicated/heavyweight ways to solve this, but > I'm wondering if any of you geniuses have a pythonic/elegant/short > algo that solves this. I would recommend one of the following, in descending order of preference: * Try very hard to change the requirements so that the input must be in a mature well-known format for which there are *existing*, maintained, reliable parsers. Use those instead of rolling your own. * If that fails, then: Try very hard to drastically simplify the specified input format so that every possible input is either obviously invalid, or obviously has exactly one meaning. * If that fails, then: Bite the bullet and acknowledge you will be entering the complexities of parsing text. Use a mature library for writing your parser; don't attempt to write a parsing library yourself. *This is the worst option*; changing the requirements for input will be much less pain than this. -- \ “Fear him, which after he hath killed hath power to cast into | `\ hell; yea, I say unto you, Fear him.” –Jesus, as quoted in Luke | _o__) 12:5 | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:04 -0600 |
| Message-ID | <mailman.16308.1416981872.18130.python-list@python.org> |
| In reply to | #81540 |
On 11/25/2014 07:54 PM, Ben Finney wrote: > Tim Daneliuk <tundra@tundraware.com> writes: > >> Here's the problem: Determine is the string S appears *outside* or >> *inside* any such quotation. > > This is a problem for parsing text. There is no general, simple > solution. > > If someone tries to convince you they have one, be highly suspicious: it > will either be not general, or not simple, or neither simple nor general. > >> I know lots of ugly/complicated/heavyweight ways to solve this, but >> I'm wondering if any of you geniuses have a pythonic/elegant/short >> algo that solves this. > > I would recommend one of the following, in descending order of > preference: > > * Try very hard to change the requirements so that the input must be in > a mature well-known format for which there are *existing*, maintained, > reliable parsers. Use those instead of rolling your own. > > * If that fails, then: Try very hard to drastically simplify the > specified input format so that every possible input is either > obviously invalid, or obviously has exactly one meaning. > > * If that fails, then: Bite the bullet and acknowledge you will be > entering the complexities of parsing text. Use a mature library for > writing your parser; don't attempt to write a parsing library > yourself. *This is the worst option*; changing the requirements for > input will be much less pain than this. > In this case, I am not trying to write a fullblown language or recover from syntax errors. Here's a usecase - I want to know whether I need to use a sudo password when the user passes a command on the command line of a program: someprog.py uname && sudo cat /etc/sudoers vs. someprog.py uname && echo "sudo cat /etc/suoders" In the first instance, I need the sudo passoword, in the second I don't. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 00:04 -0600 |
| Message-ID | <54756D5F.4040806@tundraware.com> |
| In reply to | #81540 |
On 11/25/2014 07:54 PM, Ben Finney wrote: > Tim Daneliuk <tundra@tundraware.com> writes: > >> Here's the problem: Determine is the string S appears *outside* or >> *inside* any such quotation. > > This is a problem for parsing text. There is no general, simple > solution. > > If someone tries to convince you they have one, be highly suspicious: it > will either be not general, or not simple, or neither simple nor general. > >> I know lots of ugly/complicated/heavyweight ways to solve this, but >> I'm wondering if any of you geniuses have a pythonic/elegant/short >> algo that solves this. > > I would recommend one of the following, in descending order of > preference: > > * Try very hard to change the requirements so that the input must be in > a mature well-known format for which there are *existing*, maintained, > reliable parsers. Use those instead of rolling your own. > > * If that fails, then: Try very hard to drastically simplify the > specified input format so that every possible input is either > obviously invalid, or obviously has exactly one meaning. > > * If that fails, then: Bite the bullet and acknowledge you will be > entering the complexities of parsing text. Use a mature library for > writing your parser; don't attempt to write a parsing library > yourself. *This is the worst option*; changing the requirements for > input will be much less pain than this. > In this case, I am not trying to write a fullblown language or recover from syntax errors. Here's a usecase - I want to know whether I need to use a sudo password when the user passes a command on the command line of a program: someprog.py uname && sudo cat /etc/sudoers vs. someprog.py uname && echo "sudo cat /etc/suoders" In the first instance, I need the sudo passoword, in the second I don't. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-11-26 18:02 +1100 |
| Subject | Using a password with ‘sudo’ (was: Quotation Ugliness) |
| Message-ID | <mailman.16311.1416985333.18130.python-list@python.org> |
| In reply to | #81547 |
Tim Daneliuk <tundra@tundraware.com> writes: > Here's a usecase - I want to know whether I need to use a sudo > password when the user passes a command on the command line of a > program: […] > In the first instance, I need the sudo passoword, in the second I don't. I don't understand what “need a sudo password” means, or what you would do differently if you detect one case or the other. It's the ‘sudo’ command itself that determines whether you need a password, so what is your Python code going to do differently? -- \ “We have to go forth and crush every world view that doesn't | `\ believe in tolerance and free speech.” —David Brin | _o__) | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-26 18:10 +1100 |
| Message-ID | <mailman.16312.1416985812.18130.python-list@python.org> |
| In reply to | #81547 |
On Wed, Nov 26, 2014 at 5:04 PM, Tim Daneliuk <tundra@tundraware.com> wrote: > Here's a usecase - I want to know whether I need > to use a sudo password when the user passes a command on the command line > of a program: > > someprog.py uname && sudo cat /etc/sudoers > > vs. > > someprog.py uname && echo "sudo cat /etc/suoders" > > > In the first instance, I need the sudo passoword, in the second I don't. This is actually needing the nesting concern that I raised. Compare: someprog.py uname " ' " && sudo cat /etc/sudoers But frankly, you have much MUCH bigger problems than quote characters. Why not set up sudo to not require a password, rather than fiddling with this? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 08:59 -0600 |
| Message-ID | <mailman.16326.1417013991.18130.python-list@python.org> |
| In reply to | #81551 |
On 11/26/2014 01:10 AM, Chris Angelico wrote: > Why not set up sudo to not require a password Because I do not control the machines to which this program is talking and the security policy in question requires passwords. ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundra@tundraware.com> |
|---|---|
| Date | 2014-11-26 08:59 -0600 |
| Message-ID | <5475EAD5.5050505@tundraware.com> |
| In reply to | #81551 |
On 11/26/2014 01:10 AM, Chris Angelico wrote: > Why not set up sudo to not require a password Because I do not control the machines to which this program is talking and the security policy in question requires passwords. ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web