def start_psyco(): """ run psyco if it is installed """ try: import psyco print "starting psyco..." import re psyco.cannotcompile(re.compile) psyco.full() except: pass
def cannot_compile(thing): try: import psyco except ImportError: return return psyco.cannotcompile(thing)
def usepsyco(self, options): # options.psyco == None means the default, which is "full", but don't give a warning... # options.psyco == "none" means don't use psyco at all... if getattr(options, "psyco", "none") == "none": return try: import psyco except Exception: if options.psyco is not None: self.warning("psyco unavailable", options, sys.exc_info()) return if options.psyco is None: options.psyco = "full" if options.psyco == "full": psyco.full() elif options.psyco == "profile": psyco.profile() # tell psyco the functions it cannot compile, to prevent warnings import encodings psyco.cannotcompile(encodings.search_function)
def main(): parser = optparse.OptionParser() toggle = lambda x: ("store_%s" % (not x)).lower() parser.add_option("-f", dest="filename", metavar="<file>", default=FILENAME, help="data file (default: %default)") parser.add_option( "-r", dest="reset", default=RESET, action=toggle(RESET), help="reset database (default: %default)" ) parser.add_option( "-o", dest="order", metavar="<int>", default=ORDER, type="int", help="markov order (default: %default)" ) if PSYCO: parser.add_option("-p", dest="psyco", default=PSYCO, action=toggle(PSYCO), help="use psyco (default: %default)") opts, args = parser.parse_args() if PSYCO: if opts.psyco: psyco.cannotcompile(re.compile) psyco.full() if os.path.exists(opts.filename) and not opts.reset: with open(opts.filename, "rb") as fp: hal = pickle.load(fp) else: hal = HAL(order=opts.order) try: for path in args: hal.train(path) while True: line = raw_input(">>> ") print hal.process(line, reply=True, learn=True) except (EOFError, KeyboardInterrupt): print finally: with open(opts.filename, "wb") as fp: pickle.dump(hal, fp) return 0
except AttributeError: pass assert d[i] == d1 def do_test(n, do_test_1=do_test_1): random.jumpahead(n*111222333444555666777L) N = 1 TAIL = 'lo' objects = [None, -1, 0, 1, 123455+N, -99-N, 'hel'+TAIL, [1,2], {(5,): do_test}, 5.43+0.01*N, xrange(5)] do_test_1(objects) for o in objects[4:]: #print '%5d -> %r' % (sys.getrefcount(o), o) assert sys.getrefcount(o) == 4 psyco.cannotcompile(do_test) def subprocess_test(n): sys.stdout.flush() childpid = os.fork() if not childpid: do_test(n) sys.exit(0) childpid, status = os.wait() return os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0 ##def test_compact_stress(repeat=20): ## for i in range(repeat): ## yield subprocess_test, i
# SEE http://code.djangoproject.com/wiki/PsycoMiddleware # Import the required modules import re from platform import architecture # We should use psyco only on 32 bot systems if architecture()[0] == '32bit': try: import psyco except ImportError: pass else: # re.compile does not benefit from psyco psyco.cannotcompile(re.compile) # psyco.profile seems like the most sane choice psyco.profile() # The middleware class definition is just here so django doesn't whine. # Note also that we placed this class outside the if so that # the middleware can be used without effect. class PsycoMiddleware(object): """ Enables the psyco extension module which can massively speed up the execution of any Python code. """ pass # vim: set ft=python ai ts=4 sts=4 et sw=4 sta nowrap nu :
def _disable_checking(self, text_view): """Disable checking on the given text_view.""" spell = None try: spell = self.gtkspell.get_from_text_view(text_view) except SystemError, e: # At least on Mandriva .get_from_text_view() sometimes returns # a SystemError without a description. Things seem to work fine # anyway, so let's ignore it and hope for the best. pass if not spell is None: spell.detach() text_view.spell_lang = None if psyco: psyco.cannotcompile(_disable_checking) # SIGNAL HANDLERS # def _on_unit_lang_changed(self, unit_view, text_view, language): if not self.gtkspell: return if not self.enchant.dict_exists(language): # Sometimes enchants *wants* a country code, other times it does not. # For the cases where it requires one, we look for the first language # code that enchant supports and use that one. for code in self.enchant.list_languages(): if code.startswith(language): language = code break
try: from django.db import models as django_models import psyco psyco.cannotcompile(django_models.sql.query.Query.clone) except ImportError: pass import datetime import hashlib import math import random import re from socket import inet_aton, inet_ntoa import string import struct import uuid from django.db.models import AutoField, BooleanField, CharField, DateField, \ DateTimeField, FloatField, ForeignKey, Q, TextField, \ IntegerField, IPAddressField, ManyToManyField, Model from django.db.models.signals import post_init from django.contrib.auth.models import User def get_delta_time_sec(t1, t2): """Returns the number of seconds between two times.""" deltaT = t2 - t1 return deltaT.seconds + 60*60*24*deltaT.days def make_mask_field(): return IntegerField(choices=tuple([(i, u'/%d'%i) for i in range(1,33)]), help_text='Number of bits which are dedicated to a' +
from parser import parse, GMLSyntaxError import sys sys.setrecursionlimit(120000) psyco = (sys.argv[1] == "-p") if psyco: files = sys.argv[2:] else: files = sys.argv[1:] if psyco: try: import psyco psyco.full() psyco.cannotcompile(do_evaluate) print "Using psyco" except ImportError: print "psyco not installed" pass for f in files: print f print "=" * len(f) try: r = evaluate(parse(tokenize(preprocess(f)))) except GMLSyntaxError: print "contains syntax errors" except GMLRuntimeError: print "runtime error" except GMLSubscriptError:
import unittest from test import test_support from test.test_support import run_unittest, have_unicode from django.template import Origin, Template, Context, TemplateDoesNotExist from django.conf import settings from django.apps import apps from django.conf.urls import patterns, include from django.contrib import admin import time try: import psyco from django.db.models.sql.query import Query psyco.cannotcompile(Query.clone) except ImportError: pass template_source = """ {% extends "admin/base_site.html" %} {% load i18n admin_static %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}" />{% endblock %} {% block coltype %}colMS{% endblock %} {% block bodyclass %}{{ block.super }} dashboard{% endblock %} {% block breadcrumbs %}{% endblock %}
try: from django.db import models as django_models import psyco psyco.cannotcompile(django_models.sql.query.Query.clone) except ImportError: pass import datetime import hashlib import math import random import re from socket import inet_aton, inet_ntoa import string import struct import uuid from django.db.models import AutoField, BooleanField, CharField, DateField, \ DateTimeField, FloatField, ForeignKey, Q, TextField, \ IntegerField, IPAddressField, ManyToManyField, Model from django.db.models.signals import post_init from django.contrib.auth.models import User def get_delta_time_sec(t1, t2): """Returns the number of seconds between two times.""" deltaT = t2 - t1 return deltaT.seconds + 60 * 60 * 24 * deltaT.days def make_mask_field():
def prevent_compile(obj): for a in dir(obj): attr = getattr(obj, a) if type(attr) == types.FunctionType: psyco.cannotcompile(attr)
if getattr(text_view, 'spell_lang', 'xxxx') is None: # No change necessary - already disabled return spell = None try: spell = self.gtkspell.get_from_text_view(text_view) except SystemError, e: # At least on Mandriva .get_from_text_view() sometimes returns # a SystemError without a description. Things seem to work fine # anyway, so let's ignore it and hope for the best. pass if not spell is None: spell.detach() text_view.spell_lang = None if psyco: psyco.cannotcompile(_disable_checking) # SIGNAL HANDLERS # def _on_unit_lang_changed(self, unit_view, text_view, language): if not self.gtkspell: return if language == 'en': language = 'en_US' if not language in self._seen_languages and not self.enchant.dict_exists(language): # Sometimes enchants *wants* a country code, other times it does not. # For the cases where it requires one, we look for the first language # code that enchant supports and use that one. for code in self._enchant_languages:
try: # try to import the dateutils and time module from time import strftime from dateutils import daycount, returndate # ,counttodate # counttodate returns a daynumber as a date except: DATEIN = 0 # If PSYCOON is set to 0 then we won't try and import the psyco module # IF importing fails, PSYCOON is set to 0 PSYCOON = 1 if PSYCOON: try: import psyco psyco.full() from psyco.classes import * try: psyco.cannotcompile(re.compile) # psyco hinders rather than helps regular expression compilation except NameError: pass except: PSYCOON = 0 # note - changing the order of the TABLE here can be used to change the mapping. TABLE = '_-0123456789' + \ 'abcdefghijklmnopqrstuvwxyz'+ \ 'NOPQRSTUVWXYZABCDEFGHIJKLM' # table should be exactly 64 printable characters long... or we'll all die horribly # Obviously the same TABLE should be used for decoding as for encoding.... # This version of TABLE (v1.1.2) uses only characters that are safe to pass in URLs # (e.g. using the GET method for passing FORM data)
df = multitorrent.shutdown() stop_rawserver = lambda r: rawserver.stop() df.addCallbacks(stop_rawserver, stop_rawserver) rawserver.add_task(0, core_doneflag.addCallback, lambda r: rawserver.external_add_task(0, shutdown)) return multitorrent if __name__ == '__main__': print rawserver.reactor try: import psyco import traceback psyco.cannotcompile(traceback.print_stack) psyco.cannotcompile(traceback.format_stack) psyco.cannotcompile(traceback.extract_stack) psyco.bind(RawServer.listen_forever) from BTL import sparse_set psyco.bind(sparse_set.SparseSet) from BitTorrent import PiecePicker psyco.bind(PiecePicker.PieceBuckets) psyco.bind(PiecePicker.PiecePicker) from BitTorrent import PieceSetBuckets psyco.bind(PieceSetBuckets.PieceSetBuckets) psyco.bind(PieceSetBuckets.SortedPieceBuckets) from BTL import bitfield psyco.bind(bitfield.Bitfield) except ImportError: pass
print 'test_getframe():' while 1: try: f = sys._getframe(i) except ValueError: break #print '%-26s %-60s %-40s' % (f, f.f_code, f.f_locals.keys()) print f.f_code.co_name.replace('<module>', '?') i += 1 def test_getframe1(): return test_getframe() psyco.cannotcompile(test_getframe1) def test_getframe_b(): import sys i = 0 print 'test_getframe_b():' f = sys._getframe() while f is not None: print f.f_code.co_name.replace('<module>', '?') f = f.f_back # walk the stack with f_back def test_getframe_b1(): return test_getframe_b()
from platform import architecture if architecture()[0] != '32bit': raise Exception("Don't use this on non-32-bit platforms") # let ImportError propagate at module load time so that people can notice and fix it import psyco import re from django.contrib.auth.middleware import AuthenticationMiddleware psyco.cannotcompile(re.compile) psyco.cannotcompile(AuthenticationMiddleware.process_request) #psyco.profile(0.25) psyco.full() class PsycoMiddleware(object): """ This middleware enables the psyco extension module which can massively speed up the execution of any Python code. """ def process_request(self, request): return None
def prevent_compile(obj): for a in dir(obj): attr = getattr(obj,a) if type(attr) == types.FunctionType: psyco.cannotcompile(attr)
# Banner print("Process memory finder") print("by Mario Vilas (mvilas at gmail.com)") print # Parse the command line self.parse_cmdline() # Prepare the input self.prepare_input() # Perform the search on the selected targets self.do_search() #------------------------------------------------------------------------------ def main(argv): return Main(argv).run() if __name__ == '__main__': try: import psyco psyco.cannotcompile(re.compile) psyco.bind(main) except ImportError: pass main(sys.argv)
# No change necessary - already disabled return spell = None try: spell = self.gtkspell.get_from_text_view(text_view) except SystemError, e: # At least on Mandriva .get_from_text_view() sometimes returns # a SystemError without a description. Things seem to work fine # anyway, so let's ignore it and hope for the best. pass if not spell is None: spell.detach() text_view.spell_lang = None if psyco: psyco.cannotcompile(_disable_checking) # SIGNAL HANDLERS # def _on_unit_lang_changed(self, unit_view, text_view, language): if not self.gtkspell: return # enchant doesn't like anything except plain strings (bug 1852) language = str(language) if language == 'en': language = 'en_US' elif language == 'pt': language == 'pt_PT' if not language in self._seen_languages and not self.enchant.dict_exists(
from time import strftime from dateutils import daycount, returndate # ,counttodate # counttodate returns a daynumber as a date except: DATEIN = 0 # If PSYCOON is set to 0 then we won't try and import the psyco module # IF importing fails, PSYCOON is set to 0 PSYCOON = 1 if PSYCOON: try: import psyco psyco.full() from psyco.classes import * try: psyco.cannotcompile( re.compile ) # psyco hinders rather than helps regular expression compilation except NameError: pass except: PSYCOON = 0 # note - changing the order of the TABLE here can be used to change the mapping. TABLE = '_-0123456789' + \ 'abcdefghijklmnopqrstuvwxyz'+ \ 'NOPQRSTUVWXYZABCDEFGHIJKLM' # table should be exactly 64 printable characters long... or we'll all die horribly # Obviously the same TABLE should be used for decoding as for encoding.... # This version of TABLE (v1.1.2) uses only characters that are safe to pass in URLs # (e.g. using the GET method for passing FORM data)
# register shutdown action def shutdown(): df = multitorrent.shutdown() stop_rawserver = lambda r : rawserver.stop() df.addCallbacks(stop_rawserver, stop_rawserver) rawserver.add_task(0, core_doneflag.addCallback, lambda r: rawserver.external_add_task(0, shutdown)) return multitorrent if __name__ == '__main__': print rawserver.reactor try: import psyco import traceback psyco.cannotcompile(traceback.print_stack) psyco.cannotcompile(traceback.format_stack) psyco.cannotcompile(traceback.extract_stack) psyco.bind(RawServer.listen_forever) from BTL import sparse_set psyco.bind(sparse_set.SparseSet) from BitTorrent import PiecePicker psyco.bind(PiecePicker.PieceBuckets) psyco.bind(PiecePicker.PiecePicker) from BitTorrent import PieceSetBuckets psyco.bind(PieceSetBuckets.PieceSetBuckets) psyco.bind(PieceSetBuckets.SortedPieceBuckets) from BTL import bitfield psyco.bind(bitfield.Bitfield) except ImportError: pass