Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

The constructor of Client() checks for AssertionError in validate_url to open a file instead of connection to a URL if it fails. #872

Closed
wants to merge 1 commit into from

2 participants

Hannes Schulz Min RK
Hannes Schulz

The constructor of Client() checks for AssertionError in validate_url to open a file instead of connection to a URL if it fails.

When running python -O, this failed, since the assertions were optimized away and other (random) errors were thrown.
These random errors are not catched. IMHO one should not depend on the side effects of assertions, which has been done here.

Min RK
Owner

Fair point.

I overloaded the validate_url, which is really just supposed to check that a url is valid, but I used it in the client to distinguish between a url and a file, which is inappropriate, since assertions get optimized away.

Do you want to change the try/except in Client from:

try:
   util.validate_url(url_or_file)
except AssertionError:

to:

if not util.is_url(url_or_file):

adding to parallel.util:

def is_url(url):
    """boolean check for whether a string is a zmq url"""
    if '://' not in url:
        return False
    proto, addr = url.split('://', 1)
    if proto.lower() not in ['tcp','pgm','epgm','ipc','inproc']:
        return False
    return True

That way the assertions in validate_url are never used for actual logic, and only used for actual validation, where assertions are appropriate, and appropriate to optimize away when you trust that you don't have certain errors.

Hannes Schulz

This definitely sounds cleaner than my (minimum-impact-solution-) patch, I'd go with your solution!

Min RK
Owner

Did you want to make those changes to your PR, or shall I just make the change?

Hannes Schulz

I changed my commit as you suggested.

Min RK

This needs to be util.is_url, otherwise it gets a NameError. Also, it's indented by a tab instead of 8 spaces for some reason.

Min RK
Owner

Since it's a tiny typo, I'll go ahead and fix it in the merge. Thanks!

Min RK minrk closed this pull request from a commit
Min RK minrk fix is_url typo in parallel client
closes #872
4332951
Min RK minrk closed this in 4332951
Brian E. Granger ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
Min RK minrk fix is_url typo in parallel client
closes #872
75d5d76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2011
  1. Hannes Schulz

    introduce is_url() replacing validate_url() in cases where it is used…

    temporaer authored
    … in a control structure (as opposed to an assert)
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +1 −3 IPython/parallel/client/client.py
  2. +9 −0 IPython/parallel/util.py
4 IPython/parallel/client/client.py
View
@@ -306,9 +306,7 @@ def __init__(self, url_or_file=None, profile=None, profile_dir=None, ipython_dir
assert url_or_file is not None, "I can't find enough information to connect to a hub!"\
" Please specify at least one of url_or_file or profile."
- try:
- util.validate_url(url_or_file)
- except AssertionError:
+ if not is_url(url_or_file):
if not os.path.exists(url_or_file):
if self._cd:
url_or_file = os.path.join(self._cd.security_dir, url_or_file)
9 IPython/parallel/util.py
View
@@ -108,6 +108,15 @@ def asbytes(s):
s = s.encode('ascii')
return s
+def is_url(url):
+ """boolean check for whether a string is a zmq url"""
+ if '://' not in url:
+ return False
+ proto, addr = url.split('://', 1)
+ if proto.lower() not in ['tcp','pgm','epgm','ipc','inproc']:
+ return False
+ return True
+
def validate_url(url):
"""validate a url for zeromq"""
if not isinstance(url, basestring):
Something went wrong with that request. Please try again.