def pathjoin(*args, **kwargs):
log.debug('<STR_LIT>' % list(args))<EOL>def _pathjoin(*args, **kwargs):<EOL><INDENT>len_ = len(args) - <NUM_LIT:1><EOL>if len_ < <NUM_LIT:0>:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>elif len_ == <NUM_LIT:0>:<EOL><INDENT>if not isinstance(args, basestring):<EOL><INDENT>if hasattr(args, '<STR_LIT>'):<EOL><INDENT>_args = args<EOL>_args<EOL>args = args[<NUM_LIT:0>]<EOL><DEDENT><DEDENT><DEDENT>for i, arg in enumerate(args):<EOL><INDENT>if not i:<EOL><INDENT>yield arg.rstrip('<STR_LIT:/>')<EOL><DEDENT>elif i == len_:<EOL><INDENT>yield arg.lstrip('<STR_LIT:/>')<EOL><DEDENT>else:<EOL><INDENT>yield arg.strip('<STR_LIT:/>')<EOL><DEDENT><DEDENT><DEDENT>joined_path = u'<STR_LIT:/>'.join(_pathjoin(*args))<EOL>return sanitize_path(joined_path)<EOL>
Arguments:
    args (list): *args list of paths
        if len(args) == 1, args[0] is not a string, and args[0] is iterable,
        set args to args[0].

Basically::

    joined_path = u'/'.join(
        [args[0].rstrip('/')] +
        [a.strip('/') for a in args[1:-1]] +
        [args[-1].lstrip('/')])