py: Various flake8 cleanups

None of these are particularly significant, but they do get the CI
output clean.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2020-11-17 15:32:10 +00:00
parent e187d836ad
commit d270b6c3db
20 changed files with 129 additions and 108 deletions

View File

@ -53,7 +53,7 @@ def main():
for line in log_lines: for line in log_lines:
for keyword in BANNED_KEYWORDS: for keyword in BANNED_KEYWORDS:
if re.search("(^|\W+){}(\W+|$)".format(keyword), line): if re.search(r"(^|\W+){}(\W+|$)".format(keyword), line):
banned_words_seen.add(keyword) banned_words_seen.add(keyword)
seen_in_log = True seen_in_log = True
@ -72,7 +72,7 @@ def main():
continue continue
for keyword in BANNED_KEYWORDS: for keyword in BANNED_KEYWORDS:
if re.search("(^|\W+){}(\W+|$)".format(keyword), line): if re.search(r"(^|\W+){}(\W+|$)".format(keyword), line):
banned_words_seen.add(keyword) banned_words_seen.add(keyword)
seen_in_diff = True seen_in_diff = True

View File

@ -11,7 +11,6 @@
import argparse import argparse
import datetime import datetime
import json import json
import os
import sys import sys
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET

View File

@ -18,6 +18,7 @@
# #
# Author: Xavier Claessens <xavier.claessens@collabora.com> # Author: Xavier Claessens <xavier.claessens@collabora.com>
import os
import sys import sys
if len(sys.argv) < 3: if len(sys.argv) < 3:

View File

