Пример #1
0
 def test_is_Tuple(self):
     assert is_Tuple(())
     try:
         class mytuple(tuple):
             pass
     except TypeError:
         pass
     else:
         assert is_Tuple(mytuple(()))
     assert not is_Tuple([])
     assert not is_Tuple({})
     assert not is_Tuple("")
Пример #2
0
 def sub_match(match, val=val, matchlist=matchlist):
     a = match.group(1)
     if a in matchlist:
         a = val
     if is_List(a) or is_Tuple(a):
         return string.join(map(str, a))
     else:
         return str(a)
Пример #3
0
def scons_subst_once(strSubst, env, key):
    """Perform single (non-recursive) substitution of a single
    construction variable keyword.

    This is used when setting a variable when copying or overriding values
    in an Environment.  We want to capture (expand) the old value before
    we override it, so people can do things like:

        env2 = env.Clone(CCFLAGS = '$CCFLAGS -g')

    We do this with some straightforward, brute-force code here...
    """
    if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0:
        return strSubst

    matchlist = ['$' + key, '${' + key + '}']
    val = env.get(key, '')

    def sub_match(match, val=val, matchlist=matchlist):
        a = match.group(1)
        if a in matchlist:
            a = val
        if is_List(a) or is_Tuple(a):
            return string.join(map(str, a))
        else:
            return str(a)

    if is_List(strSubst) or is_Tuple(strSubst):
        result = []
        for arg in strSubst:
            if is_String(arg):
                if arg in matchlist:
                    arg = val
                    if is_List(arg) or is_Tuple(arg):
                        result.extend(arg)
                    else:
                        result.append(arg)
                else:
                    result.append(_dollar_exps.sub(sub_match, arg))
            else:
                result.append(arg)
        return result
    elif is_String(strSubst):
        return _dollar_exps.sub(sub_match, strSubst)
    else:
        return strSubst
Пример #4
0
 def sub_match(match, val=val, matchlist=matchlist):
     a = match.group(1)
     if a in matchlist:
         a = val
     if is_List(a) or is_Tuple(a):
         return string.join(map(str, a))
     else:
         return str(a)
Пример #5
0
def scons_subst_once(strSubst, env, key):
    """Perform single (non-recursive) substitution of a single
    construction variable keyword.

    This is used when setting a variable when copying or overriding values
    in an Environment.  We want to capture (expand) the old value before
    we override it, so people can do things like:

        env2 = env.Clone(CCFLAGS = '$CCFLAGS -g')

    We do this with some straightforward, brute-force code here...
    """
    if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0:
        return strSubst

    matchlist = ['$' + key, '${' + key + '}']
    val = env.get(key, '')
    def sub_match(match, val=val, matchlist=matchlist):
        a = match.group(1)
        if a in matchlist:
            a = val
        if is_List(a) or is_Tuple(a):
            return string.join(map(str, a))
        else:
            return str(a)

    if is_List(strSubst) or is_Tuple(strSubst):
        result = []
        for arg in strSubst:
            if is_String(arg):
                if arg in matchlist:
                    arg = val
                    if is_List(arg) or is_Tuple(arg):
                        result.extend(arg)
                    else:
                        result.append(arg)
                else:
                    result.append(_dollar_exps.sub(sub_match, arg))
            else:
                result.append(arg)
        return result
    elif is_String(strSubst):
        return _dollar_exps.sub(sub_match, strSubst)
    else:
        return strSubst
Пример #6
0
 def _gen_nodelist(self):
     list = self.list
     if list is None:
         list = []
     elif not is_List(list) and not is_Tuple(list):
         list = [list]
     # The map(self.func) call is what actually turns
     # a list into appropriate proxies.
     self.nodelist = SCons.Util.NodeList(map(self.func, list))
     self._create_nodelist = self._return_nodelist
     return self.nodelist
Пример #7
0
 def _gen_nodelist(self):
     list = self.list
     if list is None:
         list = []
     elif not is_List(list) and not is_Tuple(list):
         list = [list]
     # The map(self.func) call is what actually turns
     # a list into appropriate proxies.
     self.nodelist = SCons.Util.NodeList(map(self.func, list))
     self._create_nodelist = self._return_nodelist
     return self.nodelist
