
import urllib
from pipe2py import util

def pipe_urlbuilder(context, _INPUT, conf, **kwargs):
    """This source builds a url and yields it forever.
    
    Keyword arguments:
    context -- pipeline context
    _INPUT -- not used
    conf:
        BASE -- base
        PATH -- path elements
        PARAM -- query parameters
    
    Yields (_OUTPUT):
    url
    """
    
    for item in _INPUT:
        #note: we could cache get_value results if item==True
        url = util.get_value(conf['BASE'], item, **kwargs)
        if not url.endswith('/'):
            url += '/'
        
        path = util.get_value(conf['PATH'], item, **kwargs)
        if not isinstance(path, list):
            path = [path]
        
        url += "/".join(path)
        url = url.rstrip("/")
        
        params = dict([(util.get_value(p['key'], item, **kwargs), util.get_value(p['value'], item, **kwargs)) for p in conf['PARAM']])
        if params:
            url += "?" + urllib.urlencode(params)
        
        yield url



import urllib
from pipe2py import util

def pipe_urlbuilder(context, _INPUT, conf, **kwargs):
    """This source builds a url and yields it forever.
    
    Keyword arguments:
    context -- pipeline context
    _INPUT -- not used
    conf:
        BASE -- base
        PATH -- path elements
        PARAM -- query parameters
    
    Yields (_OUTPUT):
    url
    """
    
    for item in _INPUT:
        #note: we could cache get_value results if item==True
        url = util.get_value(conf['BASE'], item, **kwargs)
        if not url.endswith('/'):
            url += '/'
        
        path = conf['PATH']
        if not isinstance(path, list):
            path = [path]
        path = [util.get_value(p, item, **kwargs) for p in path]
        
        url += "/".join(path)
        url = url.rstrip("/")
        
        params = dict([(util.get_value(p['key'], item, **kwargs), util.get_value(p['value'], item, **kwargs)) for p in conf['PARAM']])
        if params:
            url += "?" + urllib.urlencode(params)
        
        yield url


Fix to handle multiple path segments
Fix to handle multiple path segments

  
  import urllib
  from pipe2py import util
  
  def pipe_urlbuilder(context, _INPUT, conf, **kwargs):
      """This source builds a url and yields it forever.
      
      Keyword arguments:
      context -- pipeline context
      _INPUT -- not used
      conf:
          BASE -- base
          PATH -- path elements
          PARAM -- query parameters
      
      Yields (_OUTPUT):
      url
      """
      
      for item in _INPUT:
          #note: we could cache get_value results if item==True
          url = util.get_value(conf['BASE'], item, **kwargs)
          if not url.endswith('/'):
              url += '/'
          
-         path = util.get_value(conf['PATH'], item, **kwargs)
+         path = conf['PATH']
          if not isinstance(path, list):
              path = [path]
+         path = [util.get_value(p, item, **kwargs) for p in path]
          
          url += "/".join(path)
          url = url.rstrip("/")
          
          params = dict([(util.get_value(p['key'], item, **kwargs), util.get_value(p['value'], item, **kwargs)) for p in conf['PARAM']])
          if params:
              url += "?" + urllib.urlencode(params)
          
          yield url
  
  
Fix to handle multiple path segments
## Code Before:

import urllib
from pipe2py import util

def pipe_urlbuilder(context, _INPUT, conf, **kwargs):
    """This source builds a url and yields it forever.
    
    Keyword arguments:
    context -- pipeline context
    _INPUT -- not used
    conf:
        BASE -- base
        PATH -- path elements
        PARAM -- query parameters
    
    Yields (_OUTPUT):
    url
    """
    
    for item in _INPUT:
        #note: we could cache get_value results if item==True
        url = util.get_value(conf['BASE'], item, **kwargs)
        if not url.endswith('/'):
            url += '/'
        
        path = util.get_value(conf['PATH'], item, **kwargs)
        if not isinstance(path, list):
            path = [path]
        
        url += "/".join(path)
        url = url.rstrip("/")
        
        params = dict([(util.get_value(p['key'], item, **kwargs), util.get_value(p['value'], item, **kwargs)) for p in conf['PARAM']])
        if params:
            url += "?" + urllib.urlencode(params)
        
        yield url


## Instruction:
Fix to handle multiple path segments
## Code After:

import urllib
from pipe2py import util

def pipe_urlbuilder(context, _INPUT, conf, **kwargs):
    """This source builds a url and yields it forever.
    
    Keyword arguments:
    context -- pipeline context
    _INPUT -- not used
    conf:
        BASE -- base
        PATH -- path elements
        PARAM -- query parameters
    
    Yields (_OUTPUT):
    url
    """
    
    for item in _INPUT:
        #note: we could cache get_value results if item==True
        url = util.get_value(conf['BASE'], item, **kwargs)
        if not url.endswith('/'):
            url += '/'
        
        path = conf['PATH']
        if not isinstance(path, list):
            path = [path]
        path = [util.get_value(p, item, **kwargs) for p in path]
        
        url += "/".join(path)
        url = url.rstrip("/")
        
        params = dict([(util.get_value(p['key'], item, **kwargs), util.get_value(p['value'], item, **kwargs)) for p in conf['PARAM']])
        if params:
            url += "?" + urllib.urlencode(params)
        
        yield url

