prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): <|fim_middle|> def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._name
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): <|fim_middle|> def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): <|fim_middle|> def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): <|fim_middle|> def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)])
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): <|fim_middle|> class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name())
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): <|fim_middle|> return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): <|fim_middle|> def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value()
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): <|fim_middle|> def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._size
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): <|fim_middle|> return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._value
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): <|fim_middle|> class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): <|fim_middle|> @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): <|fim_middle|> def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): <|fim_middle|> def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): <|fim_middle|> @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._registers.iteritems()
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): <|fim_middle|> @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): <|fim_middle|> class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): <|fim_middle|> class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): <|fim_middle|> @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self)
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): <|fim_middle|> class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
raise NotImplementedError
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): <|fim_middle|> def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): <|fim_middle|> def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
self._cpu_factory = cpu_factory self._cpus = {}
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): <|fim_middle|> def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): <|fim_middle|> _cpu_map = {} <|fim▁end|>
_cpu_map[cls.architecture()] = cls return cls
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: <|fim_middle|> chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._register_fmt[self.size()] % self.value()
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: <|fim_middle|> return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return register_dict[name]
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: <|fim_middle|> cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
return self._cpus[architecture]
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def <|fim_middle|>(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__init__
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def <|fim_middle|>(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
name
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def <|fim_middle|>(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
size
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def <|fim_middle|>(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
value
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def <|fim_middle|>(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
str
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def <|fim_middle|>(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
create_static_register
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def <|fim_middle|>(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__init__
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def <|fim_middle|>(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
size
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def <|fim_middle|>(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
value
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def <|fim_middle|>(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__init__
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def <|fim_middle|>(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
architecture
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def <|fim_middle|>(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
register
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def <|fim_middle|>(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
registers
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def <|fim_middle|>(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
stack_pointer
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def <|fim_middle|>(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
program_counter
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def <|fim_middle|>(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
create_cpu
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def <|fim_middle|>(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
create_register
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def <|fim_middle|>(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
__init__
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def <|fim_middle|>(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def register_cpu(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
get_cpu
<|file_name|>cpu.py<|end_file_name|><|fim▁begin|># (void)walker hardware platform support # Copyright (C) 2012-2013 David Holm <[email protected]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import abc from ..utils import OrderedDict from ..utils import enum Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', enum_type='Architecture') class Register(object): _register_fmt = {16: '0x%032lX', 10: '0x%020lX', 8: '0x%016lX', 4: '0x%08lX', 2: '0x%04lX', 1: '0x%02lX'} def __init__(self, name): self._name = name def name(self): return self._name def size(self): raise NotImplementedError def value(self): raise NotImplementedError def str(self): if self.value() is not None: return self._register_fmt[self.size()] % self.value() chars_per_byte = 2 return ''.join(['-' * (self.size() * chars_per_byte)]) def create_static_register(register): class StaticRegister(type(register), object): def __init__(self, name): super(StaticRegister, self).__init__(name) self._size = register.size() self._value = register.value() def size(self): return self._size def value(self): return self._value return StaticRegister(register.name()) class Cpu(object): __metaclass__ = abc.ABCMeta def __init__(self, cpu_factory, registers): self._registers = OrderedDict() for group, register_list in registers.iteritems(): registers = OrderedDict([(x.name(), cpu_factory.create_register(self, x)) for x in register_list]) self._registers[group] = registers @classmethod @abc.abstractmethod def architecture(cls): raise NotImplementedError def register(self, name): for register_dict in self._registers.itervalues(): if name in register_dict: return register_dict[name] return None def registers(self): return self._registers.iteritems() @abc.abstractmethod def stack_pointer(self): raise NotImplementedError @abc.abstractmethod def program_counter(self): raise NotImplementedError class CpuFactory(object): __metaclass__ = abc.ABCMeta def create_cpu(self, architecture): assert architecture in _cpu_map return _cpu_map.get(architecture, None)(self) @abc.abstractmethod def create_register(self, cpu, register): raise NotImplementedError class CpuRepository(object): def __init__(self, cpu_factory): self._cpu_factory = cpu_factory self._cpus = {} def get_cpu(self, architecture): if architecture in self._cpus: return self._cpus[architecture] cpu = self._cpu_factory.create_cpu(architecture) self._cpus[architecture] = cpu return cpu def <|fim_middle|>(cls): _cpu_map[cls.architecture()] = cls return cls _cpu_map = {} <|fim▁end|>
register_cpu
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw)<|fim▁hole|> w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF =============================================<|fim▁end|>
def hittest(self, pt): x, y = pt
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): <|fim_middle|> except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): <|fim_middle|> def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw)
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): <|fim_middle|> except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: <|fim_middle|> class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
pass
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): <|fim_middle|> # ============= EOF ============================================= <|fim▁end|>
""" this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd))
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 <|fim_middle|> def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw)
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): <|fim_middle|> # ============= EOF ============================================= <|fim▁end|>
DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd))
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: <|fim_middle|> super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: <|fim_middle|> if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0))
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: <|fim_middle|> self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
self.x += d
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: <|fim_middle|> # ============= EOF ============================================= <|fim▁end|>
h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd))
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def <|fim_middle|>(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
overlay
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def <|fim_middle|>(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
hittest
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def <|fim_middle|>(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def do_layout(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
overlay
<|file_name|>flow_label.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright 2013 Jake Ross # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # ============= enthought library imports ======================= from chaco.data_label import DataLabel from chaco.plot_label import PlotLabel # ============= standard library imports ======================== from numpy import max from traits.api import Bool, Str # ============= local library imports ========================== from pychron.pipeline.plot.overlays.mean_indicator_overlay import MovableMixin try: class FlowPlotLabel(PlotLabel, MovableMixin): def overlay(self, component, gc, *args, **kw): if self.ox: self.x = self.ox - self.offset_x self.y = self.oy - self.offset_y super(FlowPlotLabel, self).overlay(component, gc, *args, **kw) def hittest(self, pt): x, y = pt w, h = self.get_preferred_size() return abs(x - self.x) < w and abs(y - self.y) < h except TypeError: # documentation auto doc hack class FlowPlotLabel: pass class FlowDataLabel(DataLabel): """ this label repositions itself if doesn't fit within the its component bounds. """ constrain_x = Bool(True) constrain_y = Bool(True) # position_event=Event id = Str # _ox=None # def _draw(self, gc, **kw): # self.font='modern 18' # gc.set_font(self.font) # print 'draw', self.font # super(FlowDataLabel, self)._draw(gc,**kw) # def _set_x(self, val): # super(FlowDataLabel, self)._set_x(val) # if self._ox is None: # self._ox = val # elif self._ox != val: # self.position_event=(self.x, self.y) # # def _set_y(self, val): # super(FlowDataLabel, self)._set_y(val) # if val>0: # self.position_event = (self.x, self.y) def overlay(self, component, gc, *args, **kw): # face name was getting set to "Helvetica" by reportlab during pdf generation # set face_name back to "" to prevent font display issue. see issue #72 self.font.face_name = "" super(FlowDataLabel, self).overlay(component, gc, *args, **kw) def <|fim_middle|>(self, **kw): DataLabel.do_layout(self, **kw) ws, hs = self._cached_line_sizes.T if self.constrain_x: w = max(ws) d = self.component.x2 - (self.x + w + 3 * self.border_padding) if d < 0: self.x += d self.x = max((self.x, 0)) if self.constrain_y: h = max(hs) self.y = max((self.y, 0)) yd = self.component.y2 - h - 2 * self.border_padding - self.line_spacing self.y = min((self.y, yd)) # ============= EOF ============================================= <|fim▁end|>
do_layout
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import os from setuptools import setup import sys if sys.version_info < (2, 6): raise Exception('Wiggelen requires Python 2.6 or higher.') install_requires = [] # Python 2.6 does not include the argparse module. try: import argparse except ImportError: install_requires.append('argparse') # Python 2.6 does not include OrderedDict. try: from collections import OrderedDict except ImportError: install_requires.append('ordereddict') try: with open('README.rst') as readme: long_description = readme.read() except IOError: long_description = 'See https://pypi.python.org/pypi/wiggelen' # This is quite the hack, but we don't want to import our package from here # since that's recipe for disaster (it might have some uninstalled # dependencies, or we might import another already installed version). distmeta = {} for line in open(os.path.join('wiggelen', '__init__.py')): try: field, value = (x.strip() for x in line.split('=')) except ValueError: continue if field == '__version_info__': value = value.strip('[]()') value = '.'.join(x.strip(' \'"') for x in value.split(',')) else: value = value.strip('\'"') distmeta[field] = value setup( name='wiggelen', version=distmeta['__version_info__'], description='Working with wiggle tracks in Python', long_description=long_description, author=distmeta['__author__'], author_email=distmeta['__contact__'], url=distmeta['__homepage__'], license='MIT License', platforms=['any'],<|fim▁hole|> }, classifiers = [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering', ], keywords='bioinformatics' )<|fim▁end|>
packages=['wiggelen'], install_requires=install_requires, entry_points = { 'console_scripts': ['wiggelen = wiggelen.commands:main']
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import os from setuptools import setup import sys if sys.version_info < (2, 6): <|fim_middle|> install_requires = [] # Python 2.6 does not include the argparse module. try: import argparse except ImportError: install_requires.append('argparse') # Python 2.6 does not include OrderedDict. try: from collections import OrderedDict except ImportError: install_requires.append('ordereddict') try: with open('README.rst') as readme: long_description = readme.read() except IOError: long_description = 'See https://pypi.python.org/pypi/wiggelen' # This is quite the hack, but we don't want to import our package from here # since that's recipe for disaster (it might have some uninstalled # dependencies, or we might import another already installed version). distmeta = {} for line in open(os.path.join('wiggelen', '__init__.py')): try: field, value = (x.strip() for x in line.split('=')) except ValueError: continue if field == '__version_info__': value = value.strip('[]()') value = '.'.join(x.strip(' \'"') for x in value.split(',')) else: value = value.strip('\'"') distmeta[field] = value setup( name='wiggelen', version=distmeta['__version_info__'], description='Working with wiggle tracks in Python', long_description=long_description, author=distmeta['__author__'], author_email=distmeta['__contact__'], url=distmeta['__homepage__'], license='MIT License', platforms=['any'], packages=['wiggelen'], install_requires=install_requires, entry_points = { 'console_scripts': ['wiggelen = wiggelen.commands:main'] }, classifiers = [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering', ], keywords='bioinformatics' ) <|fim▁end|>
raise Exception('Wiggelen requires Python 2.6 or higher.')
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import os from setuptools import setup import sys if sys.version_info < (2, 6): raise Exception('Wiggelen requires Python 2.6 or higher.') install_requires = [] # Python 2.6 does not include the argparse module. try: import argparse except ImportError: install_requires.append('argparse') # Python 2.6 does not include OrderedDict. try: from collections import OrderedDict except ImportError: install_requires.append('ordereddict') try: with open('README.rst') as readme: long_description = readme.read() except IOError: long_description = 'See https://pypi.python.org/pypi/wiggelen' # This is quite the hack, but we don't want to import our package from here # since that's recipe for disaster (it might have some uninstalled # dependencies, or we might import another already installed version). distmeta = {} for line in open(os.path.join('wiggelen', '__init__.py')): try: field, value = (x.strip() for x in line.split('=')) except ValueError: continue if field == '__version_info__': <|fim_middle|> else: value = value.strip('\'"') distmeta[field] = value setup( name='wiggelen', version=distmeta['__version_info__'], description='Working with wiggle tracks in Python', long_description=long_description, author=distmeta['__author__'], author_email=distmeta['__contact__'], url=distmeta['__homepage__'], license='MIT License', platforms=['any'], packages=['wiggelen'], install_requires=install_requires, entry_points = { 'console_scripts': ['wiggelen = wiggelen.commands:main'] }, classifiers = [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering', ], keywords='bioinformatics' ) <|fim▁end|>
value = value.strip('[]()') value = '.'.join(x.strip(' \'"') for x in value.split(','))
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import os from setuptools import setup import sys if sys.version_info < (2, 6): raise Exception('Wiggelen requires Python 2.6 or higher.') install_requires = [] # Python 2.6 does not include the argparse module. try: import argparse except ImportError: install_requires.append('argparse') # Python 2.6 does not include OrderedDict. try: from collections import OrderedDict except ImportError: install_requires.append('ordereddict') try: with open('README.rst') as readme: long_description = readme.read() except IOError: long_description = 'See https://pypi.python.org/pypi/wiggelen' # This is quite the hack, but we don't want to import our package from here # since that's recipe for disaster (it might have some uninstalled # dependencies, or we might import another already installed version). distmeta = {} for line in open(os.path.join('wiggelen', '__init__.py')): try: field, value = (x.strip() for x in line.split('=')) except ValueError: continue if field == '__version_info__': value = value.strip('[]()') value = '.'.join(x.strip(' \'"') for x in value.split(',')) else: <|fim_middle|> distmeta[field] = value setup( name='wiggelen', version=distmeta['__version_info__'], description='Working with wiggle tracks in Python', long_description=long_description, author=distmeta['__author__'], author_email=distmeta['__contact__'], url=distmeta['__homepage__'], license='MIT License', platforms=['any'], packages=['wiggelen'], install_requires=install_requires, entry_points = { 'console_scripts': ['wiggelen = wiggelen.commands:main'] }, classifiers = [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering', ], keywords='bioinformatics' ) <|fim▁end|>
value = value.strip('\'"')
<|file_name|>test.py<|end_file_name|><|fim▁begin|>from test_support import * <|fim▁hole|>prove_all(prover=["plop"], opt=["--why3-conf=test.conf"])<|fim▁end|>
# this test calls a prover which is correctly configured but whose execution # gives an error (here: the prover executable doesn't exist). The intent is to # test the output of gnatprove in this specific case
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text<|fim▁hole|> if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results<|fim▁end|>
size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): <|fim_middle|> <|fim▁end|>
def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): <|fim_middle|> def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self)
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): <|fim_middle|> def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): <|fim_middle|> def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): <|fim_middle|> <|fim▁end|>
results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: <|fim_middle|> return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.warning("Invalid username or password or pin. Check your settings")
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): <|fim_middle|> login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
return True
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: <|fim_middle|> if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.warning("Unable to connect to provider") return False
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): <|fim_middle|> return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.warning("Invalid username or password. Check your settings") return False
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): <|fim_middle|> for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
return results
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": <|fim_middle|> search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.debug(_("Search String: {search_string}".format(search_string=search_string)))
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: <|fim_middle|> try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: <|fim_middle|> torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.debug("Data returned from provider does not contain any torrents") continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: <|fim_middle|> torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.exception("Could not find table of torrents") continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): <|fim_middle|> else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
title = link["title"]
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: <|fim_middle|> download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
title = link.contents[0]
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: <|fim_middle|> except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
torrent_size = cells[7].text size = convert_size(torrent_size) or -1
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): <|fim_middle|> # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: <|fim_middle|> item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": <|fim_middle|> continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) )
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": <|fim_middle|> items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers))
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def <|fim_middle|>(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
__init__
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def <|fim_middle|>(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
_check_auth
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def <|fim_middle|>(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def search(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
login
<|file_name|>pretome.py<|end_file_name|><|fim▁begin|>import re import traceback from urllib.parse import quote from requests.utils import dict_from_cookiejar from sickchill import logger from sickchill.helper.common import convert_size, try_int from sickchill.oldbeard import tvcache from sickchill.oldbeard.bs4_parser import BS4Parser from sickchill.providers.torrent.TorrentProvider import TorrentProvider class Provider(TorrentProvider): def __init__(self): super().__init__("Pretome") self.username = None self.password = None self.pin = None self.minseed = 0 self.minleech = 0 self.urls = { "base_url": "https://pretome.info", "login": "https://pretome.info/takelogin.php", "detail": "https://pretome.info/details.php?id=%s", "search": "https://pretome.info/browse.php?search=%s%s", "download": "https://pretome.info/download.php/%s/%s.torrent", } self.url = self.urls["base_url"] self.categories = "&st=1&cat%5B%5D=7" self.proper_strings = ["PROPER", "REPACK"] self.cache = tvcache.TVCache(self) def _check_auth(self): if not self.username or not self.password or not self.pin: logger.warning("Invalid username or password or pin. Check your settings") return True def login(self): if any(dict_from_cookiejar(self.session.cookies).values()): return True login_params = {"username": self.username, "password": self.password, "login_pin": self.pin} response = self.get_url(self.urls["login"], post_data=login_params, returns="text") if not response: logger.warning("Unable to connect to provider") return False if re.search("Username or password incorrect", response): logger.warning("Invalid username or password. Check your settings") return False return True def <|fim_middle|>(self, search_params, age=0, ep_obj=None): results = [] if not self.login(): return results for mode in search_params: items = [] logger.debug(_("Search Mode: {mode}".format(mode=mode))) for search_string in search_params[mode]: if mode != "RSS": logger.debug(_("Search String: {search_string}".format(search_string=search_string))) search_url = self.urls["search"] % (quote(search_string), self.categories) data = self.get_url(search_url, returns="text") if not data: continue try: with BS4Parser(data, "html5lib") as html: # Continue only if one Release is found empty = html.find("h2", text="No .torrents fit this filter criteria") if empty: logger.debug("Data returned from provider does not contain any torrents") continue torrent_table = html.find("table", style="border: none; width: 100%;") if not torrent_table: logger.exception("Could not find table of torrents") continue torrent_rows = torrent_table("tr", class_="browse") for result in torrent_rows: cells = result("td") size = None link = cells[1].find("a", style="font-size: 1.25em; font-weight: bold;") torrent_id = link["href"].replace("details.php?id=", "") try: if link.get("title", ""): title = link["title"] else: title = link.contents[0] download_url = self.urls["download"] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: torrent_size = cells[7].text size = convert_size(torrent_size) or -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != "RSS": logger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers ) ) continue item = {"title": title, "link": download_url, "size": size, "seeders": seeders, "leechers": leechers, "hash": ""} if mode != "RSS": logger.debug("Found result: {0} with {1} seeders and {2} leechers".format(title, seeders, leechers)) items.append(item) except Exception: logger.exception("Failed parsing provider. Traceback: {0}".format(traceback.format_exc())) # For each search mode sort all the items by seeders if available items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True) results += items return results <|fim▁end|>
search
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop):<|fim▁hole|> def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0)<|fim▁end|>
pass
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): <|fim_middle|> def clim_get_val(self, prop): pass def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
""" Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime()
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop): <|fim_middle|> def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
pass
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop): pass def clim_query(self): <|fim_middle|> def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
""" returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop): pass def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): <|fim_middle|> # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
""" Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p]
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: <|fim_middle|> clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: return # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop): pass def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
print("load_clim")
<|file_name|>_isyclimate.py<|end_file_name|><|fim▁begin|>""" This is a subfile for IsyClass.py These funtions are accessable via the Isy class opj """ __author__ = 'Peter Shipley <[email protected]>' __copyright__ = "Copyright (C) 2013 Peter Shipley" __license__ = "BSD" import time ## ## Climate funtions ## def load_clim(self): """ Load climate data from ISY device args: none internal function call """ if self.debug & 0x01: print("load_clim") clim_tree = self._getXMLetree("/rest/climate") self.climateinfo = dict() if clim_tree is None: <|fim_middle|> # Isy._printXML(self.climateinfo) for cl in clim_tree.iter("climate"): for k, v in cl.items(): self.climateinfo[k] = v for ce in list(cl): self.climateinfo[ce.tag] = ce.text self.climateinfo["time"] = time.gmtime() def clim_get_val(self, prop): pass def clim_query(self): """ returns dictionary of climate info """ if not self.climateinfo: self.load_clim() # # ADD CODE to check self.cachetime # return self.climateinfo def clim_iter(self): """ Iterate though climate values args: None returns: Return an iterator over the climate values """ if not self.climateinfo: self.load_clim() k = self.climateinfo.keys() for p in k: yield self.climateinfo[p] # Do nothing # (syntax check) # if __name__ == "__main__": import __main__ print(__main__.__file__) print("syntax ok") exit(0) <|fim▁end|>
return