Exemple #1
0
def import_repy_module(repy_module_name):
    """
  <Arguments>
    repy_module_name
      The name of the repy file without the ".repy" on the end.
  """
    return __import__(repyhelper.translate(repy_module_name + ".repy"))
def import_repy_module(repy_module_name):
  """
  <Arguments>
    repy_module_name
      The name of the repy file without the ".repy" on the end.
  """
  return __import__(repyhelper.translate(repy_module_name + ".repy"))
Exemple #3
0
def test_name(name, expected):
  if prepare_file(name):
    translation_name = repyhelper.translate(name)
    
    if translation_name != expected:
      print "ERROR: expected:", expected, " but translation name was:", translation_name
      
    test_utils.cleanup_file(name)
    test_utils.cleanup_file(translation_name + ".py")
  else:
    print "Couldn't prepare test for filename test:", name
def test_name(name, expected):
  if prepare_file(name):
    translation_name = repyhelper.translate(name)
    
    if translation_name != expected:
      print "ERROR: expected:", expected, " but translation name was:", translation_name
      
    test_utils.cleanup_file(name)
    test_utils.cleanup_file(translation_name + ".py")
  else:
    print "Couldn't prepare test for filename test:", name
import test_utils
import repyhelper

TESTFILE = "rhtest_callargs.r2py"
#Make sure we have fresh translations per test run

test_utils.cleanup_translations([TESTFILE])


#Now test that the string escaping works properly
modname = repyhelper.translate(TESTFILE, callargs=["\"a\"", "samoas", "\\\'b\"\\", ""])
mod = __import__(modname)


if mod.callargs[0] != "\"a\"":
  print "double quotes not properly escaped:", mod.callargs[0]
if mod.callargs[1] != "samoas":
  print "simple string badly escaped:", mod.callargs[2]
if mod.callargs[2] != "\\\'b\"\\":
  print "double/single quotes not escaped properly:", mod.callargs[1]
if mod.callargs[3] != "":
  print "empty string improperly passed:", mod.callargs[1]

test_utils.cleanup_translations([TESTFILE])
import time
time.sleep(1)
"""
Test the callfunc arg of the translations, to make sure it actually
gets used

"""

import repyhelper
import test_utils

TESTFILE = 'rhtest_callfunc.r2py'

#Make sure we have fresh translations per test run
test_utils.cleanup_translations([TESTFILE])

modname = repyhelper.translate(TESTFILE, callfunc='plankton')
a = __import__(modname)


### Try again with translate_and_import
#Allow retranslation
test_utils.cleanup_translations([TESTFILE])

repyhelper.translate_and_import(TESTFILE, callfunc='plankton')

test_utils.cleanup_translations([TESTFILE])
"""
Test the callargs parameter of the translation calls, to make sure it actually
gets used

"""

import repyhelper
import test_utils

TESTFILE = "rhtest_callargs.repy"

#Make sure we have fresh translations per test run
test_utils.cleanup_translations([TESTFILE])

modname = repyhelper.translate(TESTFILE, callargs=["", "samoas"])
mod = __import__(modname)

if mod.num_callargs() is not 2:
    print "translate had wrong number of callargs:", mod.num_callargs()
    print "callargs =", mod.callargs

test_utils.cleanup_translations([TESTFILE])
import time
time.sleep(1)
"""
Test the callargs parameter of the translation calls, to make sure it actually
gets used

"""

import repyhelper
import test_utils

TESTFILE = "rhtest_callargs.r2py"

#Make sure we have fresh translations per test run
test_utils.cleanup_translations([TESTFILE])


modname = repyhelper.translate(TESTFILE, callargs=["", "samoas"])
mod = __import__(modname)

if mod.num_callargs() is not 2:
  print "translate had wrong number of callargs:", mod.num_callargs()
  print "callargs =", mod.callargs

test_utils.cleanup_translations([TESTFILE])
import time
time.sleep(1)
import test_utils
import repyhelper

TESTFILE = "rhtest_callargs.repy"
#Make sure we have fresh translations per test run

test_utils.cleanup_translations([TESTFILE])

#Now test that the string escaping works properly
modname = repyhelper.translate(TESTFILE,
                               callargs=["\"a\"", "samoas", "\\\'b\"\\", ""])
mod = __import__(modname)

if mod.callargs[0] != "\"a\"":
    print "double quotes not properly escaped:", mod.callargs[0]
if mod.callargs[1] != "samoas":
    print "simple string badly escaped:", mod.callargs[2]
if mod.callargs[2] != "\\\'b\"\\":
    print "double/single quotes not escaped properly:", mod.callargs[1]
