<commit_before>
# Dependencies

 * This stub has been tested on OS X 10.11.5 and Python 2.7.10
 * [urllib2](https://docs.python.org/2/library/urllib2.html) is part of [python 2.7 standard library](https://docs.python.org/2/library/index.html)


# Examples

## Running badssl tests with TryTLS runner.

```
% <path-to-your-trytls>/trytls -t showrunner.bundles.https.badssl_tests python run.py
PASS badssl(True, 'sha1-2016')
PASS badssl(False, 'expired')
```

## Running manually.

```
% python python-urllib2/run.py sha1-2016.badssl.com 443
VERIFY SUCCESS

% python python-urllib2/run.py expired.badssl.com 443
VERIFY FAILURE
```

# Dealing with unexpected behaviour

This stub tries to avoid a situation where traceback gets hidden on unexpected behaviour.

Manual / example test, connecting to non-existent domain.
```
python python-urllib2/run.py https://www.nosuch.example.local/ 443 || echo "$?"
Traceback (most recent call last):
  File "run.py", line 11, in <module>
    urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
    context=self._context)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
1
```

Another example, running with trytls runner when network is not available.

```
% <path-to-your-trytls>/trytls -t showrunner.bundles.https.badssl_tests python run.py
ERROR process exited with return code 1
    Traceback (most recent call last):
      File "run.py", line 11, in <module>
        urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
        return opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
        response = self._open(req, data)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
        '_open', req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
        context=self._context)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
        raise URLError(err)
    urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
ERROR process exited with return code 1
    Traceback (most recent call last):
      File "run.py", line 11, in <module>
        urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
        return opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
        response = self._open(req, data)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
        '_open', req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
        context=self._context)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
        raise URLError(err)
    urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
```



# Credits

Based on python3-urllib -stub.
<commit_msg>stubs/python-urllib2/README.md - language/inconsistency fixes + example to reflect the description.<commit_after>
# Dependencies

 * This stub has been tested on OS X 10.11.5 and Python 2.7.10
 * [urllib2](https://docs.python.org/2/library/urllib2.html) is part of [python 2.7 standard library](https://docs.python.org/2/library/index.html)


# Examples

## Running badssl tests with TryTLS runner.

```
% <path-to-your-trytls>/trytls -t .https.badssl_tests python python-urllib2/run.py
PASS badssl(True, 'sha1-2016')
PASS badssl(False, 'expired')
```

## Running manually.

```
% python python-urllib2/run.py sha1-2016.badssl.com 443
VERIFY SUCCESS

% python python-urllib2/run.py expired.badssl.com 443
VERIFY FAILURE
```

# Dealing with unexpected behavior

This stub tries to avoid a situation where traceback gets hidden on unexpected behaviour.

Manual / example test, connecting to non-existent domain:
```
python python-urllib2/run.py www.nosuch.example.local 443 || echo "$?"
Traceback (most recent call last):
  File "python-urllib2/run.py", line 11, in <module>
    urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
    context=self._context)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

```

Another example, running with trytls runner when network is not available:

```
% <path-to-your-trytls>/trytls -t .https.badssl_tests python run.py
ERROR process exited with return code 1
    Traceback (most recent call last):
      File "run.py", line 11, in <module>
        urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
        return opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
        response = self._open(req, data)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
        '_open', req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
        context=self._context)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
        raise URLError(err)
    urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
ERROR process exited with return code 1
    Traceback (most recent call last):
      File "run.py", line 11, in <module>
        urllib2.urlopen("https://" + host + ":" + port, cafile=cafile)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
        return opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
        response = self._open(req, data)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
        '_open', req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
        context=self._context)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
        raise URLError(err)
    urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
```

# Credits

Based on python3-urllib -stub.

{'fraction_non_alphanumeric': 0.13411078717201166, 'fraction_numerical': 0.04470359572400389, 'mean_word_length': 3.635635635635636, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 11, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5807278', 'n_tokens_mistral': 3463, 'n_tokens_neox': 3192, 'n_words': 708}