File: //proc/self/root/usr/lib64/python2.7/site-packages/mercurial/fancyopts.pyc
�
1�3\c @@ s d d l m Z d d l Z d d l Z d d l m Z d d l m Z m Z d d d h Z d � Z
e e d
� Z d e
f d � � YZ d
e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d � Z e e d d � Z d S( i ( t absolute_importNi ( t _( t errort pycompatt noninteractivet helpt versionc C@ s | j d � rz | j d � \ } } } | d | k rM | t | � | t f S| d d | k r| t | � | t f Sn� | j d � r| d k r| j d � r| d | d } } | j | d � } | d k r| t | � | | j d | d � f Sn d t d t f S(
s� Check if the given arg is a valid unabbreviated option
Returns (flag_str, has_embedded_value?, embedded_value, takes_value?)
>>> def opt(arg):
... return _earlyoptarg(arg, b'R:q', [b'cwd=', b'debugger'])
long form:
>>> opt(b'--cwd')
('--cwd', False, '', True)
>>> opt(b'--cwd=')
('--cwd', True, '', True)
>>> opt(b'--cwd=foo')
('--cwd', True, 'foo', True)
>>> opt(b'--debugger')
('--debugger', False, '', False)
>>> opt(b'--debugger=') # invalid but parsable
('--debugger', True, '', False)
short form:
>>> opt(b'-R')
('-R', False, '', True)
>>> opt(b'-Rfoo')
('-R', True, 'foo', True)
>>> opt(b'-q')
('-q', False, '', False)
>>> opt(b'-qfoo') # invalid but parsable
('-q', True, 'foo', False)
unknown or invalid:
>>> opt(b'--unknown')
('', False, '', False)
>>> opt(b'-u')
('', False, '', False)
>>> opt(b'-ufoo')
('', False, '', False)
>>> opt(b'--')
('', False, '', False)
>>> opt(b'-')
('', False, '', False)
>>> opt(b'-:')
('', False, '', False)
>>> opt(b'-:foo')
('', False, '', False)
s --t =i t -s -:i i t :t ( t
startswitht partitiont boolt Falset Truet find( t argt shortlistt namelistt flagt eqt valt i( ( s9 /usr/lib64/python2.7/site-packages/mercurial/fancyopts.pyt _earlyoptarg s 1+)c
C@ s9 g } g } d } x | t | � k r| | } | d k rL | | 7} Pn t | | | � \ } }
} } |
r� | r� | d t | � k r� Pn | s� |
r� | r� | r� | j | � | d 7} qPq |
| k r� | j | | f � | d 7} q | j | | | d f � | d 7} q W| j | | � | | f S( ss
Parse options like getopt, but ignores unknown options and abbreviated
forms
If gnu=False, this stops processing options as soon as a non/unknown-option
argument is encountered. Otherwise, option and non-option arguments may be
intermixed, and unknown-option arguments are taken as non-option.
If keepsep=True, '--' won't be removed from the list of arguments left.
This is useful for stripping early options from a full command arguments.
>>> def get(args, gnu=False, keepsep=False):
... return earlygetopt(args, b'R:q', [b'cwd=', b'debugger'],
... gnu=gnu, keepsep=keepsep)
default parsing rules for early options:
>>> get([b'x', b'--cwd', b'foo', b'-Rbar', b'-q', b'y'], gnu=True)
([('--cwd', 'foo'), ('-R', 'bar'), ('-q', '')], ['x', 'y'])
>>> get([b'x', b'--cwd=foo', b'y', b'-R', b'bar', b'--debugger'], gnu=True)
([('--cwd', 'foo'), ('-R', 'bar'), ('--debugger', '')], ['x', 'y'])
>>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=True)
([('--cwd', 'foo')], ['--unknown', '--debugger'])
restricted parsing rules (early options must come first):
>>> get([b'--cwd', b'foo', b'-Rbar', b'x', b'-q', b'y'], gnu=False)
([('--cwd', 'foo'), ('-R', 'bar')], ['x', '-q', 'y'])
>>> get([b'--cwd=foo', b'x', b'y', b'-R', b'bar', b'--debugger'], gnu=False)
([('--cwd', 'foo')], ['x', 'y', '-R', 'bar', '--debugger'])
>>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=False)
([], ['--unknown', '--cwd=foo', '--', '--debugger'])
stripping early options (without loosing '--'):
>>> get([b'x', b'-Rbar', b'--', '--debugger'], gnu=True, keepsep=True)[1]
['x', '--', '--debugger']
last argument:
>>> get([b'--cwd'])
([], ['--cwd'])
>>> get([b'--cwd=foo'])
([('--cwd', 'foo')], [])
>>> get([b'-R'])
([], ['-R'])
>>> get([b'-Rbar'])
([('-R', 'bar')], [])
>>> get([b'-q'])
([('-q', '')], [])
>>> get([b'-q', b'--'])
([('-q', '')], [])
'--' may be a value:
>>> get([b'-R', b'--', b'x'])
([('-R', '--')], ['x'])
>>> get([b'--cwd', b'--', b'x'])
([('--cwd', '--')], ['x'])
value passed to bool options:
>>> get([b'--debugger=foo', b'x'])
([], ['--debugger=foo', 'x'])
>>> get([b'-qfoo', b'x'])
([], ['-qfoo', 'x'])
short option isn't separated with '=':
>>> get([b'-R=bar'])
([('-R', '=bar')], [])
':' may be in shortlist, but shouldn't be taken as an option letter:
>>> get([b'-:', b'y'])
([], ['-:', 'y'])
'-' is a valid non-option argument:
>>> get([b'-', b'y'])
([], ['-', 'y'])
i s --i i ( t lenR t appendt extend(
t argsR R t gnut keepsept
parsedoptst
parsedargst posR R t hasvalR t takeval( ( s9 /usr/lib64/python2.7/site-packages/mercurial/fancyopts.pyt earlygetopt\ s. R
#
t customoptc B@ sD e Z d Z e j Z d � Z d � Z d � Z e j d � � Z
RS( s2 Manage defaults and mutations for any type of opt.c C@ s
| | _ d S( N( t
_defaultvalue( t selft defaultvalue( ( s9 /usr/lib64/python2.7/site-packages/mercurial/fancyopts.pyt __init__� s c C@ s t S( N( R ( R'