Skip to content

Commit

Permalink
Remove last bits of Python 2 compat code from package. (#574)
Browse files Browse the repository at this point in the history
* CLN : Cleanup last bits of python 2 compat code

- remove coding cookies
- remove future import statements
- remove 2/3 conditionals
- remove try/excepts around imports which changed

* CLN : Remove u-string prefixes

	modified:   jupyter_client/adapter.py
	modified:   jupyter_client/connect.py
	modified:   jupyter_client/jsonutil.py
	modified:   jupyter_client/session.py
	modified:   jupyter_client/tests/test_kernelspec.py
	modified:   jupyter_client/tests/test_session.py
  • Loading branch information
rahulporuri authored Aug 18, 2020
1 parent 97fecbf commit 3f8599f
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 46 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# jupyter_client documentation build configuration file, created by
# sphinx-quickstart on Tue May 26 15:41:51 2015.
Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def extract_oname_v4(code, cursor_pos):
line, _ = code_to_line(code, cursor_pos)

oldline = line
line = _match_bracket.sub(u'', line)
line = _match_bracket.sub('', line)
while oldline != line:
oldline = line
line = _match_bracket.sub(u'', line)
line = _match_bracket.sub('', line)

# remove everything after last open bracket
line = _end_bracket.sub('', line)
Expand Down
5 changes: 1 addition & 4 deletions jupyter_client/blocking/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

try:
from queue import Queue, Empty # Py 3
except ImportError:
from Queue import Queue, Empty # Py 2
from queue import Queue, Empty


class ZMQSocketChannel(object):
Expand Down
2 changes: 0 additions & 2 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ def _stdin_hook_default(self, msg):
content = msg['content']
if content.get('password', False):
prompt = getpass
elif sys.version_info < (3,):
prompt = raw_input
else:
prompt = input

Expand Down
2 changes: 1 addition & 1 deletion jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def load_connection_file(self, connection_file=None):
"""
if connection_file is None:
connection_file = self.connection_file
self.log.debug(u"Loading connection file %s", connection_file)
self.log.debug("Loading connection file %s", connection_file)
with open(connection_file) as f:
info = json.load(f)
self.load_connection_info(info)
Expand Down
3 changes: 1 addition & 2 deletions jupyter_client/jsonutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
"""Utilities to manipulate JSON objects."""

# Copyright (c) Jupyter Development Team.
Expand Down Expand Up @@ -37,7 +36,7 @@ def _ensure_tzinfo(dt):
"""
if not dt.tzinfo:
# No more naïve datetime objects!
warnings.warn(u"Interpreting naive datetime as local %s. Please add timezone info to timestamps." % dt,
warnings.warn("Interpreting naive datetime as local %s. Please add timezone info to timestamps." % dt,
DeprecationWarning,
stacklevel=4)
dt = dt.replace(tzinfo=tzlocal())
Expand Down
2 changes: 0 additions & 2 deletions jupyter_client/kernelspecapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import print_function

import errno
import os.path
import sys
Expand Down
12 changes: 3 additions & 9 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@
import hmac
import logging
import os
import pickle
import pprint
import random
import warnings
from datetime import datetime

try:
import cPickle
pickle = cPickle
except:
cPickle = None
import pickle

PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL

# We are using compare_digest to limit the surface of timing attacks
Expand Down Expand Up @@ -115,7 +109,7 @@ def new_id():
id string (16 random bytes as hex-encoded text, chunks separated by '-')
"""
buf = os.urandom(16)
return u'-'.join(b2a_hex(x).decode('ascii') for x in (
return '-'.join(b2a_hex(x).decode('ascii') for x in (
buf[:4], buf[4:]
))

Expand Down Expand Up @@ -332,7 +326,7 @@ def _unpacker_changed(self, change):
else:
self.unpack = import_item(str(new))

session = CUnicode(u'', config=True,
session = CUnicode('', config=True,
help="""The UUID identifying this session.""")
def _session_default(self):
u = new_id()
Expand Down
3 changes: 0 additions & 3 deletions jupyter_client/ssh/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#
# Redistributed from IPython under the terms of the BSD License.


from __future__ import print_function

import atexit
import os
import re
Expand Down
1 change: 0 additions & 1 deletion jupyter_client/tests/test_jsonutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
"""Test suite for our JSON utilities."""

# Copyright (c) Jupyter Development Team.
Expand Down
3 changes: 1 addition & 2 deletions jupyter_client/tests/test_kernelspec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
"""Tests for the KernelSpecManager"""

# Copyright (c) Jupyter Development Team.
Expand Down Expand Up @@ -156,7 +155,7 @@ def test_validate_kernel_name(self):

for bad in [
'has space',
u'ünicode',
'ünicode',
'%percent',
'question?',
]:
Expand Down
19 changes: 7 additions & 12 deletions jupyter_client/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

import hmac
import os
import sys
import uuid
from datetime import datetime
try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

Expand Down Expand Up @@ -141,9 +137,8 @@ def test_send(self):

# buffers must be contiguous
buf = memoryview(os.urandom(16))
if sys.version_info >= (3,4):
with self.assertRaises(ValueError):
self.session.send(A, msg, ident=b'foo', buffers=[buf[::2]])
with self.assertRaises(ValueError):
self.session.send(A, msg, ident=b'foo', buffers=[buf[::2]])

A.close()
B.close()
Expand All @@ -154,17 +149,17 @@ def test_args(self):
s = self.session
self.assertTrue(s.pack is ss.default_packer)
self.assertTrue(s.unpack is ss.default_unpacker)
self.assertEqual(s.username, os.environ.get('USER', u'username'))
self.assertEqual(s.username, os.environ.get('USER', 'username'))

s = ss.Session()
self.assertEqual(s.username, os.environ.get('USER', u'username'))
self.assertEqual(s.username, os.environ.get('USER', 'username'))

self.assertRaises(TypeError, ss.Session, pack='hi')
self.assertRaises(TypeError, ss.Session, unpack='hi')
u = str(uuid.uuid4())
s = ss.Session(username=u'carrot', session=u)
s = ss.Session(username='carrot', session=u)
self.assertEqual(s.session, u)
self.assertEqual(s.username, u'carrot')
self.assertEqual(s.username, 'carrot')

def test_tracking(self):
"""test tracking messages"""
Expand Down
5 changes: 1 addition & 4 deletions jupyter_client/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import os
pjoin = os.path.join
import sys
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch

import pytest
from jupyter_client import AsyncKernelManager
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
Expand Down

0 comments on commit 3f8599f

Please sign in to comment.