if mod.callargs[3] != "":
    print "empty string improperly passed:", mod.callargs[1]

test_utils.cleanup_translations([TESTFILE])
import time

time.sleep(1)
Exemple #10
0
  No output indicates success
  
"""

TESTFILES = [
    'rhtestrecursion_1.repy', 'rhtestrecursion_2.repy',
    'rhtestrecursion_3.repy', 'rhtestrecursion_4.repy'
]

import repyhelper
import test_utils

test_utils.cleanup_translations(TESTFILES)

#This tests circular includes
translation = repyhelper.translate(TESTFILES[0])
if translation == "":
    print "Error translating circular recursion"
else:
    #actually include it to make sure the translation was valid
    mod = __import__(translation)

test_utils.cleanup_translations(TESTFILES)

#Tests self include
translation = repyhelper.translate(TESTFILES[-1])
if translation == "":
    print "Error translating self-include"
else:
    mod2 = __import__(translation)
  Uses files of the form rhtestrecursion_n.repy
  
  No output indicates success
  
"""

TESTFILES = ['rhtestrecursion_1.repy', 'rhtestrecursion_2.repy', 'rhtestrecursion_3.repy', 'rhtestrecursion_4.repy']


import repyhelper
import test_utils

test_utils.cleanup_translations(TESTFILES)

#This tests circular includes
translation = repyhelper.translate(TESTFILES[0])
if translation == "":
  print "Error translating circular recursion"
else:
  #actually include it to make sure the translation was valid
  mod = __import__(translation)
 
test_utils.cleanup_translations(TESTFILES)
  
  
#Tests self include  
translation = repyhelper.translate(TESTFILES[-1])
if translation == "":
  print "Error translating self-include"
else:
  mod2 = __import__(translation)
Exemple #12
0
"""
Test the callfunc arg of the translations, to make sure it actually
gets used

"""

import repyhelper
import test_utils

TESTFILE = 'rhtest_callfunc.r2py'

#Make sure we have fresh translations per test run
test_utils.cleanup_translations([TESTFILE])

modname = repyhelper.translate(TESTFILE, callfunc='plankton')
a = __import__(modname)

### Try again with translate_and_import
#Allow retranslation
test_utils.cleanup_translations([TESTFILE])

repyhelper.translate_and_import(TESTFILE, callfunc='plankton')

test_utils.cleanup_translations([TESTFILE])
"""
Test to make sure specifying that modules have a unique mycontext works
"""

import repyhelper
import test_utils

TESTFILE1 = "rhtest_mycontext_unique1.repy"
TESTFILE2 = "rhtest_mycontext_unique2.repy"

test_utils.cleanup_translations([TESTFILE1, TESTFILE2])

modname1 = repyhelper.translate(TESTFILE1, shared_mycontext=False)
mod1 = __import__(modname1)

modname2 = repyhelper.translate(TESTFILE2, shared_mycontext=False)
mod2 = __import__(modname2)

if mod2.foo() is None:
    pass
else:
    print "Context sharing wasn't unique'! foo returned", mod2.foo()

test_utils.cleanup_translations([TESTFILE1, TESTFILE2])
"""
Test to make sure specifying that modules have a unique mycontext works
"""

import repyhelper
import test_utils


TESTFILE1 = "rhtest_mycontext_unique1.repy"
TESTFILE2 = "rhtest_mycontext_unique2.repy"

test_utils.cleanup_translations([TESTFILE1, TESTFILE2])


modname1 = repyhelper.translate(TESTFILE1, shared_mycontext=False)
mod1 = __import__(modname1)

modname2 = repyhelper.translate(TESTFILE2, shared_mycontext=False)
mod2 = __import__(modname2)

if mod2.foo() is None:
    pass
else:
    print "Context sharing wasn't unique'! foo returned", mod2.foo()

test_utils.cleanup_translations([TESTFILE1, TESTFILE2])
Exemple #15
0
import seattleclearinghouse_xmlrpc   # Needed for checking auth. exceptions
import logging
import traceback
import selexorhelper
import ssl
import settings
import substitutions
# Raised when we cannot connect to the clearinghouse XMLRPC server
import xmlrpclib
import time

# We need to translate first, then import separately
# This is so that they do not overwrite python's open()
import repyhelper
# Used for serializing objects to comm. with clients
repyhelper.translate('serialize.repy')
# Used to read the nodestate transition key
repyhelper.translate('rsa.repy')

import serialize_repy
import rsa_repy



# This is a fix for slow response times for python's base http server.
# See: http://bugs.python.org/issue6085
def _bare_address_string(self):
    host, port = self.client_address[:2]
    return str(host)
BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string
# End slow respond time fix for python's base http server.