# 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
                "Stacktrace",
                "Stacktrace.gz",
                "Stacktrace.txt.1",
                ]
            trace = None
            first_crash = None
            for fname in try_files:
                stack_path = os.path.join(path, fname)
                if os.path.isfile(stack_path):
                    try:
                        trace = LaunchpadStack.load_from_file(stack_path)
                    except Exception as e:
                        if first_crash is None:
                            first_crash = e
                        continue
                    if trace is None:
                        ERROR(stack_path + " did not contain a stack trace!")
                        if first_crash is not None:
                            raise first_crash
                    else:
                        break
            if trace is None:
                raise IOError("No stacktrace file found in %s" % (path))
            crash['stacktrace'] = trace
            crash['project'] = 'Ubuntu'
            #print json.dumps(crash, indent=4, default=repr)
        else:
            raise NotImplementedError("Not a directory, I don't know how to load this.")
        return crash


# 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

                "Stacktrace",
                "Stacktrace.gz",
                "Stacktrace.txt.1",
                ]
            trace = None
            first_crash = None
            for fname in try_files:
                stack_path = os.path.join(path, fname)
                if os.path.isfile(stack_path):
                    try:
                        trace = LaunchpadStack.load_from_file(stack_path)
                    except Exception as e:
                        if first_crash is None:
                            first_crash = e
                        continue
                    if trace is None:
                        ERROR(stack_path + " did not contain a stack trace!")
                        if first_crash is not None:
                            raise first_crash
                    else:
                        break
            if trace is None:
                raise IOError("No stacktrace file found in %s" % (path))
            crash['stacktrace'] = trace
            crash['project'] = 'Ubuntu'
            #print json.dumps(crash, indent=4, default=repr)
        else:
            raise NotImplementedError("Not a directory, I don't know how to load this.")
        return crash


class LaunchpadCrash(Crash):