Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#18666 closed defect (worksforme)

ExitPolicy constructor inconsistent

Reported by: Sebastian Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

      print(str(ExitPolicy('reject *:*,')))
      print(str(ExitPolicy('reject6 *:*,')))

the former works, the latter fails

Child Tickets

Change History (2)

comment:1 Changed 3 years ago by atagar

Resolution: worksforme
Status: newclosed

Hi Sebastian, definitely confusing that the behavior is different and this took me a while to figure out. Your calls are incorrect and I was more puzzled why the first was working than why the second was not.

The ExitPolicy class takes a list of rules. For example...

ExitPolicy('reject *:80', 'accept *:*')

Your comma is within the quotes. If you moved it out of the quotes it would work as intended...

>>> str(stem.exit_policy.ExitPolicy('reject *:*',))
'reject *:*'

>>> str(stem.exit_policy.ExitPolicy('reject6 *:*',))
'reject [0000:0000:0000:0000:0000:0000:0000:0000]/0:*'

So why the difference in behavior with your calls? Reason is short circuiting. The 'reject6 *:*,' does the following...

  1. Split on the comma so there's two rules to parse: ["reject6 *:*", ""]
  2. It parses 'reject6 *:*'. That's fine.
  3. It parses "". That gives you the stacktrace you're seeing.

As for the 'reject *:*' it does the following...

  1. Split on the comma so there's two rules to parse: ["reject *:*", ""]
  2. It parses 'reject *:*'. That's fine.
  3. Since it just parsed a full wildcard rule there's no reason to read anything further so we don't attempt to parse the "".

Looks like everything is working as intended. Feel free to reopen if you have any questions or would like something tweaked.

comment:2 Changed 3 years ago by atagar

Actually, I suspect this confusion is because the ExitPolicy does coincidently work with a single string argument...

>>> str(stem.exit_policy.ExitPolicy('reject *:80, accept *:*'))
'reject *:80, accept *:*'

Didn't intend that but it works due to how ExitPolicy handles arguments internally and I'm cool with that. It's an intuitive way to use the class. It only balked on you due to ending the string with a comma.

Pushed a little tweak so the commands you gave now work.

Note: See TracTickets for help on using tickets.