mirror of https://github.com/zulip/zulip.git
Apply modernize transform libmodernize.fixes.fix_file.
This replaces use of file() with open() which is python 3 compatible, and also adds it to our python 3 support test suite.
This commit is contained in:
parent
83dd51dcd6
commit
700055c194
|
@ -164,7 +164,7 @@ class Client(object):
|
|||
config_file = get_default_config_filename()
|
||||
if os.path.exists(config_file):
|
||||
config = SafeConfigParser()
|
||||
with file(config_file, 'r') as f:
|
||||
with open(config_file, 'r') as f:
|
||||
config.readfp(f, config_file)
|
||||
if api_key is None:
|
||||
api_key = config.get("api", "key")
|
||||
|
|
|
@ -10,7 +10,7 @@ def nagios_from_file(results_file):
|
|||
This file is created by various nagios checking cron jobs such as
|
||||
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
||||
|
||||
data = file(results_file).read().strip()
|
||||
data = open(results_file).read().strip()
|
||||
pieces = data.split('|')
|
||||
|
||||
if not len(pieces) == 4:
|
||||
|
|
|
@ -376,7 +376,7 @@ option does not affect login credentials.'''.replace("\n", " "))
|
|||
|
||||
config = SafeConfigParser()
|
||||
try:
|
||||
with file(config_file, 'r') as f:
|
||||
with open(config_file, 'r') as f:
|
||||
config.readfp(f, config_file)
|
||||
except IOError:
|
||||
pass
|
||||
|
|
|
@ -9,7 +9,7 @@ ccache_data_encoded = sys.argv[3]
|
|||
|
||||
# Update the Kerberos ticket cache file
|
||||
program_name = "zmirror-%s" % (short_user,)
|
||||
with file("/home/zulip/ccache/%s" % (program_name,), "w") as f:
|
||||
with open("/home/zulip/ccache/%s" % (program_name,), "w") as f:
|
||||
f.write(base64.b64decode(ccache_data_encoded))
|
||||
|
||||
# Setup API key
|
||||
|
|
|
@ -191,7 +191,7 @@ def zephyr_bulk_subscribe(subs):
|
|||
|
||||
def update_subscriptions():
|
||||
try:
|
||||
f = file(options.stream_file_path, "r")
|
||||
f = open(options.stream_file_path, "r")
|
||||
public_streams = simplejson.loads(f.read())
|
||||
f.close()
|
||||
except:
|
||||
|
@ -287,7 +287,7 @@ def parse_zephyr_body(zephyr_data):
|
|||
|
||||
def parse_crypt_table(zephyr_class, instance):
|
||||
try:
|
||||
crypt_table = file(os.path.join(os.environ["HOME"], ".crypt-table"))
|
||||
crypt_table = open(os.path.join(os.environ["HOME"], ".crypt-table"))
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
|
@ -349,7 +349,7 @@ def process_notice(notice, log):
|
|||
|
||||
if zephyr_class == options.nagios_class:
|
||||
# Mark that we got the message and proceed
|
||||
with file(options.nagios_path, "w") as f:
|
||||
with open(options.nagios_path, "w") as f:
|
||||
f.write("0\n")
|
||||
return
|
||||
|
||||
|
@ -468,7 +468,7 @@ def zephyr_load_session_autoretry(session_path):
|
|||
backoff = zulip.RandomExponentialBackoff()
|
||||
while backoff.keep_going():
|
||||
try:
|
||||
session = file(session_path, "r").read()
|
||||
session = open(session_path, "r").read()
|
||||
zephyr._z.initialize()
|
||||
zephyr._z.load_session(session)
|
||||
zephyr.__inited = True
|
||||
|
@ -510,7 +510,7 @@ def zephyr_to_zulip(options):
|
|||
if options.nagios_class:
|
||||
zephyr_subscribe_autoretry((options.nagios_class, "*", "*"))
|
||||
if options.use_sessions:
|
||||
file(options.session_path, "w").write(zephyr._z.dump_session())
|
||||
open(options.session_path, "w").write(zephyr._z.dump_session())
|
||||
|
||||
if options.logs_to_resend is not None:
|
||||
with open(options.logs_to_resend, 'r') as log:
|
||||
|
@ -857,7 +857,7 @@ def parse_zephyr_subs(verbose=False):
|
|||
logger.error("Couldn't find ~/.zephyr.subs!")
|
||||
return []
|
||||
|
||||
for line in file(subs_file, "r").readlines():
|
||||
for line in open(subs_file, "r").readlines():
|
||||
line = line.strip()
|
||||
if len(line) == 0:
|
||||
continue
|
||||
|
@ -1050,7 +1050,7 @@ Could not find API key file.
|
|||
You need to either place your api key file at %s,
|
||||
or specify the --api-key-file option.""" % (options.api_key_file,))))
|
||||
sys.exit(1)
|
||||
api_key = file(options.api_key_file).read().strip()
|
||||
api_key = open(options.api_key_file).read().strip()
|
||||
# Store the API key in the environment so that our children
|
||||
# don't need to read it in
|
||||
os.environ["HUMBUG_API_KEY"] = api_key
|
||||
|
|
|
@ -70,7 +70,7 @@ for filepath in files:
|
|||
_, exn = path.splitext(filepath)
|
||||
if not exn:
|
||||
# No extension; look at the first line
|
||||
with file(filepath) as f:
|
||||
with open(filepath) as f:
|
||||
if re.match(r'^#!.*\bpython', f.readline()):
|
||||
exn = '.py'
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ doc.write(r'''
|
|||
''')
|
||||
doc.close()
|
||||
|
||||
with file('tools/print-all/tex/epilogue.tex', 'w') as f:
|
||||
with open('tools/print-all/tex/epilogue.tex', 'w') as f:
|
||||
def print_list(title, xs):
|
||||
f.write('\\section*{%s}\n\n' % (title,))
|
||||
for x in xs:
|
||||
|
|
|
@ -12,7 +12,7 @@ from zerver.lib.user_agent import parse_user_agent
|
|||
user_agents_parsed = defaultdict(int)
|
||||
user_agents_path = os.path.join(os.path.dirname(__file__), "user_agents_unique")
|
||||
parse_errors = 0
|
||||
for line in file(user_agents_path).readlines():
|
||||
for line in open(user_agents_path).readlines():
|
||||
line = line.strip()
|
||||
match = re.match('^(?P<count>[0-9]+) "(?P<user_agent>.*)"$', line)
|
||||
if match is None:
|
||||
|
|
|
@ -28,6 +28,7 @@ libfuturize.fixes.fix_next_call
|
|||
libfuturize.fixes.fix_print_with_import
|
||||
libfuturize.fixes.fix_raise
|
||||
libmodernize.fixes.fix_basestring
|
||||
libmodernize.fixes.fix_file
|
||||
libmodernize.fixes.fix_filter
|
||||
libmodernize.fixes.fix_imports_six
|
||||
libmodernize.fixes.fix_input_six
|
||||
|
|
|
@ -54,7 +54,7 @@ def get_or_create_key_prefix():
|
|||
# The file already exists
|
||||
tries = 1
|
||||
while tries < 10:
|
||||
with file(filename, 'r') as f:
|
||||
with open(filename, 'r') as f:
|
||||
prefix = f.readline()[:-1]
|
||||
if len(prefix) == 33:
|
||||
break
|
||||
|
|
|
@ -370,7 +370,7 @@ def gc_event_queues():
|
|||
def dump_event_queues():
|
||||
start = time.time()
|
||||
|
||||
with file(settings.JSON_PERSISTENT_QUEUE_FILENAME, "w") as stored_queues:
|
||||
with open(settings.JSON_PERSISTENT_QUEUE_FILENAME, "w") as stored_queues:
|
||||
ujson.dump([(qid, client.to_dict()) for (qid, client) in clients.iteritems()],
|
||||
stored_queues)
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ def restore_saved_messages():
|
|||
|
||||
event_glob = os.path.join(settings.EVENT_LOG_DIR, 'events.*')
|
||||
for filename in sorted(glob.glob(event_glob)):
|
||||
with file(filename, "r") as message_log:
|
||||
with open(filename, "r") as message_log:
|
||||
for line in message_log.readlines():
|
||||
process_line(line)
|
||||
|
||||
|
@ -699,7 +699,7 @@ def restore_saved_messages():
|
|||
def send_messages(data):
|
||||
(tot_messages, personals_pairs, options, output) = data
|
||||
random.seed(os.getpid())
|
||||
texts = file("zilencer/management/commands/test_messages.txt", "r").readlines()
|
||||
texts = open("zilencer/management/commands/test_messages.txt", "r").readlines()
|
||||
offset = random.randint(0, len(texts))
|
||||
|
||||
recipient_streams = [klass.id for klass in
|
||||
|
|
|
@ -14,7 +14,7 @@ class Command(BaseCommand):
|
|||
if not os.path.exists(config_file):
|
||||
raise RuntimeError("No ~/.zuliprc found")
|
||||
config = SafeConfigParser()
|
||||
with file(config_file, 'r') as f:
|
||||
with open(config_file, 'r') as f:
|
||||
config.readfp(f, config_file)
|
||||
api_key = config.get("api", "key")
|
||||
email = config.get("api", "email")
|
||||
|
|
Loading…
Reference in New Issue