@ -21,8 +21,6 @@
# #
# Author: David Zeuthen <davidz@redhat.com> # Author: David Zeuthen <davidz@redhat.com>
import sys
from . import config from . import config
from . import utils from . import utils
from . import dbustypes from . import dbustypes
@ -37,6 +35,10 @@ LICENSE_STR = """/*
*/\n""" */\n"""
# Disable line length warnings as wrapping the C code templates would be hard
# flake8: noqa: E501
def generate_namespace(namespace): def generate_namespace(namespace):
ns = namespace ns = namespace
if len(namespace) > 0: if len(namespace) > 0:
@ -163,7 +165,7 @@ class HeaderCodeGenerator:
key = (m.since, "_method_%s" % m.name_lower) key = (m.since, "_method_%s" % m.name_lower)
value = " gboolean (*handle_%s) (\n" % (m.name_lower) value = " gboolean (*handle_%s) (\n" % (m.name_lower)
value += " %s *object,\n" % (i.camel_name) value += " %s *object,\n" % (i.camel_name)
value += " GDBusMethodInvocation *invocation" % () value += " GDBusMethodInvocation *invocation"
if m.unix_fd: if m.unix_fd:
value += ",\n GUnixFDList *fd_list" value += ",\n GUnixFDList *fd_list"
for a in m.in_args: for a in m.in_args:
@ -369,7 +371,7 @@ class HeaderCodeGenerator:
"%s%s_get_%s (%s *object);\n" "%s%s_get_%s (%s *object);\n"
% (p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name) % (p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name)
) )
if p.arg.free_func != None: if p.arg.free_func is not None:
if self.symbol_decorator is not None: if self.symbol_decorator is not None:
self.outfile.write("%s\n" % self.symbol_decorator) self.outfile.write("%s\n" % self.symbol_decorator)
if p.deprecated: if p.deprecated:
@ -2342,7 +2344,7 @@ class CodeGenerator:
False, False,
) )
) )
if p.arg.free_func != None: if p.arg.free_func is not None:
self.outfile.write( self.outfile.write(
" * The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.\n" " * The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.\n"
" *\n" " *\n"
@ -2363,7 +2365,7 @@ class CodeGenerator:
) )
self.outfile.write("}\n") self.outfile.write("}\n")
self.outfile.write("\n") self.outfile.write("\n")
if p.arg.free_func != None: if p.arg.free_func is not None:
self.outfile.write( self.outfile.write(
self.docbook_gen.expand( self.docbook_gen.expand(
@ -3082,7 +3084,7 @@ class CodeGenerator:
# property vfuncs # property vfuncs
for p in i.properties: for p in i.properties:
nul_value = "0" nul_value = "0"
if p.arg.free_func != None: if p.arg.free_func is not None:
nul_value = "NULL" nul_value = "NULL"
self.outfile.write( self.outfile.write(
"static %s\n" "static %s\n"
@ -3544,7 +3546,7 @@ class CodeGenerator:
) )
self.outfile.write( self.outfile.write(
" info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n" " info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n"
" g_assert (info != NULL);\n" % () " g_assert (info != NULL);\n"
) )
self.outfile.write( self.outfile.write(
" num_params = g_variant_n_children (parameters);\n" " num_params = g_variant_n_children (parameters);\n"
@ -4006,7 +4008,7 @@ class CodeGenerator:
" g_value_copy (orig_value, &cp->orig_value);\n" " g_value_copy (orig_value, &cp->orig_value);\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" % () "\n"
) )
# Postpone setting up the refresh source until the ::notify signal is emitted as # Postpone setting up the refresh source until the ::notify signal is emitted as
@ -4506,7 +4508,7 @@ class CodeGenerator:
" G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n" " G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n"
% (self.ns_lower) % (self.ns_lower)
) )
self.outfile.write("}\n" "\n" % ()) self.outfile.write("}\n" "\n")
self.outfile.write( self.outfile.write(
"static void\n" "static void\n"
"%sobject_proxy_get_property (GObject *gobject,\n" "%sobject_proxy_get_property (GObject *gobject,\n"
@ -4536,7 +4538,7 @@ class CodeGenerator:
" break;\n" " break;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" % () "\n"
) )
self.outfile.write( self.outfile.write(
"static void\n" "static void\n"
@ -4685,7 +4687,7 @@ class CodeGenerator:
" break;\n" " break;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" % () "\n"
) )
self.outfile.write( self.outfile.write(
"static void\n" "static void\n"
@ -4716,7 +4718,7 @@ class CodeGenerator:
" break;\n" " break;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" % () "\n"
) )
self.outfile.write( self.outfile.write(
"static void\n" "static void\n"

View File

@ -19,14 +19,15 @@
# #
# Author: David Zeuthen <davidz@redhat.com> # Author: David Zeuthen <davidz@redhat.com>
import sys
import re import re
from os import path from os import path
from . import config
from . import utils from . import utils
from . import dbustypes
from . import parser
# Disable line length warnings as wrapping the Docbook templates would be hard
# flake8: noqa: E501
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
@ -167,31 +168,31 @@ class DocbookCodeGenerator:
self.out.write(" %s %s\n" % (access, p.signature)) self.out.write(" %s %s\n" % (access, p.signature))
def print_synopsis_methods(self, i): def print_synopsis_methods(self, i):
self.out.write(' <refsynopsisdiv role="synopsis">\n' % ()) self.out.write(' <refsynopsisdiv role="synopsis">\n')
self.out.write(' <title role="synopsis.title">Methods</title>\n' % ()) self.out.write(' <title role="synopsis.title">Methods</title>\n')
self.out.write(" <synopsis>\n" % ()) self.out.write(" <synopsis>\n")
for m in i.methods: for m in i.methods:
self.print_method_prototype(i, m, in_synopsis=True) self.print_method_prototype(i, m, in_synopsis=True)
self.out.write("</synopsis>\n" % ()) self.out.write("</synopsis>\n")
self.out.write(" </refsynopsisdiv>\n" % ()) self.out.write(" </refsynopsisdiv>\n")
def print_synopsis_signals(self, i): def print_synopsis_signals(self, i):
self.out.write(' <refsect1 role="signal_proto">\n' % ()) self.out.write(' <refsect1 role="signal_proto">\n')
self.out.write(' <title role="signal_proto.title">Signals</title>\n' % ()) self.out.write(' <title role="signal_proto.title">Signals</title>\n')
self.out.write(" <synopsis>\n" % ()) self.out.write(" <synopsis>\n")
for s in i.signals: for s in i.signals:
self.print_signal_prototype(i, s, in_synopsis=True) self.print_signal_prototype(i, s, in_synopsis=True)
self.out.write("</synopsis>\n" % ()) self.out.write("</synopsis>\n")
self.out.write(" </refsect1>\n" % ()) self.out.write(" </refsect1>\n")
def print_synopsis_properties(self, i): def print_synopsis_properties(self, i):
self.out.write(' <refsect1 role="properties">\n' % ()) self.out.write(' <refsect1 role="properties">\n')
self.out.write(' <title role="properties.title">Properties</title>\n' % ()) self.out.write(' <title role="properties.title">Properties</title>\n')
self.out.write(" <synopsis>\n" % ()) self.out.write(" <synopsis>\n")
for p in i.properties: for p in i.properties:
self.print_property_prototype(i, p, in_synopsis=True) self.print_property_prototype(i, p, in_synopsis=True)
self.out.write("</synopsis>\n" % ()) self.out.write("</synopsis>\n")
self.out.write(" </refsect1>\n" % ()) self.out.write(" </refsect1>\n")
def print_method(self, i, m): def print_method(self, i, m):
self.out.write( self.out.write(
@ -217,7 +218,7 @@ class DocbookCodeGenerator:
if m.in_args or m.out_args: if m.in_args or m.out_args:
self.out.write('<variablelist role="params">\n') self.out.write('<variablelist role="params">\n')
for a in m.in_args: for a in m.in_args:
self.out.write("<varlistentry>\n" % ()) self.out.write("<varlistentry>\n")
self.out.write( self.out.write(
" <term><literal>IN %s <parameter>%s</parameter></literal>:</term>\n" " <term><literal>IN %s <parameter>%s</parameter></literal>:</term>\n"
% (a.signature, a.name) % (a.signature, a.name)
@ -226,9 +227,9 @@ class DocbookCodeGenerator:
" <listitem>%s</listitem>\n" " <listitem>%s</listitem>\n"
% (self.expand_paras(a.doc_string, True)) % (self.expand_paras(a.doc_string, True))
) )
self.out.write("</varlistentry>\n" % ()) self.out.write("</varlistentry>\n")
for a in m.out_args: for a in m.out_args:
self.out.write("<varlistentry>\n" % ()) self.out.write("<varlistentry>\n")
self.out.write( self.out.write(
" <term><literal>OUT %s <parameter>%s</parameter></literal>:</term>\n" " <term><literal>OUT %s <parameter>%s</parameter></literal>:</term>\n"
% (a.signature, a.name) % (a.signature, a.name)
@ -237,7 +238,7 @@ class DocbookCodeGenerator:
" <listitem>%s</listitem>\n" " <listitem>%s</listitem>\n"
% (self.expand_paras(a.doc_string, True)) % (self.expand_paras(a.doc_string, True))
) )
self.out.write("</varlistentry>\n" % ()) self.out.write("</varlistentry>\n")
self.out.write("</variablelist>\n") self.out.write("</variablelist>\n")
if len(m.since) > 0: if len(m.since) > 0:
self.out.write('<para role="since">Since %s</para>\n' % (m.since)) self.out.write('<para role="since">Since %s</para>\n' % (m.since))
@ -272,7 +273,7 @@ class DocbookCodeGenerator:
if s.args: if s.args:
self.out.write('<variablelist role="params">\n') self.out.write('<variablelist role="params">\n')
for a in s.args: for a in s.args:
self.out.write("<varlistentry>\n" % ()) self.out.write("<varlistentry>\n")
self.out.write( self.out.write(
" <term><literal>%s <parameter>%s</parameter></literal>:</term>\n" " <term><literal>%s <parameter>%s</parameter></literal>:</term>\n"
% (a.signature, a.name) % (a.signature, a.name)
@ -281,7 +282,7 @@ class DocbookCodeGenerator:
" <listitem>%s</listitem>\n" " <listitem>%s</listitem>\n"
% (self.expand_paras(a.doc_string, True)) % (self.expand_paras(a.doc_string, True))
) )
self.out.write("</varlistentry>\n" % ()) self.out.write("</varlistentry>\n")
self.out.write("</variablelist>\n") self.out.write("</variablelist>\n")
if len(s.since) > 0: if len(s.since) > 0:
self.out.write('<para role="since">Since %s</para>\n' % (s.since)) self.out.write('<para role="since">Since %s</para>\n' % (s.since))
@ -394,19 +395,17 @@ class DocbookCodeGenerator:
def generate(self, docbook, outdir): def generate(self, docbook, outdir):
for i in self.ifaces: for i in self.ifaces:
self.out = open(path.join(outdir, "%s-%s.xml" % (docbook, i.name)), "w") self.out = open(path.join(outdir, "%s-%s.xml" % (docbook, i.name)), "w")
self.out.write("" % ()) self.out.write("")
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n' % ()) self.out.write('<?xml version="1.0" encoding="utf-8"?>\n')
self.out.write( self.out.write(
'<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n' '<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'
% ()
) )
self.out.write( self.out.write(
' "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\n' ' "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\n'
% ()
) )
self.out.write("]>\n" % ()) self.out.write("]>\n")
self.out.write('<refentry id="gdbus-%s">\n' % (i.name)) self.out.write('<refentry id="gdbus-%s">\n' % (i.name))
self.out.write(" <refmeta>" % ()) self.out.write(" <refmeta>")
self.out.write( self.out.write(
' <refentrytitle role="top_of_page" id="gdbus-interface-%s.top_of_page">%s</refentrytitle>\n' ' <refentrytitle role="top_of_page" id="gdbus-interface-%s.top_of_page">%s</refentrytitle>\n'
% (utils.dots_to_hyphens(i.name), i.name) % (utils.dots_to_hyphens(i.name), i.name)
@ -415,12 +414,12 @@ class DocbookCodeGenerator:
' <indexterm zone="gdbus-interface-%s.top_of_page"><primary sortas="%s">%s</primary></indexterm>\n' ' <indexterm zone="gdbus-interface-%s.top_of_page"><primary sortas="%s">%s</primary></indexterm>\n'
% (utils.dots_to_hyphens(i.name), i.name_without_prefix, i.name) % (utils.dots_to_hyphens(i.name), i.name_without_prefix, i.name)
) )
self.out.write(" </refmeta>" % ()) self.out.write(" </refmeta>")
self.out.write(" <refnamediv>" % ()) self.out.write(" <refnamediv>")
self.out.write(" <refname>%s</refname>" % (i.name)) self.out.write(" <refname>%s</refname>" % (i.name))
self.out.write(" <refpurpose>%s</refpurpose>" % (i.doc_string_brief)) self.out.write(" <refpurpose>%s</refpurpose>" % (i.doc_string_brief))
self.out.write(" </refnamediv>" % ()) self.out.write(" </refnamediv>")
if len(i.methods) > 0: if len(i.methods) > 0:
self.print_synopsis_methods(i) self.print_synopsis_methods(i)
@ -433,7 +432,7 @@ class DocbookCodeGenerator:
'<refsect1 role="desc" id="gdbus-interface-%s">\n' '<refsect1 role="desc" id="gdbus-interface-%s">\n'
% (utils.dots_to_hyphens(i.name)) % (utils.dots_to_hyphens(i.name))
) )
self.out.write(' <title role="desc.title">Description</title>\n' % ()) self.out.write(' <title role="desc.title">Description</title>\n')
self.out.write(" %s\n" % (self.expand_paras(i.doc_string, True))) self.out.write(" %s\n" % (self.expand_paras(i.doc_string, True)))
if len(i.since) > 0: if len(i.since) > 0:
self.out.write(' <para role="since">Since %s</para>\n' % (i.since)) self.out.write(' <para role="since">Since %s</para>\n' % (i.since))
@ -442,40 +441,36 @@ class DocbookCodeGenerator:
"<warning><para>The %s interface is deprecated.</para></warning>" "<warning><para>The %s interface is deprecated.</para></warning>"
% (i.name) % (i.name)
) )
self.out.write("</refsect1>\n" % ()) self.out.write("</refsect1>\n")
if len(i.methods) > 0: if len(i.methods) > 0:
self.out.write( self.out.write(
'<refsect1 role="details" id="gdbus-methods-%s">\n' % (i.name) '<refsect1 role="details" id="gdbus-methods-%s">\n' % (i.name)
) )
self.out.write( self.out.write(' <title role="details.title">Method Details</title>\n')
' <title role="details.title">Method Details</title>\n' % ()
)
for m in i.methods: for m in i.methods:
self.print_method(i, m) self.print_method(i, m)
self.out.write("</refsect1>\n" % ()) self.out.write("</refsect1>\n")
if len(i.signals) > 0: if len(i.signals) > 0:
self.out.write( self.out.write(
'<refsect1 role="details" id="gdbus-signals-%s">\n' % (i.name) '<refsect1 role="details" id="gdbus-signals-%s">\n' % (i.name)
) )
self.out.write( self.out.write(' <title role="details.title">Signal Details</title>\n')
' <title role="details.title">Signal Details</title>\n' % ()
)
for s in i.signals: for s in i.signals:
self.print_signal(i, s) self.print_signal(i, s)
self.out.write("</refsect1>\n" % ()) self.out.write("</refsect1>\n")
if len(i.properties) > 0: if len(i.properties) > 0:
self.out.write( self.out.write(
'<refsect1 role="details" id="gdbus-properties-%s">\n' % (i.name) '<refsect1 role="details" id="gdbus-properties-%s">\n' % (i.name)
) )
self.out.write( self.out.write(
' <title role="details.title">Property Details</title>\n' % () ' <title role="details.title">Property Details</title>\n'
) )
for s in i.properties: for s in i.properties:
self.print_property(i, s) self.print_property(i, s)
self.out.write("</refsect1>\n" % ()) self.out.write("</refsect1>\n")
self.out.write("</refentry>\n") self.out.write("</refentry>\n")
self.out.write("\n") self.out.write("\n")

View File

@ -226,24 +226,29 @@ def codegen_main():
arg_parser.add_argument( arg_parser.add_argument(
"--glib-min-required", "--glib-min-required",
metavar="VERSION", metavar="VERSION",
help="Minimum version of GLib to be supported by the outputted code (default: 2.30)", help="Minimum version of GLib to be supported by the outputted code "
"(default: 2.30)",
) )
arg_parser.add_argument( arg_parser.add_argument(
"--glib-max-allowed", "--glib-max-allowed",
metavar="VERSION", metavar="VERSION",
help="Maximum version of GLib to be used by the outputted code (default: current GLib version)", help="Maximum version of GLib to be used by the outputted code "
"(default: current GLib version)",
) )
arg_parser.add_argument( arg_parser.add_argument(
"--symbol-decorator", "--symbol-decorator",
help="Macro used to decorate a symbol in the outputted header, possibly to export symbols", help="Macro used to decorate a symbol in the outputted header, "
"possibly to export symbols",
) )
arg_parser.add_argument( arg_parser.add_argument(
"--symbol-decorator-header", "--symbol-decorator-header",
help="Additional header required for decorator specified by --symbol-decorator", help="Additional header required for decorator specified by "
"--symbol-decorator",
) )
arg_parser.add_argument( arg_parser.add_argument(
"--symbol-decorator-define", "--symbol-decorator-define",
help="Additional define required for decorator specified by --symbol-decorator", help="Additional define required for decorator specified by "
"--symbol-decorator",
) )
group = arg_parser.add_mutually_exclusive_group() group = arg_parser.add_mutually_exclusive_group()
@ -370,11 +375,13 @@ def codegen_main():
else: else:
glib_max_allowed = (config.MAJOR_VERSION, config.MINOR_VERSION) glib_max_allowed = (config.MAJOR_VERSION, config.MINOR_VERSION)
# Only allow --symbol-decorator-define and --symbol-decorator-header if --symbol-decorator is used # Only allow --symbol-decorator-define and --symbol-decorator-header if
# --symbol-decorator is used
if args.symbol_decorator is None: if args.symbol_decorator is None:
if args.symbol_decorator_header or args.symbol_decorator_define: if args.symbol_decorator_header or args.symbol_decorator_define:
print_error( print_error(
"--symbol-decorator-define and --symbol-decorator-header must be used with --symbol-decorator" "--symbol-decorator-define and --symbol-decorator-header must "
"be used with --symbol-decorator"
) )
# Round --glib-max-allowed up to the next stable release. # Round --glib-max-allowed up to the next stable release.
@ -411,7 +418,7 @@ def codegen_main():
docbook = args.generate_docbook docbook = args.generate_docbook
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces) docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces)
if docbook: if docbook:
ret = docbook_gen.generate(docbook, args.output_directory) docbook_gen.generate(docbook, args.output_directory)
if args.header: if args.header:
with open(h_file, "w") as outfile: with open(h_file, "w") as outfile:

View File

@ -414,7 +414,8 @@ class Property:
name = overridden_name name = overridden_name
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_") self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
self.name_hyphen = self.name_lower.replace("_", "-") self.name_hyphen = self.name_lower.replace("_", "-")
# don't clash with the GType getter, e.g.: GType foo_bar_get_type (void); G_GNUC_CONST # don't clash with the GType getter, e.g.:
# GType foo_bar_get_type (void); G_GNUC_CONST
if self.name_lower == "type": if self.name_lower == "type":
self.name_lower = "type_" self.name_lower = "type_"
@ -431,7 +432,8 @@ class Property:
for a in self.annotations: for a in self.annotations:
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self) a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
# FIXME: for now we only support 'false' and 'const' on the signal itself, see #674913 and # FIXME: for now we only support 'false' and 'const' on the signal itself,
# see #674913 and
# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format # http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
# for details # for details
if utils.lookup_annotation( if utils.lookup_annotation(

View File

@ -19,7 +19,6 @@
# #
# Author: David Zeuthen <davidz@redhat.com> # Author: David Zeuthen <davidz@redhat.com>
import sys
import xml.parsers.expat import xml.parsers.expat
from . import dbustypes from . import dbustypes
@ -222,7 +221,7 @@ class DBusXMLParser:
if self.doc_comment_last_symbol == old_cur_object.name: if self.doc_comment_last_symbol == old_cur_object.name:
if "name" in attrs and attrs["name"] in self.doc_comment_params: if "name" in attrs and attrs["name"] in self.doc_comment_params:
doc_string = self.doc_comment_params[attrs["name"]] doc_string = self.doc_comment_params[attrs["name"]]
if doc_string != None: if doc_string is not None:
self._cur_object.doc_string = doc_string self._cur_object.doc_string = doc_string
if "since" in self.doc_comment_params: if "since" in self.doc_comment_params:
self._cur_object.since = self.doc_comment_params[ self._cur_object.since = self.doc_comment_params[
@ -250,7 +249,7 @@ class DBusXMLParser:
if self.doc_comment_last_symbol == old_cur_object.name: if self.doc_comment_last_symbol == old_cur_object.name:
if "name" in attrs and attrs["name"] in self.doc_comment_params: if "name" in attrs and attrs["name"] in self.doc_comment_params:
doc_string = self.doc_comment_params[attrs["name"]] doc_string = self.doc_comment_params[attrs["name"]]
if doc_string != None: if doc_string is not None:
self._cur_object.doc_string = doc_string self._cur_object.doc_string = doc_string
if "since" in self.doc_comment_params: if "since" in self.doc_comment_params:
self._cur_object.since = self.doc_comment_params[ self._cur_object.since = self.doc_comment_params[

View File

@ -23,6 +23,7 @@ import distutils.version
import os import os
import sys import sys
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class Color: class Color:
"""ANSI Terminal colors""" """ANSI Terminal colors"""

View File

@ -26,12 +26,15 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import textwrap
import unittest import unittest
import taptestrunner import taptestrunner
# Disable line length warnings as wrapping the C code templates would be hard
# flake8: noqa: E501
Result = collections.namedtuple("Result", ("info", "out", "err", "subs")) Result = collections.namedtuple("Result", ("info", "out", "err", "subs"))

View File

@ -8,7 +8,6 @@
# #
# See issue #1580 # See issue #1580
import io
import string import string
import sys import sys

View File

@ -29,7 +29,7 @@ for filename in in_files:
match = re.search(b"\bg_[a-zA-Z0-9_]*_get_type\b", line) match = re.search(b"\bg_[a-zA-Z0-9_]*_get_type\b", line)
if match: if match:
func = match.group(0) func = match.group(0)
if not func in funcs: if func not in funcs:
funcs.append(func) funcs.append(func)
if debug: if debug:
print("Found ", func) print("Found ", func)

View File

@ -23,7 +23,7 @@ import sys
import tempfile import tempfile
import subprocess import subprocess
if not "GLIB_TEST_COMPILATION" in os.environ: if "GLIB_TEST_COMPILATION" not in os.environ:
print( print(
"""Test disabled because GLIB_TEST_COMPILATION is not set in the env. """Test disabled because GLIB_TEST_COMPILATION is not set in the env.
If you wish to run this test, set GLIB_TEST_COMPILATION=1 in the env, If you wish to run this test, set GLIB_TEST_COMPILATION=1 in the env,

View File

@ -30,6 +30,7 @@ import sys
import base64 import base64
from io import StringIO from io import StringIO
# Log modes # Log modes
class LogMode(object): class LogMode(object):
LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4) LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4)

View File

@ -4,6 +4,7 @@ import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
long = int long = int
# This is not quite right, as local vars may override symname # This is not quite right, as local vars may override symname
def read_global_var(symname): def read_global_var(symname):
return gdb.selected_frame().read_var(symname) return gdb.selected_frame().read_var(symname)
@ -18,11 +19,11 @@ def g_quark_to_string(quark):
try: try:
val = read_global_var("quarks") val = read_global_var("quarks")
max_q = long(read_global_var("quark_seq_id")) max_q = long(read_global_var("quark_seq_id"))
except: except Exception:
try: try:
val = read_global_var("g_quarks") val = read_global_var("g_quarks")
max_q = long(read_global_var("g_quark_seq_id")) max_q = long(read_global_var("g_quark_seq_id"))
except: except Exception:
return None return None
if quark < max_q: if quark < max_q:
return val[quark].string() return val[quark].string()
@ -130,7 +131,7 @@ class GHashPrinter:
def next(self): def next(self):
if self.ht == 0: if self.ht == 0:
raise StopIteration raise StopIteration
if self.value != None: if self.value is not None:
v = self.value v = self.value
self.value = None self.value = None
return v return v
@ -160,11 +161,11 @@ class GHashPrinter:
self.keys_are_strings = False self.keys_are_strings = False
try: try:
string_hash = read_global_var("g_str_hash") string_hash = read_global_var("g_str_hash")
except: except Exception:
string_hash = None string_hash = None
if ( if (
self.val != 0 self.val != 0
and string_hash != None and string_hash is not None
and self.val["hash_func"] == string_hash and self.val["hash_func"] == string_hash
): ):
self.keys_are_strings = True self.keys_are_strings = True
@ -267,16 +268,16 @@ class ForeachCommand(gdb.Command):
gdb.execute(command) gdb.execute(command)
def slist_iterator(self, arg, container, command): def slist_iterator(self, arg, container, command):
l = container.cast(gdb.lookup_type("GSList").pointer()) list_element = container.cast(gdb.lookup_type("GSList").pointer())
while long(l) != 0: while long(list_element) != 0:
self.do_iter(arg, l["data"], command) self.do_iter(arg, list_element["data"], command)
l = l["next"] list_element = list_element["next"]
def list_iterator(self, arg, container, command): def list_iterator(self, arg, container, command):
l = container.cast(gdb.lookup_type("GList").pointer()) list_element = container.cast(gdb.lookup_type("GList").pointer())
while long(l) != 0: while long(list_element) != 0:
self.do_iter(arg, l["data"], command) self.do_iter(arg, list_element["data"], command)
l = l["next"] list_element = list_element["next"]
def pick_iterator(self, container): def pick_iterator(self, container):
t = container.type.unqualified() t = container.type.unqualified()

View File

@ -4,10 +4,13 @@
# #
# ./update-gtranslit.py /path/to/glibc/localedata/locales > gtranslit-data.h # ./update-gtranslit.py /path/to/glibc/localedata/locales > gtranslit-data.h
import sys, os import os
import sys
localedir = sys.argv[1] localedir = sys.argv[1]
# returns true if the name looks like a POSIX locale name # returns true if the name looks like a POSIX locale name
def looks_like_locale(name): def looks_like_locale(name):
name, _, variant = name.partition("@") name, _, variant = name.partition("@")
@ -34,7 +37,7 @@ def unescape(string):
chunks.append(string[i:]) chunks.append(string[i:])
break break
assert string[start_escape : start_escape + 2] == "<U" assert string[start_escape : (start_escape + 2)] == "<U"
start_escape += 2 start_escape += 2
end_escape = string.find(">", start_escape) end_escape = string.find(">", start_escape)
@ -65,7 +68,8 @@ class Mapping:
# Scans a string like # Scans a string like
# #
# <U00C4> "<U0041><U0308>";"<U0041><U0045>" % LATIN CAPITAL LETTER A WITH DIAERESIS. # <U00C4> "<U0041><U0308>";"<U0041><U0045>" % \
# LATIN CAPITAL LETTER A WITH DIAERESIS.
# #
# and adds the first all-ascii choice (or IGNORE) to the mapping # and adds the first all-ascii choice (or IGNORE) to the mapping
# dictionary, with the origin string as the key. In the case of # dictionary, with the origin string as the key. In the case of
@ -227,7 +231,7 @@ chains = {}
def get_chain(name): def get_chain(name):
if not name in chains: if name not in chains:
chains[name] = Chain(name) chains[name] = Chain(name)
return chains[name] return chains[name]
@ -362,8 +366,6 @@ class Serialiser:
mappings_table.append((src_range, ascii_range)) mappings_table.append((src_range, ascii_range))
mapping_end = len(mappings_table)
for chain in self.chains: for chain in self.chains:
chain_starts.append(len(chains_table)) chain_starts.append(len(chains_table))

View File

@ -1,4 +1,3 @@
import os.path
import gdb import gdb
import glib_gdb import glib_gdb
import sys import sys
@ -19,6 +18,7 @@ try:
except ImportError: except ImportError:
HAVE_GDB_FRAMEDECORATOR = False HAVE_GDB_FRAMEDECORATOR = False
# This is not quite right, as local vars may override symname # This is not quite right, as local vars may override symname
def read_global_var(symname): def read_global_var(symname):
return gdb.selected_frame().read_var(symname) return gdb.selected_frame().read_var(symname)
@ -44,7 +44,7 @@ def g_type_to_typenode(gtype):
def g_type_to_name(gtype): def g_type_to_name(gtype):
typenode = g_type_to_typenode(gtype) typenode = g_type_to_typenode(gtype)
if typenode != None: if typenode is not None:
return glib_gdb.g_quark_to_string(typenode["qname"]) return glib_gdb.g_quark_to_string(typenode["qname"])
return None return None
@ -116,7 +116,7 @@ class GTypeHandlePrettyPrinter:
def to_string(self): def to_string(self):
typenode = g_type_to_typenode(self.val) typenode = g_type_to_typenode(self.val)
if typenode != None: if typenode is not None:
name = glib_gdb.g_quark_to_string(typenode["qname"]) name = glib_gdb.g_quark_to_string(typenode["qname"])
s = ("0x%x [%s%s") % (long(self.val), self.hint, name) s = ("0x%x [%s%s") % (long(self.val), self.hint, name)
for i in range(1, int(typenode["n_supers"])): for i in range(1, int(typenode["n_supers"])):
@ -178,7 +178,7 @@ class SignalFrame(FrameDecorator):
v = frame_var(frame, name) v = frame_var(frame, name)
if v is None or v.is_optimized_out: if v is None or v.is_optimized_out:
return None return None
if array != None: if array is not None:
array.append(v) array.append(v)
return v return v
except ValueError: except ValueError:
@ -191,8 +191,8 @@ class SignalFrame(FrameDecorator):
return None return None
v = v.cast(gdb.lookup_type("GObject").pointer()) v = v.cast(gdb.lookup_type("GObject").pointer())
# Ensure this is a somewhat correct object pointer # Ensure this is a somewhat correct object pointer
if v != None and g_type_name_from_instance(v): if v is not None and g_type_name_from_instance(v):
if array != None: if array is not None:
array.append(v) array.append(v)
return v return v
return None return None
@ -200,7 +200,7 @@ class SignalFrame(FrameDecorator):
return None return None
def append(self, array, obj): def append(self, array, obj):
if obj != None: if obj is not None:
array.append(obj) array.append(obj)
def or_join_array(self, array): def or_join_array(self, array):

View File

@ -32,6 +32,10 @@ import unittest
import taptestrunner import taptestrunner
# Disable line length warnings as wrapping the C code templates would be hard
# flake8: noqa: E501
Result = collections.namedtuple("Result", ("info", "out", "err", "subs")) Result = collections.namedtuple("Result", ("info", "out", "err", "subs"))

View File

@ -30,6 +30,7 @@ import sys
import base64 import base64
from io import StringIO from io import StringIO
# Log modes # Log modes
class LogMode(object): class LogMode(object):
LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4) LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4)

View File

@ -27,6 +27,10 @@ import sys
import argparse import argparse
# Disable line length warnings as wrapping the test templates would be hard
# flake8: noqa: E501
def main(argv): def main(argv):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Generate test cases for case mapping from Unicode data" description="Generate test cases for case mapping from Unicode data"
@ -183,9 +187,9 @@ tr_TR.UTF-8\tI\u0307\ti\tI\u0307\tI\u0307\t# I => LATIN SMALL LETTER DOTLESS I
\t\u03b1\u0345\u0314\t\u03b1\u0345\u0314\t\u0391\u0345\u0314\t\u0391\u0314\u0399\t \t\u03b1\u0345\u0314\t\u03b1\u0345\u0314\t\u0391\u0345\u0314\t\u0391\u0314\u0399\t
\t\u03b1\u0314\u0345\t\u03b1\u0314\u0345\t\u0391\u0314\u0345\t\u0391\u0314\u0399\t \t\u03b1\u0314\u0345\t\u03b1\u0314\u0345\t\u0391\u0314\u0345\t\u0391\u0314\u0399\t
# Handling of final and nonfinal sigma # Handling of final and nonfinal sigma
\tΜΆΙΟΣ μάιος Μάιος ΜΆΙΟΣ \tΜΆΙΟΣ μάιος Μάιος ΜΆΙΟΣ \t
\tΜΆΙΟΣ μάιος Μάιος ΜΆΙΟΣ \tΜΆΙΟΣ μάιος Μάιος ΜΆΙΟΣ\t
\ΙΓΜΑ σιγμα Σιγμα ΣΙΓΜΑ \ΙΓΜΑ σιγμα Σιγμα ΣΙΓΜΑ\t
# Lithuanian rule of i followed by letter with dot. Not at all sure # Lithuanian rule of i followed by letter with dot. Not at all sure
# about the titlecase part here # about the titlecase part here
lt_LT\ti\u0117\ti\u0117\tIe\tIE\t lt_LT\ti\u0117\ti\u0117\tIe\tIE\t