Пример #8
0
def scons_subst_list(strSubst,
                     env,
                     mode=SUBST_RAW,
                     target=None,
                     source=None,
                     gvars={},
                     lvars={},
                     conv=None):
    """Substitute construction variables in a string (or list or other
    object) and separate the arguments into a command list.

    The companion scons_subst() function (above) handles basic
    substitutions within strings, so see that function instead
    if that's what you're looking for.
    """

    #    try:
    #        Subst_List_Strings[strSubst] = Subst_List_Strings[strSubst] + 1
    #    except KeyError:
    #        Subst_List_Strings[strSubst] = 1
    #    import SCons.Debug
    #    SCons.Debug.caller(1)
    class ListSubber(UserList.UserList):
        """A class to construct the results of a scons_subst_list() call.

        Like StringSubber, this class binds a specific construction
        environment, mode, target and source with two methods
        (substitute() and expand()) that handle the expansion.

        In addition, however, this class is used to track the state of
        the result(s) we're gathering so we can do the appropriate thing
        whenever we have to append another word to the result--start a new
        line, start a new word, append to the current word, etc.  We do
        this by setting the "append" attribute to the right method so
        that our wrapper methods only need ever call ListSubber.append(),
        and the rest of the object takes care of doing the right thing
        internally.
        """
        def __init__(self, env, mode, target, source, conv, gvars):
            UserList.UserList.__init__(self, [])
            self.env = env
            self.mode = mode
            self.target = target
            self.source = source
            self.conv = conv
            self.gvars = gvars

            if self.mode == SUBST_RAW:
                self.add_strip = lambda x, s=self: s.append(x)
            else:
                self.add_strip = lambda x, s=self: None
            self.in_strip = None
            self.next_line()

        def expand(self, s, lvars, within_list):
            """Expand a single "token" as necessary, appending the
            expansion to the current result.

            This handles expanding different types of things (strings,
            lists, callables) appropriately.  It calls the wrapper
            substitute() method to re-expand things as necessary, so that
            the results of expansions of side-by-side strings still get
            re-evaluated separately, not smushed together.
            """

            if is_String(s):
                try:
                    s0, s1 = s[:2]
                except (IndexError, ValueError):
                    self.append(s)
                    return
                if s0 != '$':
                    self.append(s)
                    return
                if s1 == '$':
                    self.append('$')
                elif s1 == '(':
                    self.open_strip('$(')
                elif s1 == ')':
                    self.close_strip('$)')
                else:
                    key = s[1:]
                    if key[0] == '{' or string.find(key, '.') >= 0:
                        if key[0] == '{':
                            key = key[1:-1]
                        try:
                            s = eval(key, self.gvars, lvars)
                        except KeyboardInterrupt:
                            raise
                        except Exception, e:
                            if e.__class__ in AllowableExceptions:
                                return
                            raise_exception(e, self.target, s)
                    else:
                        if lvars.has_key(key):
                            s = lvars[key]
                        elif self.gvars.has_key(key):
                            s = self.gvars[key]
                        elif not NameError in AllowableExceptions:
                            raise_exception(NameError(), self.target, s)
                        else:
                            return

                    # Before re-expanding the result, handle
                    # recursive expansion by copying the local
                    # variable dictionary and overwriting a null
                    # string for the value of the variable name
                    # we just expanded.
                    lv = lvars.copy()
                    var = string.split(key, '.')[0]
                    lv[var] = ''
                    self.substitute(s, lv, 0)
                    self.this_word()
            elif is_List(s) or is_Tuple(s):
                for a in s:
                    self.substitute(a, lvars, 1)
                    self.next_word()
Пример #9
0
def scons_subst(strSubst,
                env,
                mode=SUBST_RAW,
                target=None,
                source=None,
                gvars={},
                lvars={},
                conv=None):
    """Expand a string containing construction variable substitutions.

    This is the work-horse function for substitutions in file names
    and the like.  The companion scons_subst_list() function (below)
    handles separating command lines into lists of arguments, so see
    that function if that's what you're looking for.
    """
    if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0:
        return strSubst

    class StringSubber:
        """A class to construct the results of a scons_subst() call.

        This binds a specific construction environment, mode, target and
        source with two methods (substitute() and expand()) that handle
        the expansion.
        """
        def __init__(self, env, mode, target, source, conv, gvars):
            self.env = env
            self.mode = mode
            self.target = target
            self.source = source
            self.conv = conv
            self.gvars = gvars

        def expand(self, s, lvars):
            """Expand a single "token" as necessary, returning an
            appropriate string containing the expansion.

            This handles expanding different types of things (strings,
            lists, callables) appropriately.  It calls the wrapper
            substitute() method to re-expand things as necessary, so that
            the results of expansions of side-by-side strings still get
            re-evaluated separately, not smushed together.
            """
            if is_String(s):
                try:
                    s0, s1 = s[:2]
                except (IndexError, ValueError):
                    return s
                if s0 != '$':
                    return s
                if s1 == '$':
                    return '$'
                elif s1 in '()':
                    return s
                else:
                    key = s[1:]
                    if key[0] == '{' or string.find(key, '.') >= 0:
                        if key[0] == '{':
                            key = key[1:-1]
                        try:
                            s = eval(key, self.gvars, lvars)
                        except KeyboardInterrupt:
                            raise
                        except Exception, e:
                            if e.__class__ in AllowableExceptions:
                                return ''
                            raise_exception(e, self.target, s)
                    else:
                        if lvars.has_key(key):
                            s = lvars[key]
                        elif self.gvars.has_key(key):
                            s = self.gvars[key]
                        elif not NameError in AllowableExceptions:
                            raise_exception(NameError(key), self.target, s)
                        else:
                            return ''

                    # Before re-expanding the result, handle
                    # recursive expansion by copying the local
                    # variable dictionary and overwriting a null
                    # string for the value of the variable name
                    # we just expanded.
                    #
                    # This could potentially be optimized by only
                    # copying lvars when s contains more expansions,
                    # but lvars is usually supposed to be pretty
                    # small, and deeply nested variable expansions
                    # are probably more the exception than the norm,
                    # so it should be tolerable for now.
                    lv = lvars.copy()
                    var = string.split(key, '.')[0]
                    lv[var] = ''
                    return self.substitute(s, lv)
            elif is_List(s) or is_Tuple(s):

                def func(l,
                         conv=self.conv,
                         substitute=self.substitute,
                         lvars=lvars):
                    return conv(substitute(l, lvars))

                r = map(func, s)
                return string.join(r)
