pyline icon indicating copy to clipboard operation
pyline copied to clipboard

ENH: --url/--urlobject: 'u = url = urlobject.URLObject(l) if l else None'

Open westurner opened this issue 10 years ago • 3 comments

  • [ ] ENH,UBY: convenience CLI arguments to cast line to urlobject.URLObject()
    • -u / --url / --urlobject
    • ENH: url = urlobject.URLObject(line)
  • [ ] ENH: provide URL = urlobject.URLObject for the expr
  • [ ] ENH,UBY: try/import URLObject as URL
    • [ ] ENH: URL = urlobject.URLObject
    • [x] TST: pyline -m urlobject 'urlobject.URL(w[0]) (if URLObject is installed)
    • [ ] TST: pyline 'URL(w[0])
    • [ ] TST: pyline "words and URL(w[0])")
    • [ ] TST: pyline --urlobject 'url'
    • [ ] TST: pyline --urlobject "line and url and url.with_scheme('https')")
  • This suggests a need for multiple expressions (e.g. before, kernel, after)
    • Or a registry of event handlers with a defined sequence
    • Because I want to do url=URL(words[1]); url
      • I could either or both parse ; semicolon and eval the expr appropriately
      • Or require each statement to be a separate argument e.g. with action='append'

westurner avatar Jul 25 '15 07:07 westurner

useful e.g. for westurner/dotfiles/scripts/git-upgrade-remote-to-ssh.sh

function git_upgrade_url_to_ssh_pyline {
    echo "${@}" | pyline -m urlobject \
    'l and ((u.with_scheme("ssh").with_username(u.username or "git")) for u in [urlobject.URLObject(l)])'
}

westurner avatar Jul 25 '15 07:07 westurner

So, ideally:

function git_upgrade_url_to_ssh_pyline {
    echo "${@}" | pyline --url \
    'u and u.with_scheme("ssh").with_username(u.username or "git")'
}

westurner avatar Jul 25 '15 07:07 westurner

[edit] See also:

  • ENH: pyline.py: --rgxurl / --rgxuri / --rgxurn to rfc3987 URI/URL regex #20
  • ENH: rfc6570 URI templates #21
  • ENH: --regex to new regex (if installed) #22

westurner avatar Jan 27 '16 19:01 westurner