[tor-bugs] #9975 [Flashproxy]: use argparse rather than getopt

Tor Bug Tracker & Wiki blackhole at torproject.org
Sat Jan 18 15:01:32 UTC 2014


#9975: use argparse rather than getopt
-----------------------------+--------------------------
     Reporter:  infinity0    |      Owner:  infinity0
         Type:  enhancement  |     Status:  needs_review
     Priority:  minor        |  Milestone:
    Component:  Flashproxy   |    Version:
   Resolution:               |   Keywords:
Actual Points:               |  Parent ID:
       Points:               |
-----------------------------+--------------------------

Comment (by infinity0):

 There is no technical reason for localising the variables, so we can drop
 those if you feel strongly about it. However, it's generally good to
 restrict the scope of variables as much as possible. In this case, you
 could think of those not as "global options", but options that control the
 ''instantiation'' of the program. If you had a function prog(a,b) that
 called other smaller functions, you wouldn't necessarily want all of those
 smaller functions to see a,b and be able to mutate them.

 For `add_module_opts`: argparse only creates and populates a local
 `namespace` object (containing parsed options across all modules), and
 doesn't touch global state. So we need to copy the state into the module's
 global `options` object. Also, some of these options (e.g.
 `address_family`) are complex enough that argparse's own `parse_args` can
 only handle it incompletely; we need to finish off the job with extra
 logic. If we don't do all of this, then consumers of our module need to do
 it themselves, duplicating code.

 I'll think about a better way for doing `ignore_pubkey`...

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/9975#comment:15>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list