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

Changes for pyparsing 3.1 #4580 #4760

Merged
merged 9 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion dependencies.ini
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ version_property: get_version()
[pyparsing]
dpkg_name: python3-pyparsing
minimum_version: 2.4.2
maximum_version: 3.1.0
rpm_name: python3-pyparsing
version_property: __version__

Expand Down
2 changes: 1 addition & 1 deletion plaso/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'pymodi': ('get_version()', '20210405', None, True),
'pymsiecf': ('get_version()', '20150314', None, True),
'pyolecf': ('get_version()', '20151223', None, True),
'pyparsing': ('__version__', '2.4.2', '3.1.0', True),
'pyparsing': ('__version__', '2.4.2', None, True),
'pyphdi': ('get_version()', '20220228', None, True),
'pyqcow': ('get_version()', '20201213', None, True),
'pyregf': ('get_version()', '20201002', None, True),
Expand Down
37 changes: 20 additions & 17 deletions plaso/parsers/text_plugins/android_logcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class AndroidLogcatTextPlugin(

ENCODING = 'utf-8'

_INTEGER = pyparsing.Word(pyparsing.nums).setParseAction(
_INTEGER = pyparsing.Word(pyparsing.nums).set_parse_action(
lambda tokens: int(tokens[0], 10))

_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).setParseAction(
_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).set_parse_action(
lambda tokens: int(tokens[0], 10))

_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).setParseAction(
_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).set_parse_action(
lambda tokens: int(tokens[0], 10))

_MONTH_DAY = (
Expand All @@ -115,45 +115,48 @@ class AndroidLogcatTextPlugin(
pyparsing.Word('+-', exact=1) + _TWO_DIGITS + _TWO_DIGITS)

_PID_AND_THREAD_IDENTIFIER = (
_INTEGER.setResultsName('pid') +
_INTEGER.setResultsName('thread_identifier'))
_INTEGER.set_results_name('pid') +
_INTEGER.set_results_name('thread_identifier'))

_USER_PID_AND_THREAD_IDENTIFIER = (
_INTEGER.setResultsName('user_identifier') +
_INTEGER.set_results_name('user_identifier') +
_PID_AND_THREAD_IDENTIFIER)

_END_OF_LINE = pyparsing.Suppress(pyparsing.LineEnd())

_BEGINNING_LINE = (
pyparsing.Suppress('--------- beginning of ') +
pyparsing.oneOf(['events', 'kernel', 'main', 'radio', 'system']) +
pyparsing.one_of(['events', 'kernel', 'main', 'radio', 'system']) +
_END_OF_LINE)

_THREADTIME_LINE_BODY = (
pyparsing.Or([
_USER_PID_AND_THREAD_IDENTIFIER, _PID_AND_THREAD_IDENTIFIER]) +
pyparsing.Word('VDIWEFS', exact=1).setResultsName('priority') +
pyparsing.Word('VDIWEFS', exact=1).set_results_name('priority') +
pyparsing.Optional(pyparsing.Word(
pyparsing.printables + ' ', excludeChars=':').setResultsName('tag')))
pyparsing.printables + ' ', excludeChars=':').set_results_name(
'tag')))

_TIME_LINE_BODY = (
pyparsing.Word('VDIWEFS', exact=1).setResultsName('priority') +
pyparsing.Word('VDIWEFS', exact=1).set_results_name('priority') +
pyparsing.Suppress('/') +
pyparsing.Word(
pyparsing.printables + ' ', excludeChars='(').setResultsName('tag') +
pyparsing.printables + ' ', excludeChars='(').set_results_name(
'tag') +
pyparsing.Suppress('(') +
pyparsing.Or([
_INTEGER.setResultsName('pid'),
(_INTEGER.setResultsName('user_identifier') +
pyparsing.Suppress(':') + _INTEGER.setResultsName('pid'))]) +
_INTEGER.set_results_name('pid'),
(_INTEGER.set_results_name('user_identifier') +
pyparsing.Suppress(':') + _INTEGER.set_results_name('pid'))]) +
pyparsing.Suppress(')'))