Пример #10
0
def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={}, lvars={}, conv=None):
    """Substitute construction variables in a string (or list or other
    object) and separate the arguments into a command list.

    The companion scons_subst() function (above) handles basic
    substitutions within strings, so see that function instead
    if that's what you're looking for.
    """
#    try:
#        Subst_List_Strings[strSubst] = Subst_List_Strings[strSubst] + 1
#    except KeyError:
#        Subst_List_Strings[strSubst] = 1
#    import SCons.Debug
#    SCons.Debug.caller(1)
    class ListSubber(UserList.UserList):
        """A class to construct the results of a scons_subst_list() call.

        Like StringSubber, this class binds a specific construction
        environment, mode, target and source with two methods
        (substitute() and expand()) that handle the expansion.

        In addition, however, this class is used to track the state of
        the result(s) we're gathering so we can do the appropriate thing
        whenever we have to append another word to the result--start a new
        line, start a new word, append to the current word, etc.  We do
        this by setting the "append" attribute to the right method so
        that our wrapper methods only need ever call ListSubber.append(),
        and the rest of the object takes care of doing the right thing
        internally.
        """
        def __init__(self, env, mode, target, source, conv, gvars):
            UserList.UserList.__init__(self, [])
            self.env = env
            self.mode = mode
            self.target = target
            self.source = source
            self.conv = conv
            self.gvars = gvars

            if self.mode == SUBST_RAW:
                self.add_strip = lambda x, s=self: s.append(x)
            else:
                self.add_strip = lambda x, s=self: None
            self.in_strip = None
            self.next_line()

        def expand(self, s, lvars, within_list):
            """Expand a single "token" as necessary, appending the
            expansion to the current result.

            This handles expanding different types of things (strings,
            lists, callables) appropriately.  It calls the wrapper
            substitute() method to re-expand things as necessary, so that
            the results of expansions of side-by-side strings still get
            re-evaluated separately, not smushed together.
            """

            if is_String(s):
                try:
                    s0, s1 = s[:2]
                except (IndexError, ValueError):
                    self.append(s)
                    return
                if s0 != '$':
                    self.append(s)
                    return
                if s1 == '$':
                    self.append('$')
                elif s1 == '(':
                    self.open_strip('$(')
                elif s1 == ')':
                    self.close_strip('$)')
                else:
                    key = s[1:]
                    if key[0] == '{' or string.find(key, '.') >= 0:
                        if key[0] == '{':
                            key = key[1:-1]
                        try:
                            s = eval(key, self.gvars, lvars)
                        except KeyboardInterrupt:
                            raise
                        except Exception, e:
                            if e.__class__ in AllowableExceptions:
                                return
                            raise_exception(e, self.target, s)
                    else:
                        if lvars.has_key(key):
                            s = lvars[key]
                        elif self.gvars.has_key(key):
                            s = self.gvars[key]
                        elif not NameError in AllowableExceptions:
                            raise_exception(NameError(), self.target, s)
                        else:
                            return

                    # Before re-expanding the result, handle
                    # recursive expansion by copying the local
                    # variable dictionary and overwriting a null
                    # string for the value of the variable name
                    # we just expanded.
                    lv = lvars.copy()
                    var = string.split(key, '.')[0]
                    lv[var] = ''
                    self.substitute(s, lv, 0)
                    self.this_word()
            elif is_List(s) or is_Tuple(s):
                for a in s:
                    self.substitute(a, lvars, 1)
                    self.next_word()
