text
stringlengths 0
93.6k
|
---|
lv = len(value)
|
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
|
# ----------------------------------------------------------------------
|
class quick_regexp(object):
|
"""
|
Quick regular expression class, which can be used directly in if()
|
statements in a perl-like fashion.
|
#### Sample code ####
|
r = quick_regexp()
|
if(r.search('pattern (test) (123)', string)):
|
print(r.groups[0]) # Prints 'test'
|
print(r.groups[1]) # Prints '123'
|
"""
|
def __init__(self):
|
self.groups = None
|
self.matched = False
|
def search(self, pattern, string, flags=0):
|
match = re.search(pattern, string, flags)
|
if match:
|
self.matched = True
|
if match.groups():
|
self.groups = re.search(pattern, string, flags).groups()
|
else:
|
self.groups = True
|
else:
|
self.matched = False
|
self.groups = None
|
return self.matched
|
# ----------------------------------------------------------------------
|
# #######################################
|
# ##### Configure logging behavior ######
|
# #######################################
|
# No need to change anything here
|
def _configureLogging(loglevel):
|
"""
|
Configures the default logger.
|
If the log level is set to NOTSET (0), the
|
logging is disabled
|
# More info here: https://docs.python.org/2/howto/logging.html
|
"""
|
numeric_log_level = getattr(logging, loglevel.upper(), None)
|
try:
|
if not isinstance(numeric_log_level, int):
|
raise ValueError()
|
except ValueError:
|
error_and_exit('Invalid log level: %s\n'
|
'\tLog level must be set to one of the following:\n'
|
'\t CRITICAL <- Least verbose\n'
|
'\t ERROR\n'
|
'\t WARNING\n'
|
'\t INFO\n'
|
'\t DEBUG <- Most verbose' % loglevel)
|
defaultLogger = logging.getLogger('default')
|
# If numeric_log_level == 0 (NOTSET), disable logging.
|
if not numeric_log_level:
|
numeric_log_level = 1000
|
defaultLogger.setLevel(numeric_log_level)
|
logFormatter = logging.Formatter()
|
defaultHandler = logging.StreamHandler()
|
defaultHandler.setFormatter(logFormatter)
|
defaultLogger.addHandler(defaultHandler)
|
# ######################################################
|
# ##### Add command line options in this function ######
|
# ######################################################
|
# Add the user defined command line arguments in this function
|
def _command_Line_Options():
|
"""
|
Define the accepted command line arguments in this function
|
Read the documentation of argparse for more advanced command line
|
argument parsing examples
|
http://docs.python.org/2/library/argparse.html
|
"""
|
parser = argparse.ArgumentParser(
|
description=PROGRAM_NAME + " version " + VERSION)
|
parser.add_argument("-v", "--version",
|
action="version", default=argparse.SUPPRESS,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.