当前位置: 首页>>代码示例>>Python>>正文


Python lang.ClassLoader类代码示例

本文整理汇总了Python中java.lang.ClassLoader的典型用法代码示例。如果您正苦于以下问题:Python ClassLoader类的具体用法?Python ClassLoader怎么用?Python ClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: archive_read

def archive_read(archive, path):
    from java.lang import ClassLoader
    from java.io import InputStreamReader, BufferedReader

    # --- make sure this works from within .jar files and such
    stream = ClassLoader.getSystemResourceAsStream(path)
    reader = BufferedReader(InputStreamReader(stream))
    archive.addAll(reader)
开发者ID:BackupTheBerlios,项目名称:gavrog,代码行数:8,代码来源:identify.py

示例2: get_jython_jar

def get_jython_jar():
    from java.lang import ClassLoader  # @UnresolvedImport
    cl = ClassLoader.getSystemClassLoader()
    paths = map(lambda url: url.getFile(), cl.getURLs())
    for p in paths:
        if 'jython.jar' in p:
            return p
    raise RuntimeError('Unable to find jython.jar')
开发者ID:wesleybl,项目名称:Pydev,代码行数:8,代码来源:debugger_fixtures.py

示例3: __init__

 def __init__(self):
     if ClassPath._instance:
         self.__dict__.update(ClassPath._instance.__dict__)
     else:
         if 'CLASSPATH' in os.environ:
             self._path = classpath.split(classpathsep)
         else:
             raise InstallationError("Cannot find CLASSPATH environmment variable")
         self._stdloader = ClassLoader.getSystemClassLoader()
         ClassPath._instance = self
开发者ID:RedstonerServer,项目名称:Python-Plugin-Loader,代码行数:10,代码来源:jclasspath.py

示例4: __init__

 def __init__(self):
     if ClassPath._instance:
         self.__dict__.update(ClassPath._instance.__dict__)
     else:
         if 'CLASSPATH' in os.environ:
             self._path = classpath.split(classpathsep)
         else:
             self._path = []
         self._stdloader = ClassLoader.getSystemClassLoader()
         ClassPath._instance = self
开发者ID:fiber-space,项目名称:jynx,代码行数:10,代码来源:jclasspath.py

示例5: addURL

 def addURL(self, u): 
      """Purpose: Call this with u= URL for 
      the new Class/jar to be loaded""" 
      sysloader = javaClassLoader.getSystemClassLoader() 
      sysclass = URLClassLoader 
      method = sysclass.getDeclaredMethod("addURL", [javaURL]) 
      a = method.setAccessible(1) 
      jar_a = jarray.array([u], javaObject) 
      b = method.invoke(sysloader, [u]) 
      return u 
开发者ID:dimagi,项目名称:touchforms,代码行数:10,代码来源:classPathHacker.py

示例6: get_logging_config

def get_logging_config():
    """Returns the absolute path to the logging config file
    """

    # We need to find the path to the /pyrig
    from java.lang import ClassLoader
    cl = ClassLoader.getSystemClassLoader()
    paths = map(lambda url: url.getFile(), cl.getURLs())

    # Search all available paths for the one to /pyrig
    path = next(x for x in paths if "pyrig" in x)

    # Now we can return the absolute path to the logging file
    return os.path.join(path, "logging.conf")
开发者ID:potty-dzmeia,项目名称:jatu,代码行数:14,代码来源:misc_utils.py

示例7: _jython_set_classpath

def _jython_set_classpath(jars):
    '''
    import a jar at runtime (needed for JDBC [Class.forName])

    adapted by Bastian Bowe from
    http://stackoverflow.com/questions/3015059/jython-classpath-sys-path-and-jdbc-drivers
    '''
    from java.net import URL, URLClassLoader
    from java.lang import ClassLoader
    from java.io import File
    m = URLClassLoader.getDeclaredMethod("addURL", [URL])
    m.accessible = 1
    urls = [File(i).toURL() for i in jars]
    m.invoke(ClassLoader.getSystemClassLoader(), urls)
