Package lib :: Package cuckoo :: Package common :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

Classes [hide private]
  TimeoutServer
Timeout server for XMLRPC.
  TimeoutTransport
  Singleton
Singleton.
  ThreadSingleton
Singleton per thread.
  SuperLock
Functions [hide private]
 
create_folders(root='.', folders=[])
Create directories.
source code
 
create_folder(root='.', folder=None)
Create directory.
source code
 
delete_folder(folder)
Delete a folder and all its subdirectories.
source code
 
convert_char(c)
Escapes characters.
source code
 
is_printable(s)
Test if a string is printable.
source code
 
convert_to_printable(s)
Convert char to printable.
source code
 
datetime_to_iso(timestamp)
Parse a datatime string and returns a datetime in iso format.
source code
 
get_filename_from_path(path)
Cross-platform filename extraction from path.
source code
 
store_temp_file(filedata, filename, path=None)
Store a temporary file.
source code
 
to_unicode(s)
Attempt to fix non uft-8 string into utf-8.
source code
 
cleanup_value(v)
Cleanup utility function, strips some unwanted parts from values.
source code
 
classlock(f)
Classlock decorator (created for database.Database).
source code
 
hash_file(method, filepath)
Calculates an hash on a file by path.
source code
 
md5_file(filepath) source code
 
sha1_file(filepath) source code
 
sha256_file(filepath) source code
 
guid_name(guid) source code
 
exception_message()
Creates a message describing an unhandled exception.
source code
 
jsbeautify(javascript)
Beautifies Javascript through jsbeautifier and ignore some messages.
source code
 
htmlprettify(html)
Beautifies HTML through BeautifulSoup4.
source code
 
json_default(obj)
JSON serializer for objects not serializable by default json code
source code
 
json_hook(obj)
JSON object hook, deserializing datetimes ($date)
source code
 
json_encode(obj, **kwargs)
JSON encoding wrapper that handles datetime objects
source code
 
json_decode(x)
JSON decoder that does ugly first-level datetime handling
source code
 
versiontuple(v)
Return the version as a tuple for easy comparison.
source code
Variables [hide private]
  HAVE_BS4 = False
  HAVE_CHARDET = False
  HAVE_JSBEAUTIFIER = False
  log = logging.getLogger(__name__)
  PRINTABLE_CHARACTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL...
  GUIDS = {}
  _jsbeautify_blacklist = ['', 'error: Unknown p.a.c.k.e.r. enco...
  _jsbeautify_lock = threading.Lock()
  __package__ = 'lib.cuckoo.common'
Function Details [hide private]

create_folders(root='.', folders=[])

source code 

Create directories.

Parameters:
  • root - root path.
  • folders - folders list to be created.
Raises:

create_folder(root='.', folder=None)

source code 

Create directory.

Parameters:
  • root - root path.
  • folder - folder name to be created.
Raises:

delete_folder(folder)

source code 

Delete a folder and all its subdirectories.

Parameters:
  • folder - path to delete.
Raises:

convert_char(c)

source code 

Escapes characters.

Parameters:
  • c - dirty char.
Returns:
sanitized char.

convert_to_printable(s)

source code 

Convert char to printable.

Parameters:
  • s - string.
Returns:
sanitized string.

datetime_to_iso(timestamp)

source code 

Parse a datatime string and returns a datetime in iso format.

Parameters:
  • timestamp - timestamp string
Returns:
ISO datetime

get_filename_from_path(path)

source code 

Cross-platform filename extraction from path.

Parameters:
  • path - file path.
Returns:
filename.

store_temp_file(filedata, filename, path=None)

source code 

Store a temporary file.

Parameters:
  • filedata - content of the original file.
  • filename - name of the original file.
  • path - optional path for temp directory.
Returns:
path to the temporary file.

to_unicode(s)

source code 

Attempt to fix non uft-8 string into utf-8. It tries to guess input encoding, if fail retry with a replace strategy (so undetectable chars will be escaped).

See Also: fuller list of encodings at http://docs.python.org/library/codecs.html#standard-encodings

classlock(f)

source code 

Classlock decorator (created for database.Database). Used to put a lock to avoid sqlite errors.

hash_file(method, filepath)

source code 

Calculates an hash on a file by path.

Parameters:
  • method - callable hashing method
  • path - file path
Returns:
computed hash string

Variables Details [hide private]

PRINTABLE_CHARACTERS

Value:
'''abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%\
&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\r
'''

_jsbeautify_blacklist

Value:
['', 'error: Unknown p.a.c.k.e.r. encoding.\n']