81 Commits

Author SHA1 Message Date
Enji Cooper
46c9ead0eb Make all classes Entry, Struct, etc) new-style classes
This allows the object methods to be properly inherited and called via
`super(..)`, addressing breakage with python 2.x, introduced in
cfcc093606e747a5d250787012bac0b149c60d6d.

Fixes #1042.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-06-25 08:11:00 -07:00
Azat Khuzhin
b57b6e4600 event_rpcgen.py: fix arguments-differ 2020-03-28 16:01:46 +03:00
Azat Khuzhin
7cdf75ca26 event_rpcgen.py: fix attribute-defined-outside-init 2020-03-28 15:58:57 +03:00
Azat Khuzhin
121fe01372 event_rpcgen: suppress some warnings to make pylint clean 2020-03-28 15:58:36 +03:00
Enji Cooper
47a2bcf6e8 Don't accumulate arguments in Entry.GetTranslation
Initialize `extradict` safely to avoid accumulating arguments in dict
objects passed in across calls.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 17:30:23 -07:00
Enji Cooper
6a3ca34737 Fix improper string concatenations in lists
This change adds commas between elements or explicitly concatenates the
strings, so the values are no longer concatenated by accident.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 17:30:02 -07:00
Enji Cooper
496fc02b2f Fix warnings regarding unused variables
Prefix all unused variables with `_` to mute unused variable warnings
with flake8/pylint.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 17:27:35 -07:00
Enji Cooper
80171db515 Don't override the type built-in
Name the second parameter to `Entry(..)` `ent_type` to avoid overriding
the built-in.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:45:21 -07:00
Enji Cooper
cfcc093606 Call super to call methods from the parent class
Not only does it make it clearer to the reader what the intent is behind
the code, it fixes MRO evaluation of classes if the parent-child
relationship is nonlinear.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:27:56 -07:00
Enji Cooper
83175940d4 Address no-self-use issues reported by pylint
Sprinkle around `@staticmethod` where need be and raise
`NotImplementedError` from `Entry.GetInitializer` instead of doing
similar with `assert`. `NotImplementedError` will provide a hint to
static analyzers that there are abstract methods which need to be
implemented, if they aren't, in subclasses.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:20:24 -07:00
Enji Cooper
6da0cc6108 Run the code through the black formatter
This resolves a number of flake8 issues as well as pylint issues. Not
all of the changes mesh between flake8/pylint though, so there are some
false positives, but it's better than before.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:04:37 -07:00
Enji Cooper
10a0403685 Reformat strings to template
This change converts the existing code to use triple-quotes extensively,
in the end-goal of making the code to reformat with black more readable
before and after the change (black messes around with the formatting in
a less than desirable way).

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 15:58:02 -07:00
Enji Cooper
4cde51b678 Add argparse support
This change converts raw parsing with `sys.argv` to its equivalent logic
with `argparse`.

It doesn't fully convert over all of the TODO items listed in the
comments, but it does provide some top-level structure which can be used
to drive down further improvements and structure.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
23874cfcd5 Precompile regular expressions
This change boost performance at scale by pre-compiling regular
expressions in the global space, then reusing them many times within
functions.

This (while not the desired intent of the author) will boost
performance when parsing input.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
1b545a46cd Use bools instead of ints values where possible
This is being done to clarify logic and isn't being done for performance
reasons whatsoever, as bools are derived from ints.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
9157b0d2fa Rename all global variables to match the PEP8 spec
Global variables should be in all caps, as opposed to lowercase.

While here, use named groups for `STRUCT_REF_RE` instead of numbered
groups to make the results and their indented tokens to parse more
intuitive to the end reader.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
dc57672900 Handle file pointers with context suite patterns
This removes the need for manually calling the file pointer's `.close`
methods directly.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
7f115c17c0 Iterate over tokens with a for instead of while
This simplifies the logic and avoids unnecessary copying/slicing of
array elements in `tokens`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
5408b9636f Fix indentation for RpcGenError
Indentation for the exception was double what it should have been. This
change normalizes the indentation to a consistent standard with the rest
of the file.

Fix minor flake8 issues while here corresponding to the minimum number
of needed blank lines around the class and its methods.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
30229dcf95 Don't override file built-in
Use `filep` instead of `file` to clarify the fact that `file` is a file
pointer object.

This mutes warnings on python 2.7 with `pylint`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
2c38d6b115 Resolve variable name issues per PEP8
Move all logic under `if __name__ == "__main__"` to a `main(..)`
function.

The purpose of this is to not only address flake8/pylint reported issues
with variable names, but also to enable testing of the function in
isolation to ensure the logic acts as desired.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
f30cc2b04b Sort imports per PEP8
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Azat Khuzhin
e85818d248
Cleanup __func__ detection
First of all __func__ is not a macro, it is char[] array, so the code
that we had before in cmake, was incorrect, i.e.:
  #if defined (__func__)
  #define EVENT____func__ __func__
  #elif defined(__FUNCTION__)
  #define EVENT____func__  __FUNCTION__
  #else
  #define EVENT____func__ __FILE__
  #endif

So just detect do we have __func__/__FUNCTION__ in configure/cmake
before build and define EVENT__HAVE___func__/EVENT__HAVE___FUNCTION__
to use the later to choose which should be used as a __func__ (if it is
not presented).