开发者ID:LetschM,项目名称:iis,代码行数:14,代码来源:dbapi2.py

示例8: actionPerformed

 def actionPerformed(self, event):
   browsers = ["google-chrome", "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", "kazehakase", "mozilla"]
   osName = System.getProperty("os.name")
   helpHTML = ClassLoader.getSystemResource("help.html").toString()
   if osName.find("Mac OS") == 0:
     Class.forName("com.apple.eio.FileManager").getDeclaredMethod( "openURL", [String().getClass()]).invoke(None, [helpHTML])
   elif osName.find("Windows") == 0:
     Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + helpHTML)
   else:
     browser = None
     for b in browsers:
       if browser == None and Runtime.getRuntime().exec(["which", b]).getInputStream().read() != -1:
         browser = b
         Runtime.getRuntime().exec([browser, helpHTML])
开发者ID:pavithra03,项目名称:neofelis,代码行数:14,代码来源:main.py

示例9: set_font

def set_font(font_size):
    '''
    Loads font from resources' ttf file.
    DejaVuSans doesn't work in Retina display screens properly, so check OS,
    if OSX then use Monaco instead.
    '''
    # Take into account user preferred font size
    if "mac" in System.getProperty("os.name").lower():
        font = Font("Monaco", Font.PLAIN, font_size)
    else:
        path_to_ttf = 'resources/fonts/dejavu/ttf/DejaVuSans.ttf'
        loader = ClassLoader.getSystemClassLoader()
        stream = loader.getResourceAsStream(path_to_ttf)
        font = Font.createFont(Font.TRUETYPE_FONT, stream)
        font = font.deriveFont(Font.PLAIN, font_size)
    return font
开发者ID:oracc,项目名称:nammu,代码行数:16,代码来源:__init__.py

示例10: importJar

def importJar(jarFile):
    '''
    import a jar at runtime (needed for JDBC [Class.forName])

    adapted from http://forum.java.sun.com/thread.jspa?threadID=300557
    Author: SG Langer Jan 2007 translated the above Java to Jython
    Author: [email protected] simplified and updated for jython-2.5.3b3

    >>> importJar('mysql-connector-java-5.1.29-bin.jar')
    >>> import java.lang.Class
    >>> java.lang.Class.forName('com.mysql.jdbc.Driver')
    <type 'com.mysql.jdbc.Driver'>
    '''
    from java.net import URL, URLClassLoader
    from java.lang import ClassLoader
    from java.io import File
    m = URLClassLoader.getDeclaredMethod("addURL", [URL])
    m.accessible = 1
    m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
开发者ID:lalo73,项目名称:jython-jdbc-example,代码行数:19,代码来源:importer.py

示例11: get_yaml_config

def get_yaml_config(yaml_filename):
    '''
    Load contents of <yaml_filename> into dictionary.
    Note file_handler's filename needs to be an absolute path and hence
    manually changed from here.
    '''
    # Create helper object to load log config from jar resources
    # Load config details from yaml file.
    # Note getResource returns a java.net.URL object which is incompatible
    # with Python's open method, so we need to work around it by copying the
    # file to the home directory and open from there.
    yaml_path = 'resources/config/{}'.format(yaml_filename)
    loader = ClassLoader.getSystemClassLoader()
    config_file_url = loader.getResource(yaml_path)
    # In Unix getResource returns the path with prefix "file:" but in
    # Windows prefix is "jar:file:"
    path_to_jar = str(config_file_url).split('file:')[1]
    path_to_jar = path_to_jar.split('!')[0]

    path_to_config = get_log_path(yaml_filename)

    # Check if log config file exists already.
    # If it doesn't, paste it from JAR's resources to there.
    # If it does, check is up to date with latest version
    if not os.path.isfile(path_to_config):
        copy_yaml_to_home(path_to_jar, yaml_path, path_to_config)
    else:
        # We are running from the JAR file, not the local console
        update_yaml_config(path_to_jar, yaml_path, path_to_config)

    # Load local YAML file and perform required patches on the settings in
    # memory if the settings version is different between the jar and the local
    # file. Ensures that memory and file settings always match.
    (jar_config, local_config,
     jar_version, local_version) = get_config_versions(path_to_jar, yaml_path,
                                                       path_to_config)

    if yaml_filename == 'settings.yaml':
        if different_versions(jar_version, local_version):
            return patch_config(local_config)

    return local_config