_LOG_LINE = (
_DATE_TIME.setResultsName('date_time') +
pyparsing.Optional(_TIME_ZONE_OFFSET).setResultsName('time_zone_offset') +
_DATE_TIME.set_results_name('date_time') +
pyparsing.Optional(_TIME_ZONE_OFFSET).set_results_name(
'time_zone_offset') +
(_THREADTIME_LINE_BODY ^ _TIME_LINE_BODY) +
pyparsing.Suppress(': ') +
pyparsing.restOfLine().setResultsName('message') +
pyparsing.restOfLine().set_results_name('message') +
_END_OF_LINE)

_LINE_STRUCTURES = [
Expand Down
40 changes: 20 additions & 20 deletions plaso/parsers/text_plugins/apache_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class ApacheAccessLogTextPlugin(interface.TextPlugin):
'nov': 11,
'dec': 12}

_INTEGER = pyparsing.Word(pyparsing.nums).setParseAction(
_INTEGER = pyparsing.Word(pyparsing.nums).set_parse_action(
lambda tokens: int(tokens[0], 10))

_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).setParseAction(
_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).set_parse_action(
lambda tokens: int(tokens[0], 10))

_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).setParseAction(
_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).set_parse_action(
lambda tokens: int(tokens[0], 10))

_THREE_LETTERS = pyparsing.Word(pyparsing.alphas, exact=3)
Expand All @@ -93,17 +93,17 @@ class ApacheAccessLogTextPlugin(interface.TextPlugin):
pyparsing.Suppress(':') + _TWO_DIGITS +
pyparsing.Suppress(':') + _TWO_DIGITS +
pyparsing.Suppress(':') + _TWO_DIGITS +
_TIME_ZONE_OFFSET + pyparsing.Suppress(']')).setResultsName('date_time')
_TIME_ZONE_OFFSET + pyparsing.Suppress(']')).set_results_name('date_time')

