# Path: partycrasher/crash.py
# class Crash(PCDict):
#     
#     __slots__ = tuple()
# 
#     synonyms = {
#         'crash_id': 'database_id', # Mozilla
#         'os_ver' : 'os_version', # Mozilla
#         'cpu_arch' : 'cpu', # Mozilla
#         'frames' : 'stacktrace', # Mozilla
#     }
# 
#     canonical_fields = {
#         'date': mustbe_date,
#         'stacktrace': PCType(
#             checker=Stacktrace,
#             converter=Stacktrace,
#             ),
#         'database_id': mustbe_string,
#         'project': mustbe_project,
#         'type': mustbe_crash_type,
#         'buckets': mustbe_buckets,
#     }
# 
#     def get_bucket_id(self, threshold):
#         key = Threshold(threshold).to_elasticsearch()
#         try:
#             buckets = self['buckets']
#         except KeyError:
#             raise Exception('No assigned buckets for: {!r}'.format(self))
#         try:
#             return buckets[key]
#         except KeyError:
#             raise Exception('Buckets threshold {} not assigned for: '
#                             '{!r}'.format(key, self))
# 
#     @classmethod
#     def load_from_file(cls, path):
#         from partycrasher import launchpad_crash
#         crash_classes = [ launchpad_crash.LaunchpadCrash ]
# 
#         crash = None
#         for crash_class in crash_classes:
#             try:
#                 crash = crash_class.load_from_file(path)
#             except NotImplementedError:
#                 raise
#             else:
#                 break
#         if crash is None:
#             raise NotImplementedError("I don't know how to load this!")
#         return crash
# 
#     @staticmethod
#     def make_id(project, database_id):
#         raise NotImplementedError("make_id removed")
# 
#     @property
#     def id(self):
#         return self['database_id']
#         #elif isinstance(o, Buckets):
#             #return o.json_serializable()
#     
#     def jsonify(self):
#         return self.as_dict()
#     
#     @classmethod
#     def fromjson(cls, s):
#         d = json.loads(s)
#         assert isinstance(d, dict)
#         c = cls(d)
#         return c
# 
# class Stacktrace(PCList):
#     __slots__ = tuple()
#     member_type = Stackframe
#     member_converter = Stackframe
#     
#     def jsonify(self):
#         return self._l
# 
# class Stackframe(PCDict):
#     """
#     Represents a Stackframe in a crash object. Proxy object for a dictionary.
#     """
#     __slots__ = tuple()
#     
#     synonyms = {}
#     
#     canonical_fields = {
#         'depth': mustbe_int,
#         'address': maybe_string,
#         'function': maybe_string,
#         'args': maybe_string,
#         'file': maybe_string,
#         'dylib': maybe_string,
#     }
#     
#     def jsonify(self):
#         assert self["function"] != "None"
#         return self.as_dict()
# 
# Path: partycrasher/stringified.py
# def fix_key_for_es(key):
#     if isinstance(key, bytes):
#         key = key.decode(encoding='utf-8', errors='replace')
#     key = key.replace('.', '_')
#     key = key.replace(':', '_')
#     key = key.replace(' ', '_')
#     return key


from partycrasher.crash import Crash, Stacktrace, Stackframe
from logging import critical, error, warning, info, debug
from partycrasher.stringified import fix_key_for_es
import os, re, io, gzip, json, sys
import dateparser
import unicodedata
import datetime
import logging
import unittest
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime
        '\tdisplay_name = (const gchar *) 0x0\n'\
        '\tmode = 7185792\n'\
        '\tdisplay = <value optimized out>\n'\
        '\tscreen_number = 7563232\n'\
        '\tenable_metadata = 0\n'\
        '\tcontext = <value optimized out>\n'\
        '\targs = (GHashTable *) 0x6f4cc0\n'\
        '\tprogram = (GnomeProgram *) 0x6c1050'

    def test_ubuntu2(self):
        dirpath=tempfile.mkdtemp()
        try:
            # Test setup
            stacktrace_path = os.path.join(dirpath, "Stacktrace.txt (retraced)")
            with open(stacktrace_path, 'w') as stacktrace_file:
                stacktrace_file.write(self.example_ubuntu_stacktrace2)
            post_path = os.path.join(dirpath, "Post.txt")
            with open(post_path, 'w') as post_file:
                post_file.write(self.example_ubuntu_post2)
            
            # Test crash loader
            crash = Crash.load_from_file(dirpath)
            
            # test that contents are loaded correctly
            assert (isinstance(crash, Crash))
            assert (crash['cpu'] == 'amd64')
            assert (crash['date'] == datetime.datetime(2007, 6, 20, 10, 27, 6))
            stacktrace = crash['stacktrace']
            assert stacktrace is crash.stacktrace
            assert (isinstance(stacktrace, Stacktrace))