开发者ID:oracc,项目名称:nammu,代码行数:42,代码来源:__init__.py

示例12: read_from_jar

def read_from_jar(relative_path):
    '''
    reads a file from within a jar. returns the file content
    '''
    from java.lang import ClassLoader
    from java.io import InputStreamReader, BufferedReader

    loader = ClassLoader.getSystemClassLoader()
    stream = loader.getResourceAsStream(relative_path)
    reader = BufferedReader(InputStreamReader(stream))
    
    line = reader.readLine()
    buf = ''
    while line is not None:
        buf += line
        line = reader.readLine()
        
    reader.close()
    stream.close()
    return buf
开发者ID:Schnitzl42,项目名称:JLibcloud,代码行数:20,代码来源:utils.py

示例13: addFile

def addFile(jarFile):
    '''
    http://stackoverflow.com/questions/3015059/jython-classpath-sys-path-and-jdbc-drivers
    import a jar at runtime (needed for JDBC [Class.forName])

    adapted from http://forum.java.sun.com/thread.jspa?threadID=300557
    Author: SG Langer Jan 2007 translated the above Java to Jython
    Author: [email protected] simplified and updated for jython-2.5.3b3

    >>> importJar('jars/jtds-1.2.5.jar')
    >>> import java.lang.Class
    >>> java.lang.Class.forName('net.sourceforge.jtds.jdbc.Driver')
    <type 'net.sourceforge.jtds.jdbc.Driver'>
    '''
    from java.net import URL, URLClassLoader
    from java.lang import ClassLoader
    from java.io import File
    m = URLClassLoader.getDeclaredMethod("addURL", [URL])
    m.accessible = 1
    m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
    return 
开发者ID:bingpan1,项目名称:programming-language-network,代码行数:21,代码来源:classpath.py

示例14: getResourceDirectoryForModuleName

def getResourceDirectoryForModuleName(moduleName):
    resourceDirectory = None
    try:
        prefix = "content/"
        moduleNamePath = moduleName.replace(".", "/")
        resourcePath = prefix + moduleNamePath
        
        if PYCYCLE_DEBUG_RESOURCE_ROOT is None:
            # serving from the "content" directory embedded in the JAR file
            resourceDirectory = _ClassLoader.getSystemResource(resourcePath).toExternalForm()
        #
        else:
            # serving from the "content" directory from the debug root
            resourceDirectory = _File(PYCYCLE_DEBUG_RESOURCE_ROOT, resourcePath).toString()
        #
    #
    except Exception as ex:
        message = "Could not get resource directory for module '" + str(moduleName) + "'. "
        message += "Caused by: \n" + repr(ex)
        raise RuntimeError(message)
    #
    return resourceDirectory
开发者ID:nsaney,项目名称:PycycleDealer,代码行数:22,代码来源:__init__.py

示例15: load

 def load(self, img_file, namehint=None):
     """
     Load image from file as a java.awt.image.BufferedImage.
     Return the bufferedimage as a Surface.
     """
     try:
         try:
             f = env.japplet.class.getResource(img_file.replace('\\','/'))    #java uses /, not os.path Windows \
             if not f:
                 raise
         except:
             cload = ClassLoader.getSystemClassLoader()
             f = cload.getResourceAsStream(img_file.replace('\\','/'))
             print "fe"
             
     except:
         
         f = File(img_file)
     
     bimage = ImageIO.read(f)
     surf = Surface(bimage)
     return surf
开发者ID:bowbahdoe,项目名称:Keys,代码行数:22,代码来源:image.py


注:本文中的java.lang.ClassLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。