Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 migration #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bepasty_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
commandline client for bepasty-server
"""

from __future__ import print_function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it still work on py2 with that?

import base64
import re
import os
Expand All @@ -16,7 +16,7 @@
import codecs
import warnings
try:
from ConfigParser import SafeConfigParser as ConfigParser, Error as ConfigParserError
from configparser import SafeConfigParser as ConfigParser, Error as ConfigParserError
except ImportError:
# Python 3
from configparser import ConfigParser, Error as ConfigParserError
Comment on lines 18 to 22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that doesn't look correct.

the upper block is meant for python 2, so it should be ConfigParser.

if that import fails (e.g. because we are on py3), it is retried in the lower except block.

Expand All @@ -40,7 +40,7 @@
'MINUTES', 'MINUTES', 'HOURS', 'HOURS', 'DAYS', 'DAYS', 'WEEKS', 'WEEKS',
'MONTHS', 'MONTHS', 'YEARS', 'YEARS', 'FOREVER', 'FOREVER'
)
LIFETIME_MAPPING = dict(zip(LIFETIME_CHOICES, LIFETIME_NAMES))
LIFETIME_MAPPING = dict(list(zip(LIFETIME_CHOICES, LIFETIME_NAMES)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why this is needed?

CONFIG_DEFAULTS = dict(
token='',
url='',
Expand Down Expand Up @@ -74,7 +74,7 @@ def setup_config_parser(override=None):
override = dict()
config = ConfigParser()
config.add_section('bepasty-client-cli')
for k, v in CONFIG_DEFAULTS.items():
for k, v in list(CONFIG_DEFAULTS.items()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

v = override.get(k, v)
config.set('bepasty-client-cli', k, str(v))
return config
Expand Down Expand Up @@ -106,7 +106,7 @@ def setup_configuration(ctx, param, value):
except ConfigParserError as exc:
raise click.UsageError('Error in configuration file: {}'.format(exc))
ctx.default_map = dict()
for option in CONFIG_DEFAULTS.keys():
for option in list(CONFIG_DEFAULTS.keys()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

if option == 'insecure':
try:
ctx.default_map[option] = config.getboolean('bepasty-client-cli', option)
Expand Down Expand Up @@ -224,7 +224,7 @@ def print_list(token, url, insecure):
verify=not insecure
)
try:
for k, v in response.json().items():
for k, v in list(response.json().items()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

meta = v['file-meta']
if not meta:
print("{:8}: BROKEN PASTE".format(k))
Expand Down Expand Up @@ -259,7 +259,7 @@ def upload(token, filename, fname, url, ftype, insecure, lifetime):
first_chunk = fileobj.read(read_size)
if not ftype:
mime = magic.Magic(mime=True)
ftype = mime.from_buffer(first_chunk).decode()
ftype = mime.from_buffer(first_chunk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it still work on py2 with that?


if not ftype:
ftype = 'text/plain'
Expand Down