<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2013, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

""" Definition of shader program.

This code is inspired by similar classes from Pygly.

"""

from __future__ import print_function, division, absolute_import

import re
import sys
import weakref

import numpy as np

from vispy import gl
from . import GLObject, ext_available
from . import VertexBuffer, ElementBuffer
#from .program_inputs import UniformInputs, AttributeInputs
from .variable import Attribute, Uniform
from .shader import parse_shader_errors, VertexShader, FragmentShader
from vispy.util.six import string_types



class ProgramError(RuntimeError):
    """ Raised when something goes wrong that depens on state that was set 
    earlier (due to deferred loading).
    """
    pass



class Program(GLObject):
    """ Representation of a shader program. It combines (links) a 
    vertex and a fragment shaders to compose a complete program.
    On (normal, non-ES 2.0) implementations, multiple shaders of 
    each type are allowed).
    
    Objects of this class are also used to set the uniforms and
    attributes that are used by the shaders. To do so, simply add
    attributes to the `uniforms` and `attributes` members. The names
    of the added attributes should match with those used in the shaders.
    
    Parameters
    ----------
    vert : Shader object or string
        The VertexShader for this program. The string can be a file name
        or the source of the shading code. It can also be a list of 
        shaders, but this is not supported on genuine OpenGL ES 2.0.
    frag : Shader object or string
        The FragmentShader for this program. The string can be a file name
        or the source of the shading code. It can also be a list of 
        shaders, but this is not supported on genuine OpenGL ES 2.0.
    
    """
    
    def __init__(self, vert=None, frag=None):
        GLObject.__init__(self)
        
        # Manage enabled state (i.e. activated)
        self._active = False
        self._activated_objects = []
        
        # List of varying names to use for feedback
        self._feedback_vars = []
        
        # Inis lists of shaders
        self._verts = []
        self._frags = []
        
        # Containers for uniforms and attributes. 
        # name -> Variable
        self._attributes = {}
        self._uniforms = {}
        
        # Keep track of which names are active (queried after linking)
        # name -> location
        self._active_attributes = {}
        self._active_uniforms = {}
        
        # Keep track of number of vertices
        self._vertex_count = None
        
        shaders = []
        
        # Get all vertex shaders
        if vert is None:
            pass
        elif isinstance(vert, VertexShader):
            shaders.append(vert)
        elif isinstance(vert, string_types):
            shaders.append(VertexShader(vert))
        elif isinstance(vert, (list, tuple)):
            for shader in vert:
                if isinstance(shader, string_types):
                    shader = VertexShader(shader)
                shaders.append(shader)
        else:
            raise ValueError('Invalid value for VertexShader "%r"' % vert)
        
        # Get all fragment shaders
        if frag is None:
            pass
        elif isinstance(frag, FragmentShader):
            shaders.append(frag)
        elif isinstance(frag, string_types):
            shaders.append(FragmentShader(frag))
        elif isinstance(frag, (list, tuple)):
            for shader in frag:
                if isinstance(shader, string_types):
                    shader = FragmentShader(shader)
                shaders.append(shader)
        else:
            raise ValueError('Invalid value for FragmentShader "%r"' % frag)
        
        # Attach shaders now
        if shaders:
            self.attach(*shaders)
    
    
    def attach(self, *shaders):
        """ Attach one or more vertex/fragment shaders to the program. 
        
        Paramaters
        ----------
        *shaders : Shader objects
            The VertexShader or FragmentShader to attach.
        
        """
        # Tuple or list given?
        if len(shaders)==1 and isinstance(shaders[0], (list,tuple)):
            shaders = shaders[0]
        
        # Process each shader
        for shader in shaders:<commit_msg>Make program to use the is_string method<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2013, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

""" Definition of shader program.

This code is inspired by similar classes from Pygly.

"""

from __future__ import print_function, division, absolute_import

import re
import sys
import weakref

import numpy as np

from vispy import gl
from . import GLObject, ext_available
from . import VertexBuffer, ElementBuffer
from .variable import Attribute, Uniform
from .shader import VertexShader, FragmentShader
from vispy.util import is_string



class ProgramError(RuntimeError):
    """ Raised when something goes wrong that depens on state that was set 
    earlier (due to deferred loading).
    """
    pass



class Program(GLObject):
    """ Representation of a shader program. It combines (links) a 
    vertex and a fragment shaders to compose a complete program.
    On (normal, non-ES 2.0) implementations, multiple shaders of 
    each type are allowed).
    
    Objects of this class are also used to set the uniforms and
    attributes that are used by the shaders. To do so, simply add
    attributes to the `uniforms` and `attributes` members. The names
    of the added attributes should match with those used in the shaders.
    
    Parameters
    ----------
    vert : Shader object or string
        The VertexShader for this program. The string can be a file name
        or the source of the shading code. It can also be a list of 
        shaders, but this is not supported on genuine OpenGL ES 2.0.
    frag : Shader object or string
        The FragmentShader for this program. The string can be a file name
        or the source of the shading code. It can also be a list of 
        shaders, but this is not supported on genuine OpenGL ES 2.0.
    
    """
    
    def __init__(self, vert=None, frag=None):
        GLObject.__init__(self)
        
        # Manage enabled state (i.e. activated)
        self._active = False
        self._activated_objects = []
        
        # List of varying names to use for feedback
        self._feedback_vars = []
        
        # Inis lists of shaders
        self._verts = []
        self._frags = []
        
        # Containers for uniforms and attributes. 
        # name -> Variable
        self._attributes = {}
        self._uniforms = {}
        
        # Keep track of which names are active (queried after linking)
        # name -> location
        self._active_attributes = {}
        self._active_uniforms = {}
        
        # Keep track of number of vertices
        self._vertex_count = None
        
        shaders = []
        
        # Get all vertex shaders
        if vert is None:
            pass
        elif isinstance(vert, VertexShader):
            shaders.append(vert)
        elif is_string(vert):
            shaders.append(VertexShader(vert))
        elif isinstance(vert, (list, tuple)):
            for shader in vert:
                if is_string(shader):
                    shader = VertexShader(shader)
                shaders.append(shader)
        else:
            raise ValueError('Invalid value for VertexShader "%r"' % vert)
        
        # Get all fragment shaders
        if frag is None:
            pass
        elif isinstance(frag, FragmentShader):
            shaders.append(frag)
        elif is_string(frag):
            shaders.append(FragmentShader(frag))
        elif isinstance(frag, (list, tuple)):
            for shader in frag:
                if is_string(shader):
                    shader = FragmentShader(shader)
                shaders.append(shader)
        else:
            raise ValueError('Invalid value for FragmentShader "%r"' % frag)
        
        # Attach shaders now
        if shaders:
            self.attach(*shaders)
    
    
    def attach(self, *shaders):
        """ Attach one or more vertex/fragment shaders to the program. 
        
        Paramaters
        ----------
        *shaders : Shader objects
            The VertexShader or FragmentShader to attach.
        
        """
        # Tuple or list given?
        if len(shaders)==1 and isinstance(shaders[0], (list,tuple)):
            shaders = shaders[0]
        
        # Process each shader
        for shader in shaders:
{'fraction_non_alphanumeric': 0.07142048670062252, 'fraction_numerical': 0.0031692133559705717, 'mean_word_length': 1.986143967556607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844195', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2236, 'n_words': 891}