Closes: #644
2018-08-02 02:50:48 +03:00
Kiyoshi Aman
8b0aa7b36a Port event_rpcgen.py and test/check-dumpevents.py to Python 3.
These scripts remain compatible with Python 2.
2017-09-25 11:35:23 +03:00
Azat Khuzhin
253e7fa90c util-internal: fix __func__ redefinition (netbsd)
==> netbsd: In file included from ../listener.c:57:0:
==> netbsd: ../util-internal.h:58:0: warning: "__func__" redefined [enabled by default]
==> netbsd:  #define __func__ EVENT____func__
==> netbsd:  ^
==> netbsd: In file included from /usr/include/amd64/types.h:39:0,
==> netbsd:                  from /usr/include/sys/types.h:45,
==> netbsd:                  from ../listener.c:30:
==> netbsd: /usr/include/sys/cdefs.h:394:0: note: this is the location of the previous definition
==> netbsd:  #define __func__ __PRETTY_FUNCTION__
2016-12-06 12:54:33 +03:00
Nick Mathewson
32ed11024a Merge remote-tracking branch 'origin/patches-2.0' 2012-10-26 19:37:00 -04:00
Ross Lagerwall
0eb01099da Use python2 rather than python
python may refer to either python2 or python3 so rather by explicit by
using python2.
See PEP 394 - http://www.python.org/dev/peps/pep-0394/ for more
details.
2012-10-23 13:30:58 +01:00
Nick Mathewson
aa59c1e924 New --quiet option for event_rpcgen.py 2012-08-28 16:14:17 -04:00
Ross Lagerwall
ffb0ba0712 event_rpcgen.py now prints status information to stdout and errors to stderr.
Before, running make > /dev/null would result in status information cluttering
the error log. This changes it so that event_rpcgen.py prints status
information to stdout like the rest of the build tools.
2012-03-06 06:05:04 +02:00
Nick Mathewson
bcefd24694 Make event_rpcgen.py output conform to indentifier conventions, more 2012-02-29 15:07:32 -05:00
Nick Mathewson
372bff1c07 Make event_rpcgen.py output conform to indentifier conventions 2012-02-29 15:07:31 -05:00
Nick Mathewson
e49e289129 Update copyright notices to 2012 2012-02-10 17:29:53 -05:00
Nick Mathewson
f1250eb698 add a requested docstring for event_rpcgen.CommandLine.__init__ 2010-10-25 15:23:41 -04:00
Nick Mathewson
ec347b9225 Move event-config.h to include/event2
This change means that all required include files are in event2, and
all files not in event2/* are optional.
2010-08-06 20:21:27 -04:00
Nick Mathewson
f6ab2a2811 Fix a memory leak when unmarshalling RPC object arrays
The old code would use type_var_add() for its side-effect of expanding the
array, then leak the new object that was added to the array.

The new code adds a static function to handle the array resizing.
2010-04-23 23:55:30 -04:00
Shuo Chen
755fbf16c3 Add void* arguments to request_new and reply_new evrpc hooks
This makes evprc setup more extensible, and helps with Shuo Chen's
work on implementing Google protocol buffers rpc on top of Libevent 2
evrpc.

This patch breaks binary compatibility with previous versions of
Libevent, since it changes struct evrpc and the signature of
evrpc_register_generic().  Since all compliant code should be calling
evrpc_register_generic via EVRPC_REGISTER, it shouldn't break source
compatibility.

(Code by Shuo Chen; commit message by Nick)
2010-04-14 14:27:29 -04:00
Nick Mathewson
91fe23fc08 Tolerate code that returns from a fatal_cb.
Also, replace more abort() calls with EVUTIL_ASSERT() or event_errx.
2009-11-20 15:46:04 -05:00
Nick Mathewson
f9de8670fd Fix a declaration of __func__ in rpcgen.
svn:r1535
2009-11-16 22:23:06 +00:00
Nick Mathewson
a826a75800 Some tweaks to Brodie Thesfield's MSVC patch.
svn:r1386
2009-07-28 19:41:48 +00:00
Nick Mathewson
5d71b25b51 Remove all trailing whitespace from end-of-line.
svn:r1350
2009-07-17 18:38:38 +00:00
Niels Provos
6469598e56 Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg; plus a tiny tweak
svn:r1336
2009-07-03 17:43:26 +00:00
Niels Provos
fbb181d1aa Allow specifying the output filename for rpcgen; based on work by jmansion; patch from Zack Weinberg.
svn:r1335
2009-07-03 17:31:17 +00:00
Niels Provos
bbcc54ef9c fix preamble of rpcgen-generated files to rely on event2 includes; based on work by jmansion; patch from Zack Weinberg.
svn:r1334
2009-07-03 17:25:45 +00:00
Niels Provos
37d3e16ce9 Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg
svn:r1333
2009-07-03 17:20:56 +00:00
Niels Provos
b228ff91b8 remove vararg macros for accessing evrpc structs
svn:r1243
2009-04-25 00:15:31 +00:00
Nick Mathewson
9516df0e2e Fix c89 bugs reported by Cory Stup.
Others may remain.  I wasn't able to get gcc --std=c89 to build libevent
at all, so I don't know what compiler the original reporter is using here.

Note that this change requires us to disable the part of our rpc code
that uses variadic macros when using a non-gcc compiler.  This is a
problem if we want our rpc api to be portable.

svn:r1231
2009-04-23 05:40:06 +00:00
Nick Mathewson
a8f6d961eb Actually stop using EVBUFFER_LENGTH/DATA, and move them to buffer_compat.h
svn:r1183
2009-04-17 06:56:09 +00:00
Nick Mathewson
9993137cbb Remove all trailing whitespace in all the source files.
svn:r1063
2009-01-27 21:10:31 +00:00
Niels Provos
99a1063e73 support 64-bit integers in rpc structs
svn:r856
2008-06-21 02:21:25 +00:00
Nick Mathewson
bb37fbb22e r19601@catbus: nickm | 2008-05-05 11:45:04 -0400
Make event_rpcgen.py use the new headers.


svn:r775
2008-05-05 15:45:47 +00:00