Пример #11
0
def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={}, lvars={}, conv=None):
    """Expand a string containing construction variable substitutions.

    This is the work-horse function for substitutions in file names
    and the like.  The companion scons_subst_list() function (below)
    handles separating command lines into lists of arguments, so see
    that function if that's what you're looking for.
    """
    if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0:
        return strSubst

    class StringSubber:
        """A class to construct the results of a scons_subst() call.

        This binds a specific construction environment, mode, target and
        source with two methods (substitute() and expand()) that handle
        the expansion.
        """
        def __init__(self, env, mode, target, source, conv, gvars):
            self.env = env
            self.mode = mode
            self.target = target
            self.source = source
            self.conv = conv
            self.gvars = gvars

        def expand(self, s, lvars):
            """Expand a single "token" as necessary, returning an
            appropriate string containing the expansion.

            This handles expanding different types of things (strings,
            lists, callables) appropriately.  It calls the wrapper
            substitute() method to re-expand things as necessary, so that
            the results of expansions of side-by-side strings still get
            re-evaluated separately, not smushed together.
            """
            if is_String(s):
                try:
                    s0, s1 = s[:2]
                except (IndexError, ValueError):
                    return s
                if s0 != '$':
                    return s
                if s1 == '$':
                    return '$'
                elif s1 in '()':
                    return s
                else:
                    key = s[1:]
                    if key[0] == '{' or string.find(key, '.') >= 0:
                        if key[0] == '{':
                            key = key[1:-1]
                        try:
                            s = eval(key, self.gvars, lvars)
                        except KeyboardInterrupt:
                            raise
                        except Exception, e:
                            if e.__class__ in AllowableExceptions:
                                return ''
                            raise_exception(e, self.target, s)
                    else:
                        if lvars.has_key(key):
                            s = lvars[key]
                        elif self.gvars.has_key(key):
                            s = self.gvars[key]
                        elif not NameError in AllowableExceptions:
                            raise_exception(NameError(key), self.target, s)
                        else:
                            return ''
    
                    # Before re-expanding the result, handle
                    # recursive expansion by copying the local
                    # variable dictionary and overwriting a null
                    # string for the value of the variable name
                    # we just expanded.
                    #
                    # This could potentially be optimized by only
                    # copying lvars when s contains more expansions,
                    # but lvars is usually supposed to be pretty
                    # small, and deeply nested variable expansions
                    # are probably more the exception than the norm,
                    # so it should be tolerable for now.
                    lv = lvars.copy()
                    var = string.split(key, '.')[0]
                    lv[var] = ''
                    return self.substitute(s, lv)
            elif is_List(s) or is_Tuple(s):
                def func(l, conv=self.conv, substitute=self.substitute, lvars=lvars):
                    return conv(substitute(l, lvars))
                r = map(func, s)
                return string.join(r)
Пример #12
0
         # recursive expansion by copying the local
         # variable dictionary and overwriting a null
         # string for the value of the variable name
         # we just expanded.
         #
         # This could potentially be optimized by only
         # copying lvars when s contains more expansions,
         # but lvars is usually supposed to be pretty
         # small, and deeply nested variable expansions
         # are probably more the exception than the norm,
         # so it should be tolerable for now.
         lv = lvars.copy()
         var = string.split(key, '.')[0]
         lv[var] = ''
         return self.substitute(s, lv)
 elif is_List(s) or is_Tuple(s):
     def func(l, conv=self.conv, substitute=self.substitute, lvars=lvars):
         return conv(substitute(l, lvars))
     r = map(func, s)
     return string.join(r)
 elif callable(s):
     try:
         s = s(target=self.target,
              source=self.source,
              env=self.env,
              for_signature=(self.mode != SUBST_CMD))
     except TypeError:
         # This probably indicates that it's a callable
         # object that doesn't match our calling arguments
         # (like an Action).
         s = str(s)
Пример #13
0
         # recursive expansion by copying the local
         # variable dictionary and overwriting a null
         # string for the value of the variable name
         # we just expanded.
         #
         # This could potentially be optimized by only
         # copying lvars when s contains more expansions,
         # but lvars is usually supposed to be pretty
         # small, and deeply nested variable expansions
         # are probably more the exception than the norm,
         # so it should be tolerable for now.
         lv = lvars.copy()
         var = string.split(key, '.')[0]
         lv[var] = ''
         return self.substitute(s, lv)
 elif is_List(s) or is_Tuple(s):
     def func(l, conv=self.conv, substitute=self.substitute, lvars=lvars):
         return conv(substitute(l, lvars))
     r = map(func, s)
     return string.join(r)
 elif callable(s):
     try:
         s = s(target=self.target,
              source=self.source,
              env=self.env,
              for_signature=(self.mode != SUBST_CMD))
     except TypeError:
         # This probably indicates that it's a callable
         # object that doesn't match our calling arguments
         # (like an Action).
         s = str(s)