# Path: partycrasher/crash.py
# class Crash(PCDict):
#     
#     __slots__ = tuple()
# 
#     synonyms = {
#         'crash_id': 'database_id', # Mozilla
#         'os_ver' : 'os_version', # Mozilla
#         'cpu_arch' : 'cpu', # Mozilla
#         'frames' : 'stacktrace', # Mozilla
#     }
# 
#     canonical_fields = {
#         'date': mustbe_date,
#         'stacktrace': PCType(
#             checker=Stacktrace,
#             converter=Stacktrace,
#             ),
#         'database_id': mustbe_string,
#         'project': mustbe_project,
#         'type': mustbe_crash_type,
#         'buckets': mustbe_buckets,
#     }
# 
#     def get_bucket_id(self, threshold):
#         key = Threshold(threshold).to_elasticsearch()
#         try:
#             buckets = self['buckets']
#         except KeyError:
#             raise Exception('No assigned buckets for: {!r}'.format(self))
#         try:
#             return buckets[key]
#         except KeyError:
#             raise Exception('Buckets threshold {} not assigned for: '
#                             '{!r}'.format(key, self))
# 
#     @classmethod
#     def load_from_file(cls, path):
#         from partycrasher import launchpad_crash
#         crash_classes = [ launchpad_crash.LaunchpadCrash ]
# 
#         crash = None
#         for crash_class in crash_classes:
#             try:
#                 crash = crash_class.load_from_file(path)
#             except NotImplementedError:
#                 raise
#             else:
#                 break
#         if crash is None:
#             raise NotImplementedError("I don't know how to load this!")
#         return crash
# 
#     @staticmethod
#     def make_id(project, database_id):
#         raise NotImplementedError("make_id removed")
# 
#     @property
#     def id(self):
#         return self['database_id']
#         #elif isinstance(o, Buckets):
#             #return o.json_serializable()
#     
#     def jsonify(self):
#         return self.as_dict()
#     
#     @classmethod
#     def fromjson(cls, s):
#         d = json.loads(s)
#         assert isinstance(d, dict)
#         c = cls(d)
#         return c
# 
# class Stacktrace(PCList):
#     __slots__ = tuple()
#     member_type = Stackframe
#     member_converter = Stackframe
#     
#     def jsonify(self):
#         return self._l
# 
# class Stackframe(PCDict):
#     """
#     Represents a Stackframe in a crash object. Proxy object for a dictionary.
#     """
#     __slots__ = tuple()
#     
#     synonyms = {}
#     
#     canonical_fields = {
#         'depth': mustbe_int,
#         'address': maybe_string,
#         'function': maybe_string,
#         'args': maybe_string,
#         'file': maybe_string,
#         'dylib': maybe_string,
#     }
#     
#     def jsonify(self):
#         assert self["function"] != "None"
#         return self.as_dict()
# 
# Path: partycrasher/stringified.py
# def fix_key_for_es(key):
#     if isinstance(key, bytes):
#         key = key.decode(encoding='utf-8', errors='replace')
#     key = key.replace('.', '_')
#     key = key.replace(':', '_')
#     key = key.replace(' ', '_')
#     return key


# Path: partycrasher/launchpad_crash.py
from partycrasher.crash import Crash, Stacktrace, Stackframe
from logging import critical, error, warning, info, debug
from partycrasher.stringified import fix_key_for_es
import os, re, io, gzip, json, sys
import dateparser
import unicodedata
import datetime
import logging
import unittest
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime
        import tempfile
        import os
        import shutil
        import datetime

        '\tdisplay_name = (const gchar *) 0x0\n'\
        '\tmode = 7185792\n'\
        '\tdisplay = <value optimized out>\n'\
        '\tscreen_number = 7563232\n'\
        '\tenable_metadata = 0\n'\
        '\tcontext = <value optimized out>\n'\
        '\targs = (GHashTable *) 0x6f4cc0\n'\
        '\tprogram = (GnomeProgram *) 0x6c1050'

    def test_ubuntu2(self):
        dirpath=tempfile.mkdtemp()
        try:
            # Test setup
            stacktrace_path = os.path.join(dirpath, "Stacktrace.txt (retraced)")
            with open(stacktrace_path, 'w') as stacktrace_file:
                stacktrace_file.write(self.example_ubuntu_stacktrace2)
            post_path = os.path.join(dirpath, "Post.txt")
            with open(post_path, 'w') as post_file:
                post_file.write(self.example_ubuntu_post2)
            
            # Test crash loader
            crash = Crash.load_from_file(dirpath)
            
            # test that contents are loaded correctly
            assert (isinstance(crash, Crash))
            assert (crash['cpu'] == 'amd64')
            assert (crash['date'] == datetime.datetime(2007, 6, 20, 10, 27, 6))
            stacktrace = crash['stacktrace']
            assert stacktrace is crash.stacktrace
            assert (isinstance(stacktrace, Stacktrace))

            assert (isinstance(stacktrace[0], Stackframe))