_HTTP_METHOD = pyparsing.oneOf([
_HTTP_METHOD = pyparsing.one_of([
'CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT',
'TRACE'])

_HTTP_VERSION = pyparsing.Combine(
pyparsing.Literal('HTTP/') + pyparsing.Word(pyparsing.nums + '.'))

_HTTP_REQUEST = pyparsing.Suppress('"') + pyparsing.Group(
_HTTP_METHOD + pyparsing.Regex(r'\S*') + _HTTP_VERSION).setResultsName(
_HTTP_METHOD + pyparsing.Regex(r'\S*') + _HTTP_VERSION).set_results_name(
'http_request') + pyparsing.Suppress('"')

_IP_ADDRESS = (
Expand All @@ -112,50 +112,50 @@ class ApacheAccessLogTextPlugin(interface.TextPlugin):

_REMOTE_NAME = (
pyparsing.Word(pyparsing.alphanums) |
pyparsing.Literal('-')).setResultsName('remote_name')
pyparsing.Literal('-')).set_results_name('remote_name')

_RESPONSE_BYTES = (
pyparsing.Literal('-') | _INTEGER).setResultsName('response_bytes')
pyparsing.Literal('-') | _INTEGER).set_results_name('response_bytes')

_SERVER_NAME = (
pyparsing.Word(pyparsing.alphanums + '-' + '.').setResultsName(
pyparsing.Word(pyparsing.alphanums + '-' + '.').set_results_name(
'server_name'))

_USER_AGENT = (
pyparsing.Suppress('"') +
pyparsing.CharsNotIn('"').setResultsName('user_agent') +
pyparsing.CharsNotIn('"').set_results_name('user_agent') +
pyparsing.Suppress('"'))

_USER_NAME = (
pyparsing.Word(pyparsing.alphanums + '@' + pyparsing.alphanums + '.') |
pyparsing.Word(pyparsing.alphanums) |
pyparsing.Literal('-')).setResultsName('user_name')
pyparsing.Literal('-')).set_results_name('user_name')

_END_OF_LINE = pyparsing.Suppress(pyparsing.LineEnd())

# Defined in https://httpd.apache.org/docs/2.4/logs.html
# format: "%h %l %u %t \"%r\" %>s %b"
_COMMON_LOG_FORMAT_LINE = (
_IP_ADDRESS.setResultsName('ip_address') +
_IP_ADDRESS.set_results_name('ip_address') +
_REMOTE_NAME +
_USER_NAME +
_DATE_TIME +
_HTTP_REQUEST +
_INTEGER.setResultsName('response_code') +
_INTEGER.set_results_name('response_code') +
_RESPONSE_BYTES +
_END_OF_LINE)

# Defined in https://httpd.apache.org/docs/2.4/logs.html
# format: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
_COMBINED_LOG_FORMAT_LINE = (
_IP_ADDRESS.setResultsName('ip_address') +
_IP_ADDRESS.set_results_name('ip_address') +
_REMOTE_NAME +
_USER_NAME +
_DATE_TIME +
_HTTP_REQUEST +
_INTEGER.setResultsName('response_code') +
_INTEGER.set_results_name('response_code') +
_RESPONSE_BYTES +
pyparsing.QuotedString('"').setResultsName('referer') +
pyparsing.QuotedString('"').set_results_name('referer') +
_USER_AGENT +
_END_OF_LINE)

Expand All @@ -164,15 +164,15 @@ class ApacheAccessLogTextPlugin(interface.TextPlugin):
_VHOST_COMBINED_LOG_FORMAT_LINE = (
_SERVER_NAME +
pyparsing.Suppress(':') +
_INTEGER.setResultsName('port_number') +
_IP_ADDRESS.setResultsName('ip_address') +
_INTEGER.set_results_name('port_number') +
_IP_ADDRESS.set_results_name('ip_address') +
_REMOTE_NAME +
_USER_NAME +
_DATE_TIME +
_HTTP_REQUEST +
_INTEGER.setResultsName('response_code') +
_INTEGER.set_results_name('response_code') +
_RESPONSE_BYTES +
pyparsing.QuotedString('"').setResultsName('referer') +
pyparsing.QuotedString('"').set_results_name('referer') +
_USER_AGENT +
_END_OF_LINE)

Expand Down
8 changes: 4 additions & 4 deletions plaso/parsers/text_plugins/apt_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class APTHistoryLogTextPlugin(interface.TextPlugin):

ENCODING = 'utf-8'

_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).setParseAction(
_TWO_DIGITS = pyparsing.Word(pyparsing.nums, exact=2).set_parse_action(
lambda tokens: int(tokens[0], 10))

_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).setParseAction(
_FOUR_DIGITS = pyparsing.Word(pyparsing.nums, exact=4).set_parse_action(
lambda tokens: int(tokens[0], 10))

_DATE_TIME = pyparsing.Group(
Expand All @@ -61,7 +61,7 @@ class APTHistoryLogTextPlugin(interface.TextPlugin):
_TWO_DIGITS +
_TWO_DIGITS + pyparsing.Suppress(':') +
_TWO_DIGITS + pyparsing.Suppress(':') +
_TWO_DIGITS).setResultsName('date_time')
_TWO_DIGITS).set_results_name('date_time')

_END_OF_LINE = pyparsing.Suppress(pyparsing.LineEnd())

Expand All @@ -70,7 +70,7 @@ class APTHistoryLogTextPlugin(interface.TextPlugin):
pyparsing.Literal('Start-Date:') + _DATE_TIME + _END_OF_LINE)

_RECORD_BODY_LINE = (
pyparsing.oneOf([
pyparsing.one_of([
'Commandline:',
'Downgrade:',
'Error:',
Expand Down
Loading