text:
import json
import requests

from ...abstract_osid.osid import objects as abc_osid_objects
from ...abstract_osid.id.primitives import Id as AbstractId
from ...abstract_osid.type.primitives import Type as AbstractType
from .. import settings
from ..primitives import Id, Type, DisplayText
from .osid_errors import NullArgument, InvalidArgument,\
    NotFound, NoAccess, IllegalState, OperationFailed,\
    Unimplemented, Unsupported, PermissionDenied
from .metadata import Metadata
from . import markers

INVALID = 0
VALID = 1

class OsidObject(abc_osid_objects.OsidObject, markers.Identifiable, markers.Extensible, markers.Browsable):
    """OsidObject is the top level interface for all OSID Objects.

    An OSID Object is an object identified by an OSID Id and may
    implements optional interfaces. OSID Objects also contain a display
    name and a description. These fields are required but may be used
    for a variety of purposes ranging from a primary name and
    description of the object to a more user friendly display of various
    attributes.

    Creation of OSID Objects and the modification of their data is
    managed through the associated OsidSession which removes the
    dependency of updating data elements upon object retrieval.  The
    OsidManager should be used to test if updates are available and
    determine what PropertyTypes are supported. The OsidManager is also
    used to create the appropriate OsidSession for object creation,
    updates and deletes.

    All OsidObjects are identified by an immutable Id. An Id is assigned
    to an object upon creation of the object and cannot be changed once
    assigned.

    An OsidObject may support one or more supplementary records which
    are expressed in the form of interfaces. Each record interface is
    identified by a Type. A record interface may extend another record
    interface where support of the parent record interface is implied.
    In this case of interface inheritance, support of the parent record
    type may be implied through has_record_type() and not explicit in
    get_record_types().

    For example, if recordB extends recordA, typeB is a child of typeA.
    If a record implements typeB, than it also implements typeA. An
    application that only knows about typeA retrieves recordA. An
    application that knows about typeB, retrieves recordB which is the
    union of methods specified in typeA and typeB. If an application
    requests typeA, it may not attempt to access methods defined in
    typeB as they may not exist until explicitly requested. The
    mechanics of this polymorphism is defined by the language binder.
    One mechanism might be the use of casting.

    In addition to the record Types, OSID Objects also have a genus
    Type. A genus Type indicates a classification or kind of the object
    where an "is a" relationship exists. The purpose of of the genus
    Type is to avoid the creation of unnecessary record types that may
    needlessly complicate an interface hierarchy or introduce
    interoperability issues. For example, an OSID object may have a
    record Type of Publication that defines methods pertinent to
    publications, such as an ISBN number. A provider may wish to
    distinguish between books and journals without having the need of
    new record interfaces. In this case, the genus Type may be one of
    Book or Journal. While this distinction can aid a search, these
    genres should be treated in such a way that do not introduce
    interoperability problems.

    Like record Types, the genus Types may also exist in an implicit
    type hierarchy. An OSID object always has at least one genus. Genus
    types should not be confused with subject tagging, which is managed
    externally to the object. Unlike record Types, an object's genus may
    be modified. However, once an object's record is created with a
    record Type, it cannot be changed.

    Methods that return values are not permitted to return nulls. If a
    value is not set, it is indicated in the Metadata of the update
    form.

    """
    _namespace = 'osid.OsidObject'
    _base_url = settings.HANDCAR + '/services/learning'
    _base_path = '/handcar/services/learning'
    _host = settings.HOST

    def __init__(self, osid_object_map, **kwargs):
        self._my_map = osid_object_map
        self._my_genus_type_map = None
        self._my_record_types = None
        self.kwargs = kwargs
        self._host = settings.HOST

    def set_host(self, mc3_host):
        """
        Hack to get copy from server to server
        :param mc3_host:
        :return:
        """
        self._host = mc3_host

    def get_host(self):
        if self._host:
            return self._host
        else:
            return None

# These two may want to be in handcar.osid.markers.browsable or
# handcar.osid.markers.extensible:

    def __iter__(self):
        for attr in dir(self):
            if not attr.startswith('__'):
                yield attr

    # def __getitem__(self, item):
    #     # can we make this work with the Handcar record extensions?
    #     # if the getattr() doesn't find the item, then search
    #     # the record extensions on Handcar...
    #     # return getattr(self, item)
    #     try:
    #         result = getattr(self, item)
    #     except:
    #         result = self.search_record_extensions(item)
    #     finally:
    #         return result
    #
    # def __setitem__(self, key, value):
    #     # also tie this to Handcar record extensions?
    #     if key in self.__dict__:
    #         self[key] = value
    #     else:
    #         self.set_record_extension(key, value)

    def _record_extension(self, key, value):
        """
        To structure a record extension property bean
        """
        record_bean = {
            'value': value,
            'displayName': self._text_bean(key),
            'description': self._text_bean(key),
            'displayLabel': self._text_bean(key),
            'associatedId': str(self.ident)
        }
        return record_bean

    def _text_bean(self, text):
        """
        To structure a text bean for MC3 with language specifications
        """
        bean = {
            'text': text,
            'scriptTypeId': '15924%3ALatin%40ISO',
            'languageTypeId': '639-2%3AEnglish%40ISO',
            'formatTypeId': 'Text+Formats%3Aplain%40okapia.net'
        }
        return bean

    def extension_url(self):
        from ..utilities import construct_url
        self_type = self.object_map['type'].lower()
        if self_type == 'objectivebank':
            extension_url = construct_url('extension_record',
                                          bank_id=self.ident)
        elif self_type == 'objective' or self_type == 'objectivenode':
            extension_url = construct_url('extension_record',
                                          bank_id=self._my_map['objectiveBankId'],
                                          obj_id=self.ident)
        elif self_type == 'activity':
            extension_url = construct_url('extension_record',
                                          bank_id=self._my_map['objectiveBankId'],
                                          act_id=self.ident)
        elif self_type == 'asset':
            extension_url = construct_url('extension_record',
                                          bank_id=self._my_map['objectiveBankId'],
                                          asset_id=self.ident)
        else:
            raise LookupError
        return extension_url

    def extensions(self):
        extension_url = self.extension_url()
        return self._get_request(extension_url)['recordProperties']

    def search_record_extensions(self, item):
        extensions = self.extensions()
        results = []
        for ext in extensions:
            if ext['displayName']['text'] == item:
                results.append(ext['value'])
        return results

    def set_record_extension(self, key, value, proxyname=None):
        # yes, hackish
        import json
        self._proxyname = proxyname
        extension_url = self.extension_url()
        current_extensions = self.extensions()
        current_keys = [e['displayName']['text'] for e in current_extensions]
        if key not in current_keys:
            current_extensions.append(self._record_extension(key, value))
        updated_extensions = {
            'associatedId': str(self.ident),
            'recordProperties': current_extensions
        }
        return self._put_request(extension_url, json.dumps(updated_extensions))
# ----------------------------------

    def _error_check(self, response):
        if response.status_code == 200:
            return
        elif response.status_code == 404:
            raise NotFound(response.text)
        elif response.status_code == 403:
            raise PermissionDenied(response.text)
        else:
            print(response.text)
            raise OperationFailed(str(response.status_code) + ' Error: ' + response.text)

    def _full_url(self, url_path):
        return 'https://{0}{1}'.format(self._host, url_path)

    # This is where the work gets done to process GET requests with handcar.
    # Here you can experiment with different libraries, etc.
    def _get_request(self, url_path):
        response = requests.get(self._full_url(url_path))
        self._error_check(response)
        return response.json()

    def _load_json(self, url_string):
        response = requests.get(url_string)
        try:
            return response.json()
        except Exception:
            raise OperationFailed()

    # This is where the work gets done to process PUT requests with handcar.
    # Here you can experiment with different libraries, etc.
    def _put_request(self, url_path, data):
        if self._proxyname is not None:
            url_path += '?proxyname=' + self._proxyname
        response = requests.put(self._full_url(url_path),
                                data=data,
                                headers={'Content-Type': 'application/json'})
        self._error_check(response)
        return response.json()

    def get_display_name(self):
        """Gets the preferred display name associated with this instance of this OSID object appropriate for display to the user.

        return: (osid.locale.DisplayText) - the display name
        compliance: mandatory - This method must be implemented.
        implementation notes: A display name is a string used for
        identifying an object in human terms. A provider may wish to
        initialize the display name based on one or more object
        attributes. In some cases, the display name may not map to a
        specific or significant object attribute but simply be used as a
        preferred display name that can be modified. A provider may also
        wish to translate the display name into a specific locale using
        the Locale service. Some OSIDs define methods for more detailed
        naming.

        """
        return DisplayText(self._my_map['displayName'])

    def get_description(self):
        """Gets the description associated with this instance of this OSID
        object.

        return: (osid.locale.DisplayText) - the description
        compliance: mandatory - This method must be implemented.
        implementation notes: A description is a string used for
        describing an object in human terms and may not have
        significance in the underlying system. A provider may wish to
        initialize the description based on one or more object
        attributes and/or treat it as an auxiliary piece of data that
        can be modified. A provider may also wish to translate the
        description into a specific locale using the Locale service.

        """
        return DisplayText(self._my_map['description'])

    def get_genus_type(self):
        """Gets the genus type of this object.

        return: (osid.type.Type) - the genus type of this object
        compliance: mandatory - This method must be implemented.

        """
        if self._my_genus_type_map is None:
            url_path = '/handcar/services/learning/types/' + self._my_map['genusTypeId']
#            url_str = self._base_url + '/types/' + self._my_map['genusTypeId']
#            self._my_genus_type_map = self._load_json(url_str)
            self._my_genus_type_map = self._get_request(url_path)
        return Type(self._my_genus_type_map)

    def is_of_genus_type(self, genus_type=None):
        """Tests if this object is of the given genus Type.

        The given genus type may be supported by the object through the
        type hierarchy.

        | arg:    ``genus_type`` (``osid.type.Type``): a genus type
        | return: (``boolean``) - true if this object is of the given genus
                Type,  false otherwise
        | raise:  ``NullArgument`` - ``genus_type`` is null
        | *compliance: mandatory - This method must be implemented.*

        """
        if genus_type is None:
            raise NullArgument()
        else:
            my_genus_type = self.get_genus_type()
            return (genus_type.get_authority() == my_genus_type.get_authority() and
                    genus_type.get_identifier_namespace() == my_genus_type.get_identifier_namespace() and
                    genus_type.get_identifier() == my_genus_type.get_identifier())

    display_name = property(get_display_name)
    description = property(get_description)
    genus_type = property(get_genus_type)

    def get_object_map(self):
        return self._my_map

    object_map = property(get_object_map)

class OsidRelationship(abc_osid_objects.OsidRelationship, OsidObject, markers.Temporal):
    """A ``Relationship`` associates two OSID objects.

    Relationships are transient. They define a date range for which they
    are in effect.

    Unlike other ``OsidObjects`` that rely on the auxiliary Journaling
    OSID to track variance over time, ``OsidRelationships`` introduce a
    different concept of time independent from journaling. For example,
    in the present, a student was registered in a course and dropped it.
    The relationship between the student and the course remains
    pertinent, independent of any journaled changes that may have
    occurred to either the student or the course.

    Once the student has dropped the course, the relationship has
    expired such that ``is_effective()`` becomes false. It can be
    inferred that during the period of the effective dates, the student
    was actively registered in the course. Here is an example:

      * T1. September 1: Student registers for course for grades
      * T2. September 10: Student drops course
      * T3. September 15: Student re-registers for course pass/fail

    The relationships are:
      T1. R1 {effective,   September 1  -> end of term,  data=grades}
      T2. R1 {ineffective, September 1  -> September 10, data=grades}
      T3. R1 {ineffective, September 1  -> September 10, data=grades}
          R2 {effective,   September 10 -> end of term,  data=p/f}

    An OSID Provider may also permit dates to be set in the future in
    which case the relationship can become automatically become
    effective at a future time and later expire. More complex
    effectiveness management can be done through other rule-based
    services.

    OSID Consumer lookups and queries of relationships need to consider
    that it may be only effective relationshps are of interest.

    """
    _namespace = 'osid.OsidRelationship'

    def has_end_reason(self):
        """Tests if a reason this relationship came to an end is known.

        return: (boolean) - ``true`` if an end reason is available,
                ``false`` otherwise
        raise:  IllegalState - ``is_effective()`` is ``true``
        *compliance: mandatory -- This method must be implemented.*

        """
        # Someday I will have real end reasons
        return False

    def get_end_reason_id(self):
        """Gets a state ``Id`` indicating why this relationship has ended.

        return: (osid.id.Id) - a state ``Id``
        raise:  IllegalState - ``has_end_reason()`` is ``false``
        *compliance: mandatory -- This method must be implemented.*

        """
        # Someday I will have real end reasons
        raise IllegalState()

    def get_end_reason(self):
        """Gets a state indicating why this relationship has ended.

        return: (osid.process.State) - a state
        raise:  IllegalState - ``has_end_reason()`` is ``false``
        raise:  OperationFailed - unable to complete request
        *compliance: mandatory -- This method must be implemented.*

        """
        # Someday I will have real end reasons
        raise IllegalState()

class OsidCatalog(abc_osid_objects.OsidCatalog, OsidObject, markers.Sourceable, markers.Federateable):
    """OsidCatalog is the top level interface for all OSID catalog-like
    objects."""
    _namespace = 'osid.OsidCatalog'

class OsidForm(abc_osid_objects.OsidForm, markers.Identifiable, markers.Suppliable):
    """The OsidForm is the vehicle used to create and update objects.

    The form is a container for data to be sent to an update or create
    method of a session. Applications should persist their own data
    until a form is successfully submitted in an update or create
    transaction.

    The form may provide some feedback as to the validity of certain
    data updates before the update transaction is issued to the
    correspodning session but a successful modification of the form is
    not a guarantee of success for the update transaction. A consumer
    may elect to perform all updates within a single update transaction
    or break up a large update intio smaller units. The tradeoff is the
    granularity of error feedback vs. the performance gain of a single
    transaction.

    OsidForms are Identifiable. The Id of the OsidForm is used to
    uniquely identify the update or create transaction and not that of
    the object being updated. Currently, it is not necessary to have
    these Ids persisted.

    As with all aspects of the OSIDs, nulls cannot be used. Methods to
    clear values are also defined in the form.

    A new OsidForm should be acquired for each transaction upon an
    OsidObject. Forms should not be reused from one object to another
    even if the supplied data is the same as the forms may encapsulate
    data specific to the object requested. Example of changing a display
    name and a color defined in a color interface extension:
      ObjectForm form = session.getObjectFormForUpdate(objectId);
      form.setDisplayName("new name");
      ColorForm recordForm = form.getFormRecord(colorRecordType);
      recordForm.setColor("green");
      session.updateObject(objectId, form);

    """
    _namespace = 'osid.OsidForm'

    def __init__(self, osid_object_map=None, **kwargs):
        import uuid
        self._validity_map = dict()
        self._identifier = str(uuid.uuid4())
        self.kwargs = kwargs
        if osid_object_map is None:
            self._my_map = dict()
            self._for_update = False
            self._init_map()
        else:
            self._my_map = osid_object_map
            self._for_update = True
        self._init_validity_map()

    def _init_map(self):
        self._my_map['journalComment'] = {
            'languageTypeId': settings.LANGUAGE_TYPE_ID,
            'scriptTypeId': settings.SCRIPT_TYPE_ID,
            'formatTypeId': settings.FORMAT_TYPE_ID,
            'text': ''
        }

    def _init_validity_map(self):
        self._validity_map['journalComment'] = VALID

    # The _is_valid_input method takes three arguments, the user input to
    # be checked and the associated metadata structure (an osid.Metadata
    # object) that will store the  validation requirements.
    def _is_valid_input(self, input, metadata, array):
        syntax = metadata.get_syntax()
        valid = True

        # First check if this is a required data element
        if metadata.is_required and not input:
            return False

        # Recursively run through all the elements of an array
        if array:
            min_elements = metadata.get_minimum_elements()
            max_elements = metadata.get_maximum_elements()
            if min_elements is not None and len(input) < min_elements:
                valid = False
            elif max_elements is not None and len(input) > max_elements:
                valid = False
            else:
                for element in input:
                    valid = (valid and
                             self._is_valid_input(element, metadata, array=False))
        # Run through all the possible syntax types
        elif syntax == 'ID':
            valid = self._is_valid_id(input)
        elif syntax == 'TYPE':
            valid = self._is_valid_type(input)
        elif syntax == 'BOOLEAN':
            valid = self._is_valid_boolean(input)
        elif syntax == 'STRING':
            valid = self._is_valid_string(input, metadata)
        else:
            raise OperationFailed('no validation function available for ' + syntax)
        return valid

    def _is_valid_id(self, input):
        if isinstance(input, AbstractId):
            return True
        else:
            return False

    def _is_valid_type(self, input):
        if isinstance(input, AbstractType):
            return True
        else:
            return False

    def _is_valid_boolean(self, input):
        if isinstance(input, bool):
            return True
        else:
            return False

    def _is_valid_string(self, input_, metadata):
        from ..utilities import is_string
        if not is_string(input_):
            return False
        if len(input_) < metadata.get_minimum_string_length():
            return False
        elif len(input_) > metadata.get_maximum_string_length():
            return False
        if (metadata.get_string_set() and
                input_ not in metadata.get_string_set()):
            return False
        else:
            return True

    # Override get_id as implemented in Identifiable for the purpose of
    # returning an Id unique to this form for submission purposed as
    # recommended in the osid documentation. This implementation
    # substitutes the intialized Python uuid4 identifier, and the
    # form namespace from the calling Osid Form thing.
    def get_id(self):
        return Id(identifier=self._identifier,
                  namespace=self._namespace,
                  authority=self._authority)

    def is_for_update(self):
        """Tests if this form is for an update operation.

        return: (boolean) - true if this form is for an update
                operation, false if for a create operation
        compliance: mandatory - This method must be implemented.

        """
        return self._for_update

    def get_default_locale(self):
        """Gets a default locale for DisplayTexts when a locale is not
        specified.

        return: (osid.locale.Locale) - the default locale
        compliance: mandatory - This method must be implemented.

        """
        raise Unimplemented()

    def get_locales(self):
        """Gets a list of locales for available DisplayText translations
        that can be performed using this form.

        return: (osid.locale.LocaleList) - a list of available locales
                or an empty list if no translation operations are
                available
        compliance: mandatory - This method must be implemented.

        """
        raise Unimplemented()

    def set_locale(self, language_type=None, script_type=None):
        """Specifies a language and script type for DisplayText fields in
        this form.

        Setting a locale to something other than the default locale may
        affect the Metadata in this form.

        If multiple locales are available for managing translations, the
        Metadata indicates the fields are unset as they may be returning
        a defeult value based on the default locale.

        arg:    languageType (osid.type.Type): the language type
        arg:    scriptType (osid.type.Type): the script type
        raise:  NullArgument - languageType or scriptType is null
        raise:  Unsupported - languageType and scriptType not available
                from get_locales()
        compliance: mandatory - This method must be implemented.

        """
        raise Unsupported()

    def get_journal_comment_metadata(self):
        """Gets the metadata for the comment corresponding to this form
        submission.

        The comment is used for describing the nature of the change to
        the corresponding object for the purposes of logging and
        auditing.

        return: (osid.Metadata) - metadata for the comment
        compliance: mandatory - This method must be implemented.

        """
        return Metadata(**settings.METADATA['journalComment'])

    def set_journal_comment(self, comment=None):
        """Sets a comment.

        arg:    comment (string): the new comment
        raise:  InvalidArgument - comment is invalid
        raise:  NoAccess - metadata.is_readonly() is true
        raise:  NullArgument - comment is null
        compliance: mandatory - This method must be implemented.

        """
        if comment is None:
            raise NullArgument()
        metadata = Metadata(**settings.METADATA['comment'])
        if metadata.is_read_only():
            raise NoAccess()
        if self._is_valid_input(comment, metadata, array=False):
            self._my_map['journalComment']['text'] = comment
        else:
            raise InvalidArgument()

    def is_valid(self):
        """Tests if ths form is in a valid state for submission.

        A form is valid if all required data has been supplied compliant
        with any constraints.

        return: (boolean) - false if there is a known error in this
                form, true otherwise
        raise:  OperationFailed - attempt to perform validation failed
        compliance: mandatory - This method must be implemented.

        """
        validity = True
        for element in self._validity_map:
            if self._validity_map[element] is not VALID:
                validity = False
        return validity

    def get_validation_messages(self):
        """Gets text messages corresponding to additional instructions to
        pass form validation.

        return: (osid.locale.DisplayText) - a list of messages
        compliance: mandatory - This method must be implemented.

        """
        pass

    def get_invalid_metadata(self):
        """Gets a list of metadata for the elements in this form which are
        not valid.

        return: (osid.Metadata) - invalid metadata
        compliance: mandatory - This method must be implemented.

        """
        pass

    default_locale = property(get_default_locale)
    locales = property(get_locales)
    journal_comment_metadata = property(get_journal_comment_metadata)
    validation_messages = property(get_validation_messages)
    invalid_metadata = property(get_invalid_metadata)
    journal_comment = property(fset=set_journal_comment)

class OsidIdentifiableForm(abc_osid_objects.OsidIdentifiableForm, OsidForm):
    """The OsidIdentifiableForm is used to create and update identifiable
    objects.

    The form is a container for data to be sent to an update or create
    method of a session.

    """

class OsidExtensibleForm(abc_osid_objects.OsidExtensibleForm, OsidForm, markers.Extensible):
    """The OsidExtensibleForm is used to create and update extensible
    objects.

    The form is a container for data to be sent to an update or create
    method of a session.

    """

    def get_required_record_types(self):
        """Gets the required record types for this form.

        The required records may change as a result of other data in
        this form and should be checked before submission.

        return: (osid.type.TypeList) - a list of required record types
        compliance: mandatory - This method must be implemented.

        """
        pass

    required_record_types = property(get_required_record_types)

class OsidBrowsableForm(abc_osid_objects.OsidBrowsableForm, OsidForm):
    """The OsidBrowsableForm is used to create and update browsable
    objects.

    The form is a container for data to be sent to an update or create
    method of a session.

    """

class OsidTemporalForm(abc_osid_objects.OsidTemporalForm, OsidForm):
    """This form is used to create and update temporals."""

    def get_start_date_metadata(self):
        """Gets the metadata for a start date.

        return: (osid.Metadata) - metadata for the date
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

    start_date_metadata = property(get_start_date_metadata)

    def set_start_date(self, date=None):
        """Sets the start date.

        arg:    date (osid.calendaring.DateTime): the new date
        raise:  InvalidArgument - ``date`` is invalid
        raise:  NoAccess - ``Metadata.isReadOnly()`` is ``true``
        raise:  NullArgument - ``date`` is ``null``
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

    def clear_start_date(self):
        """Clears the start date.

        raise:  NoAccess - ``Metadata.isRequired()`` or
                ``Metadata.isReadOnly()`` is ``true``
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

    def get_end_date_metadata(self):
        """Gets the metadata for an end date.

        return: (osid.Metadata) - metadata for the date
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

    def set_end_date(self, date=None):
        """Sets the end date.

        arg:    date (osid.calendaring.DateTime): the new date
        raise:  InvalidArgument - ``date`` is invalid
        raise:  NoAccess - ``Metadata.isReadOnly()`` is ``true``
        raise:  NullArgument - ``date`` is ``null``
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

    def clear_end_date(self):
        """Clears the end date.

        raise:  NoAccess - ``Metadata.isRequired()`` or
                ``Metadata.isReadOnly()`` is ``true``
        *compliance: mandatory -- This method must be implemented.*

        """
        pass

class OsidAggregateableForm(OsidForm):
    """This form is used to create and update assemblages."""

class OsidSourceableForm(abc_osid_objects.OsidSourceableForm, OsidForm):
    """This form is used to create and update sourceables."""

    def get_provider_metadata(self):
        """Gets the metadata for a provider.

        return: (osid.Metadata) - metadata for the provider
        compliance: mandatory - This method must be implemented.

        """
        pass

    def set_provider(self, provider_id=None):
        """Sets a provider.

        arg:    providerId (osid.id.Id): the new provider
        raise:  INVALID_ARGUMENT - providerId is invalid
        raise:  NO_ACCESS - metadata.is_read_only() is true
        raise:  NULL_ARGUMENT - providerId is null
        compliance: mandatory - This method must be implemented.

        """
        pass

    def clear_provider(self):
        """Removes the provider.

        raise:  NO_ACCESS - metadata.is_required() is true or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        pass

    def get_branding_metadata(self):
        """Gets the metadata for the asset branding.

        return: (osid.Metadata) - metadata for the asset branding.
        compliance: mandatory - This method must be implemented.

        """
        pass

    def set_branding(self, asset_ids=None):
        """Sets the branding.

        arg:    assetIds (osid.id.Id): the new assets
        raise:  INVALID_ARGUMENT - assetIds is invalid
        raise:  NO_ACCESS - metadata.is_read_only() is true
        raise:  NULL_ARGUMENT - assetIds is null
        compliance: mandatory - This method must be implemented.

        """
        pass

    def clear_branding(self):
        """Removes the branding.

        raise:  NO_ACCESS - metadata.is_required() is true or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        pass

    def get_license_metadata(self):
        """Gets the metadata for the license.

        return: (osid.Metadata) - metadata for the license
        compliance: mandatory - This method must be implemented.

        """
        pass

    def set_license(self, license=None):
        """Sets the license.

        arg:    license (string): the new license
        raise:  INVALID_ARGUMENT - license is invalid
        raise:  NO_ACCESS - metadata.is_read_only() is true
        raise:  NULL_ARGUMENT - license is null
        compliance: mandatory - This method must be implemented.

        """
        pass

    def clear_license(self):
        """Removes the license.

        raise:  NO_ACCESS - metadata.is_required() is true or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        pass

class OsidFederateableForm(abc_osid_objects.OsidFederateableForm, OsidForm):
    """This form is used to create and update federateables."""

class OsidObjectForm(abc_osid_objects.OsidObjectForm, OsidIdentifiableForm, OsidExtensibleForm, OsidBrowsableForm):
    """The OsidObjectForm is used to create and update OsidObjects.

    The form is not an OsidObject but merely a container for data to be
    sent to an update or create method of a session. A provider may or
    may not combine the OsidObject and OsidObjectForm interfaces into a
    single object.

    Generally, a set method parallels each get method of an OsidObject.
    Additionally, Metadata may be examined for each data element to
    assist in understanding particular rules concerning acceptable data.

    The form may provide some feedback as to the validity of certain
    data updates before the update transaction is issued to the
    correspodning session but a successful modification of the form is
    not a guarantee of success for the update transaction. A consumer
    may elect to perform all updates within a single update transaction
    or break up a large update intio smaller units. The tradeoff is the
    granularity of error feedback vs. the performance gain of a single
    transaction.

    As with all aspects of the OSIDs, nulls cannot be used. Methods to
    clear values are also defined in the form.

    A new OsidForm should be acquired for each transaction upon an
    OsidObject. Forms should not be reused from one object to another
    even if the supplied data is the same as the forms may encapsulate
    data specific to the object requested. Example of changing a display
    name and a color defined in a color interface extension:
      ObjectForm form = session.getObjectFormForUpdate(objectId);
      form.setDisplayName("new name");
      ColorForm recordForm = form.getFormRecord(colorRecordType);
      recordForm.setColor("green");
      session.updateObject(objectId, form);

    """
    _namespace = "osid.OsidObject"

    def _init_map(self):
        OsidForm._init_map(self)
        self._my_map['displayName'] = {
            'languageTypeId': settings.LANGUAGE_TYPE_ID,
            'scriptTypeId': settings.SCRIPT_TYPE_ID,
            'formatTypeId': settings.FORMAT_TYPE_ID,
            'text': ''
        }
        self._my_map['description'] = {
            'languageTypeId': settings.LANGUAGE_TYPE_ID,
            'scriptTypeId': settings.SCRIPT_TYPE_ID,
            'formatTypeId': settings.FORMAT_TYPE_ID,
            'text': ''
        }
        self._my_map['genusTypeId'] = settings.DEFAULT_GENUS_TYPES[self._namespace]

    def _init_validity_map(self):
        OsidForm._init_validity_map(self)
        self._validity_map['display_name'] = VALID
        self._validity_map['description'] = VALID
        self._validity_map['genus_type'] = VALID

    def get_display_name_metadata(self):
        """Gets the metadata for a display name.

        return: (osid.Metadata) - metadata for the display name
        compliance: mandatory - This method must be implemented.

        """
        return Metadata(**settings.METADATA['display_name'])

    def set_display_name(self, display_name=None):
        """Sets a display name.

        A display name is required and if not set, will be set by the
        provider.

        arg:    displayName (string): the new display name
        raise:  InvalidArgument - displayName is invalid
        raise:  NoAccess - metadata.is_readonly() is true
        raise:  NullArgument - displayName is null
        compliance: mandatory - This method must be implemented.

        """
        if display_name is None:
            raise NullArgument()
        metadata = Metadata(**settings.METADATA['display_name'])
        if metadata.is_read_only():
            raise NoAccess()
        if self._is_valid_input(display_name, metadata, array=False):
            self._my_map['displayName']['text'] = display_name
        else:
            raise InvalidArgument

    def clear_display_name(self):
        """Clears the display name.

        raise:  NoAccess - metadata.is_required() or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        metadata = Metadata(**settings.METADATA['display_name'])
        if metadata.is_read_only() or metadata.is_required():
            raise NoAccess()
        self._my_map['displayName'] = ''

    def get_description_metadata(self):
        """Gets the metadata for a description.

        return: (osid.Metadata) - metadata for the description
        compliance: mandatory - This method must be implemented.

        """
        return Metadata(**settings.METADATA['description'])

    def set_description(self, description=None):
        """Sets a description.

        arg:    description (string): the new description
        raise:  InvalidArgument - description is invalid
        raise:  NoAccess - metadata.is_readonly() is true
        raise:  NullArgument - description is null
        compliance: mandatory - This method must be implemented.

        """
        if description is None:
            raise NullArgument()
        metadata = Metadata(**settings.METADATA['description'])
        if metadata.is_read_only():
            raise NoAccess()
        if self._is_valid_input(description, metadata, array=False):
            self._my_map['description']['text'] = description
        else:
            raise InvalidArgument

    def clear_description(self):
        """Clears the description.

        raise:  NoAccess - metadata.is_required() or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        metadata = Metadata(**settings.METADATA['description'])
        if metadata.is_read_only() or metadata.is_required():
            raise NoAccess()
        self._my_map['description'] = ''

    def get_genus_type_metadata(self):
        """Gets the metadata for a genus type.

        return: (osid.Metadata) - metadata for the genus
        compliance: mandatory - This method must be implemented.

        """
        return Metadata(**settings.METADATA['genus_type'])

    def set_genus_type(self, genus_type=None):
        """Sets a genus.

        A genus cannot be cleared because all objects have at minimum a
        root genus.

        arg:    genusType (osid.type.Type): the new genus
        raise:  InvalidArgument - genusType is invalid
        raise:  NoAccess - metadata.is_readonly() is true
        raise:  NullArgument - genusType is null
        compliance: mandatory - This method must be implemented.

        """
        if genus_type is None:
            raise NullArgument()
        metadata = Metadata(**settings.METADATA['genus_type'])
        metadata_id = Metadata(**settings.METADATA['genus_type_id'])
        if metadata.is_read_only():
            raise NoAccess()
        if self._is_valid_input(genus_type, metadata, array=False):
            self._my_map['genusTypeId'] = str(genus_type)
            # REALLY?  This assumes that all genus_type arguments
            # will be Types that have come from Hancar.  Perhaps?
        elif self._is_valid_input(genus_type, metadata_id, array=False):
            self._my_map['genusTypeId'] = str(genus_type)
        else:
            raise InvalidArgument

    def clear_genus_type(self):
        """Clears the genus type.

        raise:  NoAccess - metadata.is_required() or
                metadata.is_read_only() is true
        compliance: mandatory - This method must be implemented.

        """
        metadata = Metadata(**settings.METADATA['genus_type'])
        if metadata.is_read_only() or metadata.is_required():
            raise NoAccess()
        # This may never get called, as
        # is_required will likely always
        # be True for genus types.
        self._my_map['genus_type'] = ''

    display_name_metadata = property(get_display_name_metadata)
    description_metadata = property(get_description_metadata)
    genus_type_metadata = property(get_genus_type_metadata)
    display_name = property(fset=set_display_name, fdel=clear_display_name)
    description = property(fset=set_description, fdel=clear_description)
    genus_type = property(fset=set_genus_type, fdel=clear_genus_type)

class OsidRelationshipForm(abc_osid_objects.OsidRelationshipForm, OsidObjectForm, OsidTemporalForm):
    """This form is used to create and update relationshps."""

class OsidCatalogForm(abc_osid_objects.OsidCatalogForm, OsidObjectForm, OsidSourceableForm, OsidFederateableForm):
    """This form is used to create and update catalogs."""

class OsidList(abc_osid_objects.OsidList):
    """OsidList is the top-level interface for all OSID lists.

    An OSID list provides sequential access, one at a time or many at a
    time, access to a set of elements. These elements are not required
    to be OsidObjects but generally are. The element retrieval methods
    are defined in the sub-interface of OsidList where the appropriate
    return type is defined.

    Osid lists are a once pass through iteration of elements. The size
    of the object set and the means in which the element set is
    generated or stored is not known. Assumptions based on the length of
    the element set by copying the entire contents of the list into a
    fixed buffer should be done with caution a awareness that an
    implementation may return a number of elements ranging from zero to
    infinity.

    Lists are returned by methods when multiple return values are
    possible. There is no guarantee that successive calls to the same
    method will return the same set of elements in a list. Unless an
    order is specified in an interface definition, the order of the
    elements is not known.

    """

    def __init__(self, iter_object=[], count=None):
        if count is not None:
            self._count = count
        elif isinstance(iter_object, dict) or isinstance(iter_object, list):
            self._count = len(iter_object)
        self._iter_object = iter(iter_object)

    def __iter__(self):
        return self

    def __len__(self):
        return self.available()

    def next(self):
        try:
            next_object = next(self._iter_object)
        except StopIteration:
            raise
        except Exception:  # Need to specify exceptions here!
            raise OperationFailed()
        if self._count is not None:
            self._count -= 1
        return next_object

    __next__ = next

    def has_next(self):
        """Tests if there are more elements in this list.

        return: (boolean) - true if more elements are available in this
                list, false if the end of the list has been reached
        compliance: mandatory - This method must be implemented.
        implementation notes: Any errors that may result from accesing
        the underlying set of elements are to be deferred until the
        consumer attempts retrieval in which case the provider must
        return true for this method.

        """
        if self._count is not None:
            # If count is available, use it
            return bool(self._count)
        else:
            # otherwise we have no idea
            return True

    def available(self):
        """Gets the number of elements available for retrieval.
        The number returned by this method may be less than or equal to
        the total number of elements in this list. To determine if the
        end of the list has been reached, the method has_next() should
        be used. This method conveys what is known about the number of
        remaining elements at a point in time and can be used to
        determine a minimum size of the remaining elements, if known. A
        valid return is zero even if has_next() is true.

        This method does not imply asynchronous usage. All OSID methods
        may block.
        return: (cardinal) - the number of elements available for
                retrieval
        compliance: mandatory - This method must be implemented.
        implementation notes: Any errors that may result from accesing
        the underlying set of elements are to be deferred until the
        consumer attempts retrieval in which case the provider must
        return a positive integer for this method so the consumer can
        continue execution to receive the error. In all other
        circumstances, the provider must not return a number greater
        than the number of elements known since this number will be fed
        as a parameter to the bulk retrieval method.

        """
        if self._count is not None:
            # If count is available, use it
            return self._count
        else:
            # We really have no idea.
            # Don't know what do do here, but for this
            # impl, which should only be constructed with
            # python lists, self._count should never be none.
            return 0

    def skip(self, n=None):
        """Skip the specified number of elements in the list.
        If the number skipped is greater than the number of elements in
        the list, hasNext() becomes false and available() returns zero
        as there are no more elements to retrieve.
        arg:    n (cardinal): the number of elements to skip
        compliance: mandatory - This method must be implemented.

        """
        while n > 0:
            try:
                next(self)
            except StopIteration:
                break
            n -= 1


text:
Scopes

      <mat-form-field>
        <mat-icon matPrefix="">search</mat-icon>
        <input type="text" matInput placeholder="Search" (input)="onSearch($event)">
      </mat-form-field>

Scope is a mechanism in OAuth 2.0 to limit an application's access to a user's account. The access token issued to the application will be limited to the scopes granted.

An application can request one or more scopes, this information is then presented to the user in the consent screen.

    <ngx-datatable class="material"
                   [columnMode]="'flex'"
                   [headerHeight]="40"
                   [footerHeight]="40"
                   [rowHeight]="50"
                   [rows]='scopes'
                   [externalPaging]="true"
                   [count]="page.totalElements"
                   [offset]="page.pageNumber"
                   [limit]="page.size"
                   (page)='setPage($event)'
                   [sorts]="[{prop: 'system', dir: 'desc'}, {prop: 'key', dir: 'asc'}]">
      <ngx-datatable-column name="Scopes" [flexGrow]="4" [cellClass]="'scope-name-cell'">
        <ng-template let-row="row" ngx-datatable-cell-template>

              <mat-icon>playlist_add_check</mat-icon>

{{row.key}}

                <mat-chip-list *ngIf="row.system"><mat-chip>system</mat-chip></mat-chip-list>

              {{row.description}}

        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Discovery" [flexGrow]="1">
        <ng-template let-row="row" ngx-datatable-cell-template>

            <mat-slide-toggle
              (change)="enableScopeDiscovery(row.id, $event)"
              [checked]="row.discovery"
              [disabled]="row.system || !canEdit">
            </mat-slide-toggle>

        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Actions" [flexGrow]="1" *hasAnyPermission="['domain_scope_read', 'domain_scope_delete']">
        <ng-template let-row="row" ngx-datatable-cell-template>

            <mat-icon>settings</mat-icon>
            <button *ngIf="!row.system && canDelete" mat-icon-button (click)="delete(row.id, $event)"><mat-icon>delete</mat-icon></button>

        </ng-template>
      </ngx-datatable-column>
    </ngx-datatable>

  <app-emptystate *ngIf="isEmpty"
                  [message]="'Scopes will appear here'"
                  [subMessage]="'No data to display'"
                  [icon]="'donut_large'"></app-emptystate>

      <mat-icon>add</mat-icon>

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SolutionRenamer.Win.Logic.Events;
using SolutionRenamer.Win.Logic.FileSystem;
using SolutionRenamer.Win.Logic.Logging;

namespace SolutionRenamer.Win.Logic
{
    public class Renamer
    {
        private readonly ILogger _logger;
        private IFileSystem _fileSystem;
        private RenamerRule _ruleSet;

        public Renamer(ILogger logger, IFileSystem fileSystem, RenamerRule ruleSet)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            _logger = logger;
            _fileSystem = fileSystem;
            _ruleSet = ruleSet;
        }

        public event EventHandler<RenamesSetEventArgs> RenamesSet;

        public event EventHandler<TargetFolderAddedEventArgs> TargetFolderAdded;

        public event EventHandler<SolutionRenamedEventArgs> SolutionRenamed;

        public string NewName { get; private set; }

        public bool Completed { get; private set; }

        public bool Ready
        {
            get
            {
                return !string.IsNullOrEmpty(OldName) && !string.IsNullOrEmpty(NewName) && Root != null && !string.IsNullOrEmpty(TargetFolder);
            }
        }

        public string OldName { get; private set; }

        public RenamerInfo Root { get; private set; }

        public string TargetFolder
        {
            get
            {
                return Root?.Path;
            }
        }

        public static string ValidateSolutionName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return "Null or whitespace names are not allowed.";
            }

            if (new Regex(@"^\d+").IsMatch(name))
            {
                return "Names cannot start with a number.";
            }

            if (new Regex(@"\s").IsMatch(name))
            {
                return "Spaces are not allowed.";
            }

            if (new Regex(@"(^\.)|(\.$)|(\.{2,})").IsMatch(name))
            {
                return "Dots cannot be at the beginning, end, or adjacent to each other.";
            }

            if (new Regex(@"[^a-zA-Z0-9_\.]").IsMatch(name))
            {
                return "Only a-Z, 0-9, _ and . are allowed in the name.";
            }

            var splitNames = name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries)
                .ToList();

            foreach (var part in splitNames)
            {
                if (Config.ReservedWords.Contains(part))
                {
                    return "Reserved words in c# cannot be used as a solution name.";
                }
            }

            return null;
        }

        public void DoRename(IProgress<RenamerProgress> progressReport)
        {
            if (Completed)
            {
                throw new InvalidOperationException("Cannot do a rename on the same process. Select the target folder again.");
            }

            progressReport.Report(new RenamerProgress("=== Starting rename process ===", 0, _logger));
            progressReport.Report(new RenamerProgress("Backing up solution folder to zip", 0.1, _logger));
            var backupResult = _fileSystem.Zip(Root, OldName);
            if (backupResult.IsSuccess)
            {
                progressReport.Report(new RenamerProgress(backupResult.Message, 0.3, _logger));
            }
            else
            {
                progressReport.Report(new RenamerProgress(backupResult.Message, 1, _logger, true));
                Completed = false;
                return;
            }

            Task.Delay(10).Wait();
            _fileSystem.Rename(Root, OldName, NewName, progressReport, _logger);

            // then call rename on the renamerinfo, passing in the naming strategy (or factory)
            progressReport.Report(new RenamerProgress("=== Finished rename process ===", 1, _logger));
            Completed = true;

            if (SolutionRenamed != null)
            {
                SolutionRenamed(this, new SolutionRenamedEventArgs());
            }
        }

        public void SetRename(string oldName, string newName)
        {
            var fromValidationMessage = ValidateSolutionName(oldName);
            var toValidationMessage = ValidateSolutionName(newName);

            if (!string.IsNullOrWhiteSpace(oldName) && !string.IsNullOrWhiteSpace(fromValidationMessage))
            {
                _logger.WriteWarning($"'From' solution name is invalid: {fromValidationMessage}");
            }
            else if (!string.IsNullOrWhiteSpace(newName) && !string.IsNullOrWhiteSpace(toValidationMessage))
            {
                _logger.WriteWarning($"'To' solution name is invalid: {toValidationMessage}");
            }
            else if (!string.IsNullOrWhiteSpace(oldName) && !string.IsNullOrWhiteSpace(newName))
            {
                _logger.WriteInfo($"solution names are valid.");
            }

            OldName = oldName;
            NewName = newName;

            if (RenamesSet != null)
            {
                RenamesSet(this, new RenamesSetEventArgs(string.IsNullOrWhiteSpace(fromValidationMessage), string.IsNullOrWhiteSpace(toValidationMessage)));
            }
        }

        public void SetTargetFolder(string folder)
        {
            if (string.IsNullOrWhiteSpace(folder))
            {
                _logger.WriteWarning($"Invalid folder selected. Folder: {folder ?? "[empty]"}");
                return;
            }

            if (!_fileSystem.IsValidFolder(folder))
            {
                _logger.WriteWarning($"'{folder}' is not a valid folder.");
                return;
            }

            Root = _fileSystem.GetFiles(folder, _ruleSet);
            _logger.WriteInfo($"'{folder}' folder selected.");
            Completed = false;

            if (!_fileSystem.IsSolutionFolder(Root))
            {
                _logger.WriteWarning("WARNING: no solution or more than one solution was found in this folder.");
            }

            if (TargetFolderAdded != null)
            {
                TargetFolderAdded(this, new TargetFolderAddedEventArgs(folder, _fileSystem.IsSolutionFolder(Root)));
            }
        }

        public bool CleanFolders(string folderName)
        {
            var success = true;
            if (Root == null)
            {
                _logger.WriteWarning("Target folder is not set!");
                success = false;
            }
            else
            {
                // We need to reset the target folder first before the clean can commence
                SetTargetFolder(Root.Path);
                var results = new List<RenameResult>();
                _fileSystem.CleanFolders(Root, folderName, results);
                foreach (var result in results)
                {
                    if (result.IsSuccess)
                    {
                        _logger.WriteInfo(result.Message);
                    }
                    else
                    {
                        _logger.WriteWarning(result.Message);
                    }
                }

                if (results.Any(r => !r.IsSuccess))
                {
                    _logger.WriteWarning("Clean was not sucecssful.");
                    success = false;
                }
            }

            return success;
        }

        public bool CleanDatabaseFiles(string folderName)
        {
            var success = true;
            if (Root == null)
            {
                _logger.WriteWarning("Target folder is not set!");
                success = false;
            }
            else
            {
                // We need to reset the target folder first before the clean can commence
                SetTargetFolder(Root.Path);
                var results = new List<RenameResult>();
                _fileSystem.DeleteFiles(Root, folderName, "*.ldf", results);
                _fileSystem.DeleteFiles(Root, folderName, "*.mdf", results);
                foreach (var result in results)
                {
                    if (result.IsSuccess)
                    {
                        _logger.WriteInfo(result.Message);
                    }
                    else
                    {
                        _logger.WriteWarning(result.Message);
                    }
                }

                if (results.Any(r => !r.IsSuccess))
                {
                    _logger.WriteWarning("Clean was not sucecssful.");
                    success = false;
                }
            }

            return success;
        }
    }
}


text:
--@drop_security_questions_tables.sql

@create_security_questions_tables.sql

@delete-web-links.sql

@insert-web-links.sql

--@drop_password_expiration_queue.sql

@create_password_expiration_queue.sql

@delete-notification-email-details.sql

@insert-notification-email-details.sql


text:
#ifndef _DG_VECTOR_TRAITS_
#define _DG_VECTOR_TRAITS_

#include <type_traits>
#include <thrust/memory.h>
#include "scalar_categories.h"
#include "vector_categories.h"
#include "matrix_categories.h"
#include "execution_policy.h"

namespace dg{
///@addtogroup dispatch
///@{

/*! @brief The vector traits

Specialize this struct if you want to enable your own vector/container class for the use in blas1 functions.
The contained types are
- <tt> value_type </tt> the elementary data type of the contained data
- <tt> tensor_category </tt> the layout of the data (derives from \c AnyMatrixTag)
- <tt> execution_policy </tt> for \c SharedVectorTag the execution policy
    (derives from \c AnyPolicyTag)
    indicates the type of hardware memory is physically
allocated on in a vector class and therefore indicates the
possible parallelization and optimization strategies.
\see \ref dispatch
*/
template< class Vector, class Enable=void>
struct TensorTraits
{
    using value_type = void;
    using tensor_category = NotATensorTag;
    using execution_policy = NoPolicyTag;
};

template<class Vector>
using get_value_type = typename TensorTraits<std::decay_t<Vector>>::value_type;
template<class Vector>
using get_tensor_category = typename TensorTraits< std::decay_t<Vector>>::tensor_category;
template<class Vector>
using get_execution_policy = typename TensorTraits<std::decay_t<Vector>>::execution_policy;

///@}

///@cond
////////////get element, pointer and data
template<class T> //T = SharedVector
using get_pointer_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
    const get_value_type<T>*, get_value_type<T>* >;

template<class T> //T = RecursiveVector
using get_element_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
    const typename std::decay_t<T>::value_type&, typename std::decay_t<T>::value_type& >;
template<class T> //T = std::map
using get_mapped_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
    const typename std::decay_t<T>::mapped_type&, typename std::decay_t<T>::mapped_type& >;

template<class T>//T = MPIVector
using get_data_type = std::conditional_t< std::is_const< std::remove_reference_t<T> >::value,
    const typename std::decay_t<T>::container_type&, typename std::decay_t<T>::container_type& >;

template<class T>
inline get_element_type<T> do_get_vector_element( T&& v, unsigned i, RecursiveVectorTag)//-> decltype(v[i]){
{
    return v[i];
}
template<class T, class Key>
inline get_mapped_type<T> do_get_vector_element( T&& v, const Key& key, StdMapTag)//-> decltype(v[i]){
{
    return v.at(key);
}
template<class T, class Key>
inline T&& do_get_vector_element( T&& v, const Key& i, AnyScalarTag){
    return std::forward<T>(v);
}

template<class T>
inline get_data_type<T> do_get_data( T&& v, MPIVectorTag)//-> decltype(v.data())
{
    return v.data();
}
template<class T>
inline T&& do_get_data( T&& v, AnyScalarTag){
    return std::forward<T>(v);
}

template<class T>
inline get_pointer_type<T> do_get_pointer_or_reference( T&& v, AnyVectorTag)// -> decltype(thrust::raw_pointer_cast(v.data())) //nvcc-7.5 does not like decltype in this connection
{
    return thrust::raw_pointer_cast(v.data());
}
template<class T>
inline T&& do_get_pointer_or_reference( T&& v, AnyScalarTag){
    return std::forward<T>(v);
}

///@endcond

//template<class T>
//inline std::conditional_t<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T&&, get_element_type<T> > get_vector_element( T&& v, unsigned i )// -> decltype( do_get_vector_element( std::forward<T>(v), i, get_tensor_category<T>()) )
//{
//    return do_get_vector_element( std::forward<T>(v), i, get_tensor_category<T>());
//}
//
//template<class T>
//inline std::conditional_t<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T, get_data_type<T> > get_data( T&& v)//-> decltype(do_get_data( std::forward<T>(v), get_tensor_category<T>() ))
//{
//    return do_get_data( std::forward<T>(v), get_tensor_category<T>());
//}
//
//template<class T>
//std::conditional<std::is_base_of<AnyScalarTag, get_tensor_category<T>>::value, T, get_pointer_type<T> > get_pointer_or_reference( T&& v )// -> decltype( do_get_pointer_or_reference( std::forward<T>(v), get_tensor_category<T>()))
//{
//    return do_get_pointer_or_reference( std::forward<T>(v), get_tensor_category<T>());
//}

}//namespace dg

#endif //_DG_VECTOR_TRAITS_


text:
# PostCSS Nested [![Build Status][ci-img]][ci]

[PostCSS] plugin to unwrap nested rules like how Sass does it.

```css
.phone {
    &_title {
        width: 500px;
        @media (max-width: 500px) {
            width: auto;
        }
        body.is_dark & {
            color: white;
        }
    }
    img {
        display: block;
    }
}
```

will be processed to:

```css
.phone_title {
    width: 500px;
}
@media (max-width: 500px) {
    .phone_title {
        width: auto;
    }
}
body.is_dark .phone_title {
    color: white;
}
.phone img {
    display: block;
}
```

Use [postcss-current-selector] **after** this plugin if you want to use current selector in properties or variables values.

Use [postcss-nested-ancestors] **before** this plugin if you want to reference any ancestor element directly in your selectors with `^&`.

See also [postcss-nesting], which implements [Tab Atkin's proposed syntax](https://tabatkins.github.io/specs/css-nesting/) (requires the `&` and introduces `@nest`).

There is also [postcss-nested-props] for nested properties like `font-size`.

[postcss-current-selector]: https://github.com/komlev/postcss-current-selector
[postcss-nested-ancestors]: https://github.com/toomuchdesign/postcss-nested-ancestors
[postcss-nested-props]:     https://github.com/jedmao/postcss-nested-props
[postcss-nesting]:          https://github.com/jonathantneal/postcss-nesting
[PostCSS]:                  https://github.com/postcss/postcss
[ci-img]:                   https://travis-ci.org/postcss/postcss-nested.svg
[ci]:                       https://travis-ci.org/postcss/postcss-nested

## Usage

```js
postcss([ require('postcss-nested') ])
```

See [PostCSS] docs for examples for your environment.

## Options

### `bubble`

By default, plugin will bubble only `@media` and `@supports` at-rules.
You can add your custom at-rules to this list by `bubble` option:

```js
postcss([ require('postcss-nested')({ bubble: ['phone'] }) ])
```

```css
/* input */
a {
  color: white;
  @phone {
    color: black;
  }
}
/* output */
a {
  color: white;
}
@phone {
  a {
    color: black;
  }
}
```

### `unwrap`

By default, plugin will unwrap only `@font-face`, `@keyframes` and `@document`
at-rules. You can add your custom at-rules to this list by `unwrap` option:

```js
postcss([ require('postcss-nested')({ unwrap: ['phone'] }) ])
```

```css
/* input */
a {
  color: white;
  @phone {
    color: black;
  }
}
/* output */
a {
  color: white;
}
@phone {
  color: black;
}
```

### `preserveEmpty`

By default, plugin will strip out any empty selector generated by intermediate
nesting levels. You can set `preserveEmpty` to `true` to preserve them.

```css
.a {
    .b {
        color: black;
    }
}
```

Will be compiled to:

```css
.a { }
.a .b {
    color: black;
}
```

This is especially useful if you want to export the empty classes with `postcss-modules`.


text:
[assembly:
    System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
[assembly:
    System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
        MessageId = "Mef")]


text:
#include <ntddk.h>
#include <procgrp.h>
#include <stdarg.h>
#include <xen.h>

#include "evtchn_fifo.h"
#include "shared_info.h"
#include "fdo.h"
#include "dbg_print.h"
#include "assert.h"
#include "util.h"

typedef struct _XENBUS_EVTCHN_FIFO_CONTEXT {
    PXENBUS_FDO                     Fdo;
    KSPIN_LOCK                      Lock;
    LONG                            References;
    PMDL                            ControlBlockMdl[HVM_MAX_VCPUS];
    PMDL                            *EventPageMdl;
    ULONG                           EventPageCount;
    ULONG                           Head[HVM_MAX_VCPUS][EVTCHN_FIFO_MAX_QUEUES];
} XENBUS_EVTCHN_FIFO_CONTEXT, *PXENBUS_EVTCHN_FIFO_CONTEXT;

#define EVENT_WORDS_PER_PAGE    (PAGE_SIZE / sizeof (event_word_t))

#define XENBUS_EVTCHN_FIFO_TAG  'OFIF'

static FORCEINLINE PVOID
__EvtchnFifoAllocate(
    IN  ULONG   Length
    )
{
    return __AllocatePoolWithTag(NonPagedPool, Length, XENBUS_EVTCHN_FIFO_TAG);
}

static FORCEINLINE VOID
__EvtchnFifoFree(
    IN  PVOID   Buffer
    )
{
    ExFreePoolWithTag(Buffer, XENBUS_EVTCHN_FIFO_TAG);
}

static event_word_t *
EvtchnFifoEventWord(
    IN  PXENBUS_EVTCHN_FIFO_CONTEXT Context,
    IN  ULONG                       Port
    )
{
    ULONG                           Index;
    PMDL                            Mdl;
    event_word_t                    *EventWord;

    Index = Port / EVENT_WORDS_PER_PAGE;
    ASSERT3U(Index, <, Context->EventPageCount);

    Mdl = Context->EventPageMdl[Index];

    EventWord = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
    ASSERT(EventWord != NULL);

    ASSERT3U(Port, >=, Index * EVENT_WORDS_PER_PAGE);
    Port -= Index * EVENT_WORDS_PER_PAGE;

    return &EventWord[Port];
}

static FORCEINLINE BOOLEAN
__EvtchnFifoTestFlag(
    IN  event_word_t    *EventWord,
    IN  ULONG           Flag
    )
{
    KeMemoryBarrier();
    return (*EventWord & (1 << Flag)) ? TRUE : FALSE;
}

static FORCEINLINE BOOLEAN
__EvtchnFifoTestAndSetFlag(
    IN  event_word_t    *EventWord,
    IN  ULONG           Flag
    )
{
    return (InterlockedBitTestAndSet((LONG *)EventWord, Flag) != 0) ? TRUE : FALSE;
}

static FORCEINLINE BOOLEAN
__EvtchnFifoTestAndClearFlag(
    IN  event_word_t    *EventWord,
    IN  ULONG           Flag
    )
{
    return (InterlockedBitTestAndReset((LONG *)EventWord, Flag) != 0) ? TRUE : FALSE;
}

static FORCEINLINE VOID
__EvtchnFifoSetFlag(
    IN  event_word_t    *EventWord,
    IN  ULONG           Flag
    )
{
    (VOID) InterlockedBitTestAndSet((LONG *)EventWord, Flag);
}

static FORCEINLINE VOID
__EvtchnFifoClearFlag(
    IN  event_word_t    *EventWord,
    IN  ULONG           Flag
    )
{
    (VOID) InterlockedBitTestAndReset((LONG *)EventWord, Flag);
}

static FORCEINLINE ULONG
__EvtchnFifoUnlink(
    IN  event_word_t    *EventWord
    )
{
    LONG                Old;
    LONG                New;

    do {
        Old = *EventWord;

        // Clear linked bit and link value
        New = Old & ~((1 << EVTCHN_FIFO_LINKED) | EVTCHN_FIFO_LINK_MASK);
    } while (InterlockedCompareExchange((LONG *)EventWord, New, Old) != Old);

    return Old & EVTCHN_FIFO_LINK_MASK;
}

static NTSTATUS
EvtchnFifoExpand(
    IN  PXENBUS_EVTCHN_FIFO_CONTEXT Context,
    IN  ULONG                       Port
    )
{
    LONG                            Index;
    ULONG                           EventPageCount;
    PMDL                            *EventPageMdl;
    PMDL                            Mdl;
    ULONG                           Start;
    ULONG                           End;
    NTSTATUS                        status;

    Index = Port / EVENT_WORDS_PER_PAGE;
    ASSERT3U(Index, >=, (LONG)Context->EventPageCount);

    EventPageCount = Index + 1;
    EventPageMdl = __EvtchnFifoAllocate(sizeof (PMDL) * EventPageCount);

    status = STATUS_NO_MEMORY;
    if (EventPageMdl == NULL)
        goto fail1;

    for (Index = 0; Index < (LONG)Context->EventPageCount; Index++)
        EventPageMdl[Index] = Context->EventPageMdl[Index];

    Index = Context->EventPageCount;
    while (Index < (LONG)EventPageCount) {
        event_word_t        *EventWord;
        PFN_NUMBER          Pfn;
        PHYSICAL_ADDRESS    Address;

        Mdl = __AllocatePage();

        status = STATUS_NO_MEMORY;
        if (Mdl == NULL)
            goto fail2;

        EventWord = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
        ASSERT(EventWord != NULL);

        for (Port = 0; Port < EVENT_WORDS_PER_PAGE; Port++)
            __EvtchnFifoSetFlag(&EventWord[Port], EVTCHN_FIFO_MASKED);

        Pfn = MmGetMdlPfnArray(Mdl)[0];

        status = EventChannelExpandArray(Pfn);
        if (!NT_SUCCESS(status))
            goto fail3;

        Address.QuadPart = (ULONGLONG)Pfn << PAGE_SHIFT;

        LogPrintf(LOG_LEVEL_INFO,
                  "EVTCHN_FIFO: EVENTARRAY[%u] @ %08x.%08x\n",
                  Index,
                  Address.HighPart,
                  Address.LowPart);

        EventPageMdl[Index++] = Mdl;
    }

    Start = Context->EventPageCount * EVENT_WORDS_PER_PAGE;
    End = (EventPageCount * EVENT_WORDS_PER_PAGE) - 1;

    Info("added ports [%08x - %08x]\n", Start, End);

    if (Context->EventPageMdl != NULL)
        __EvtchnFifoFree(Context->EventPageMdl);

    Context->EventPageMdl = EventPageMdl;
    Context->EventPageCount = EventPageCount;

    return STATUS_SUCCESS;

fail3:
    Error("fail3\n");

    __FreePage(Mdl);

fail2:
    Error("fail2\n");

    while (--Index >= (LONG)Context->EventPageCount) {
        Mdl = EventPageMdl[Index];

        __FreePage(Mdl);
    }

    __EvtchnFifoFree(EventPageMdl);

fail1:
    Error("fail1 (%08x)\n", status);

    return status;
}

static VOID
EvtchnFifoContract(
    IN  PXENBUS_EVTCHN_FIFO_CONTEXT Context
    )
{
    LONG                            Index;

    Index = Context->EventPageCount;
    while (--Index >= 0) {
        PMDL    Mdl;

        Mdl = Context->EventPageMdl[Index];

        __FreePage(Mdl);
    }

    __EvtchnFifoFree(Context->EventPageMdl);

    Context->EventPageMdl = NULL;
    Context->EventPageCount = 0;
}

static BOOLEAN
EvtchnFifoIsProcessorEnabled(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Index
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    unsigned int                    vcpu_id = SystemVirtualCpuIndex(Index);

    return (Context->ControlBlockMdl[vcpu_id] != NULL) ? TRUE : FALSE;
}

static BOOLEAN
EvtchnFifoPollPriority(
    IN  PXENBUS_EVTCHN_FIFO_CONTEXT Context,
    IN  unsigned int                vcpu_id,
    IN  ULONG                       Priority,
    IN  PULONG                      Ready,
    IN  XENBUS_EVTCHN_ABI_EVENT     Event,
    IN  PVOID                       Argument
    )
{
    ULONG                           Head;
    ULONG                           Port;
    event_word_t                    *EventWord;
    BOOLEAN                         DoneSomething;

    Head = Context->Head[vcpu_id][Priority];

    if (Head == 0) {
        PMDL                        Mdl;
        evtchn_fifo_control_block_t *ControlBlock;

        Mdl = Context->ControlBlockMdl[vcpu_id];

        ControlBlock = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
        ASSERT(ControlBlock != NULL);

        KeMemoryBarrier();
        Head = ControlBlock->head[Priority];
    }

    Port = Head;
    EventWord = EvtchnFifoEventWord(Context, Port);

    Head = __EvtchnFifoUnlink(EventWord);

    if (Head == 0)
        *Ready &= ~(1ull << Priority);

    DoneSomething = FALSE;

    if (!__EvtchnFifoTestFlag(EventWord, EVTCHN_FIFO_MASKED) &&
        __EvtchnFifoTestFlag(EventWord, EVTCHN_FIFO_PENDING))
        DoneSomething = Event(Argument, Port);

    Context->Head[vcpu_id][Priority] = Head;

    return DoneSomething;
}

static BOOLEAN
EvtchnFifoPoll(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Index,
    IN  XENBUS_EVTCHN_ABI_EVENT     Event,
    IN  PVOID                       Argument
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    unsigned int                    vcpu_id = SystemVirtualCpuIndex(Index);
    PMDL                            Mdl;
    evtchn_fifo_control_block_t     *ControlBlock;
    ULONG                           Ready;
    ULONG                           Priority;
    BOOLEAN                         DoneSomething;

    Mdl = Context->ControlBlockMdl[vcpu_id];

    DoneSomething = FALSE;
    if (Mdl == NULL)
        goto done;

    ControlBlock = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
    ASSERT(ControlBlock != NULL);

    Ready = InterlockedExchange((LONG *)&ControlBlock->ready, 0);

    while (_BitScanReverse(&Priority, Ready)) {
        DoneSomething |= EvtchnFifoPollPriority(Context,
                                                vcpu_id,
                                                Priority,
                                                &Ready,
                                                Event,
                                                Argument);
        Ready |= InterlockedExchange((LONG *)&ControlBlock->ready, 0);
    }

done:
    return DoneSomething;
}

static NTSTATUS
EvtchnFifoPortEnable(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Port
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    KIRQL                           Irql;
    NTSTATUS                        status;

    KeAcquireSpinLock(&Context->Lock, &Irql);

    if (Port / EVENT_WORDS_PER_PAGE >= Context->EventPageCount) {
        status = EvtchnFifoExpand(Context, Port);

        if (!NT_SUCCESS(status))
            goto fail1;
    }

    KeReleaseSpinLock(&Context->Lock, Irql);

    return STATUS_SUCCESS;

fail1:
    Error("fail1 (%08x)\n", status);

    KeReleaseSpinLock(&Context->Lock, Irql);

    return status;
}

static VOID
EvtchnFifoPortAck(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Port
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    event_word_t                    *EventWord;

    EventWord = EvtchnFifoEventWord(Context, Port);
    __EvtchnFifoClearFlag(EventWord, EVTCHN_FIFO_PENDING);
}

static VOID
EvtchnFifoPortMask(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Port
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    event_word_t                    *EventWord;

    EventWord = EvtchnFifoEventWord(Context, Port);
    __EvtchnFifoSetFlag(EventWord, EVTCHN_FIFO_MASKED);
}

static BOOLEAN
EvtchnFifoPortUnmask(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Port
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    event_word_t                    *EventWord;
    LONG                            Old;
    LONG                            New;

    EventWord = EvtchnFifoEventWord(Context, Port);

    // Clear masked bit, spinning if busy
    do {
        Old = *EventWord & ~(1 << EVTCHN_FIFO_BUSY);
        New = Old & ~(1 << EVTCHN_FIFO_MASKED);
    } while (InterlockedCompareExchange((LONG *)EventWord, New, Old) != Old);

    // If we cleared the mask then check whether something is pending
    return __EvtchnFifoTestFlag(EventWord, EVTCHN_FIFO_PENDING);
}

static VOID
EvtchnFifoPortDisable(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context,
    IN  ULONG                       Port
    )
{
    EvtchnFifoPortMask(_Context, Port);
}

static NTSTATUS
EvtchnFifoAcquire(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    KIRQL                           Irql;
    LONG                            Index;
    PMDL                            Mdl;
    NTSTATUS                        status;

    KeAcquireSpinLock(&Context->Lock, &Irql);

    if (Context->References++ != 0)
        goto done;

    Trace("====>\n");

    Index = 0;
    while (Index < (LONG)KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS)) {
        unsigned int        vcpu_id;
        PFN_NUMBER          Pfn;
        PHYSICAL_ADDRESS    Address;

        Mdl = __AllocatePage();

        status = STATUS_NO_MEMORY;
        if (Mdl == NULL)
            goto fail1;

        vcpu_id = SystemVirtualCpuIndex(Index);
        Pfn = MmGetMdlPfnArray(Mdl)[0];

        status = EventChannelInitControl(Pfn, vcpu_id);
        if (!NT_SUCCESS(status))
            goto fail2;

        Address.QuadPart = (ULONGLONG)Pfn << PAGE_SHIFT;

        LogPrintf(LOG_LEVEL_INFO,
                  "EVTCHN_FIFO: CONTROLBLOCK[%u] @ %08x.%08x\n",
                  vcpu_id,
                  Address.HighPart,
                  Address.LowPart);

        Context->ControlBlockMdl[vcpu_id] = Mdl;

        Index++;
    }

    Trace("<====\n");

done:
    KeReleaseSpinLock(&Context->Lock, Irql);

    return STATUS_SUCCESS;

fail2:
    __FreePage(Mdl);

fail1:
    Error("fail1 (%08x)\n", status);

    EvtchnReset();

    while (--Index >= 0) {
        unsigned int    vcpu_id;

        vcpu_id = SystemVirtualCpuIndex(Index);

        Mdl = Context->ControlBlockMdl[vcpu_id];
        Context->ControlBlockMdl[vcpu_id] = NULL;

        __FreePage(Mdl);
    }

    --Context->References;
    ASSERT3U(Context->References, ==, 0);
    KeReleaseSpinLock(&Context->Lock, Irql);

    return status;
}

VOID
EvtchnFifoRelease(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT  _Context
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT     Context = (PVOID)_Context;
    KIRQL                           Irql;
    int                             vcpu_id;

    KeAcquireSpinLock(&Context->Lock, &Irql);

    if (--Context->References > 0)
        goto done;

    Trace("====>\n");

    EvtchnReset();

    EvtchnFifoContract(Context);

    vcpu_id = HVM_MAX_VCPUS;
    while (--vcpu_id >= 0) {
        PMDL            Mdl;

        Mdl = Context->ControlBlockMdl[vcpu_id];
        if (Mdl == NULL)
            continue;

        Context->ControlBlockMdl[vcpu_id] = NULL;

        __FreePage(Mdl);
    }

    Trace("<====\n");

done:
    KeReleaseSpinLock(&Context->Lock, Irql);
}

static XENBUS_EVTCHN_ABI EvtchnAbiFifo = {
    NULL,
    EvtchnFifoAcquire,
    EvtchnFifoRelease,
    EvtchnFifoIsProcessorEnabled,
    EvtchnFifoPoll,
    EvtchnFifoPortEnable,
    EvtchnFifoPortDisable,
    EvtchnFifoPortAck,
    EvtchnFifoPortMask,
    EvtchnFifoPortUnmask
};

NTSTATUS
EvtchnFifoInitialize(
    IN  PXENBUS_FDO                     Fdo,
    OUT PXENBUS_EVTCHN_ABI_CONTEXT      *_Context
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT    Context;
    NTSTATUS                            status;

    Trace("====>\n");

    Context = __EvtchnFifoAllocate(sizeof (XENBUS_EVTCHN_FIFO_CONTEXT));

    status = STATUS_NO_MEMORY;
    if (Context == NULL)
        goto fail1;

    KeInitializeSpinLock(&Context->Lock);

    Context->Fdo = Fdo;

    *_Context = (PVOID)Context;

    Trace("<====\n");

    return STATUS_SUCCESS;

fail1:
    Error("fail1 (%08x)\n", status);

    return status;
}

VOID
EvtchnFifoGetAbi(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT      _Context,
    OUT PXENBUS_EVTCHN_ABI              Abi)
{
    *Abi = EvtchnAbiFifo;

    Abi->Context = (PVOID)_Context;
}

VOID
EvtchnFifoTeardown(
    IN  PXENBUS_EVTCHN_ABI_CONTEXT      _Context
    )
{
    PXENBUS_EVTCHN_FIFO_CONTEXT    Context = (PVOID)_Context;

    Trace("====>\n");

    Context->Fdo = NULL;

    RtlZeroMemory(&Context->Lock, sizeof (KSPIN_LOCK));

    ASSERT(IsZeroMemory(Context, sizeof (XENBUS_EVTCHN_FIFO_CONTEXT)));
    __EvtchnFifoFree(Context);

    Trace("<====\n");
}


text:
+++
Title = "Contact"
Type = "event"
Description = "Contact information for devopsdays Boise 2019"
+++

If you'd like to contact us by email: {{< email_organizers >}}

**Our local team**

{{< list_organizers >}}

**The core devopsdays organizer group**

{{< list_core >}}


text:
module PagSeguro
  class Installment
    class Response
      def initialize(response, collection)
        @response = response
        @collection = collection
      end

      def serialize
        if success?
          collection.installments = serialize_installments
        else
          collection.errors.add(response)
        end

        collection
      end

      def success?
        response.success? && response.xml?
      end

      private
      # The request response.
      attr_reader :response

      # The PagSeguro::Installment::Collection instance.
      attr_reader :collection

      def serialize_installments
        Nokogiri::XML(response.body).css("installments > installment").map do |node|
          ResponseSerializer.new(node).serialize
        end
      end
    end
  end
end


text:
package gdrj

import (
	"errors"
	"github.com/eaciit/orm/v1"
	"github.com/eaciit/toolkit"
	// "time"
)

type PLStructure struct {
	orm.ModelBase `json:"-" bson:"-"`
	ID            string `json:"_id" bson:"_id"` //PLItemID
	PLGroup       string
	PLSubGroup    string
	Name          string
	Notes         string
}

func (p *PLStructure) RecordID() interface{} {
	return p.ID
}

func (p *PLStructure) TableName() string {
	return "plstructure"
}

func PLStructureGetByID(id string) *PLStructure {
	p := new(PLStructure)
	DB().GetById(p, id)
	return p
}

func (p *PLStructure) Save() error {
	e := Save(p)
	if e != nil {
		return errors.New(toolkit.Sprintf("[%v-%v] Error found : ", p.TableName(), "save", e.Error()))
	}
	return e
}

func (p *PLStructure) Delete() error {
	e := Delete(p)
	if e != nil {
		return errors.New(toolkit.Sprintf("[%v-%v] Error found : ", p.TableName(), "delete", e.Error()))
	}
	return e
}


text:
<?php

declare(strict_types=1);

namespace Arcanedev\LaravelSettings;

use Arcanedev\LaravelSettings\Contracts\Store as StoreContract;
use Arcanedev\LaravelSettings\Contracts\Manager as SettingsManagerContract;
use Illuminate\Support\{Arr, Manager};

/**
 * Class     SettingsManager
 *
 * @author   ARCANEDEV <arcanedev.maroc@gmail.com>
 */
class SettingsManager extends Manager implements SettingsManagerContract
{
    /* -----------------------------------------------------------------
     |  Properties
     | -----------------------------------------------------------------
     */

    /**
     * Indicates if migrations will be run.
     *
     * @var bool
     */
    public static $runsMigrations = true;

    /* -----------------------------------------------------------------
     |  Getters & Setters
     | -----------------------------------------------------------------
     */

    /**
     * Get the default driver name.
     *
     * @return string
     */
    public function getDefaultDriver()
    {
        return $this->config->get('settings.default', 'json');
    }

    /**
     * Register a new store.
     *
     * @param  string  $driver
     * @param  array   $params
     *
     * @return $this
     */
    public function registerStore(string $driver, array $params)
    {
        return $this->extend($driver, function () use ($params) : StoreContract {
            return $this->container->make($params['driver'], [
                'options' => Arr::get($params, 'options', []),
            ]);
        });
    }
}


text:
var MotionPoint = require('../lib/profile/motionPoint').MotionPoint;
describe('Unit: cruise/dwell segment testing', function() {
    var cruiseSegmentFactory = require('../lib/segments/cruiseDwellSegment');
    var BasicMotionSegmentFactory = require('../lib/segments/basicSegment');

    xit('should create an cruise dwell segment with via distance (t0=0,tf=0.5,p0=0,v0=50,pf=25) and correctly evalute position and velocities', function() {
        // Make(t0, tf, p0, v, pf, permutation, mode, loads){
        var seg = cruiseSegmentFactory.Make(0, 0.5, 0, 50, 25, 'time', 'incremental');

        expect(seg.evaluatePositionAt(0.25)).toBe(12.5);
        expect(seg.evaluateVelocityAt(0.25)).toBe(50);
        expect(seg.evaluatePositionAt(0.50)).toBe(25);
    });

    xit('should create an cruise dwell segment with via distance (t0=0,tf=2,p0=0,v0=0,pf=25) and correctly evalute position and velocities', function() {
        var seg = cruiseSegmentFactory.Make(0, 0.5, 0, 0, 0, 'time', 'incremental');

        expect(seg.evaluatePositionAt(0.25)).toBe(0);
        expect(seg.evaluateVelocityAt(0.25)).toBe(0);
        expect(seg.evaluatePositionAt(0.50)).toBe(0);
    });

    it('should create a cruise segment via zero distance and starting with v0=0 (t0=0,tf=2,p0=0,v0=0,pf=0', function() {
        var seg = cruiseSegmentFactory.Make(0, 0.5, 0, 0, 0, 'time', 'incremental');

        expect(seg.evaluatePositionAt(0.25)).toBe(0);
        expect(seg.evaluateVelocityAt(0.25)).toBe(0);
        expect(seg.evaluatePositionAt(0.50)).toBe(0);
    });

    it('should create a cruise segment via zero distance and starting with v0=0 (t0=0,tf=2,p0=0,v0=0,pf=0', function() {
        var seg = cruiseSegmentFactory.Make(0, 0.5, 0, 0, 0, 'time', 'incremental');

        var allBasicSegments=seg.getAllSegments();
        allBasicSegments.every(function(seg){
            expect(seg instanceof BasicMotionSegmentFactory.BasicMotionSegment).toBe(true);
        });
    });

    it('should be able to duplicate a cruise dwell segment', function() {
        var seg = cruiseSegmentFactory.Make(0, 0.5, 0, 0, 0, 'time', 'incremental');

        var dupe= seg.duplicate();

        expect((dupe instanceof cruiseSegmentFactory.CruiseDwellMotionSegment)).toBe(true);
    });

    it('should throw when creating a cruise segment via non-zero distance and starting with v0=0 (t0=0,tf=0.5,p0=0,v0=0,pf=5', function() {
        expect(function() {
            cruiseSegmentFactory.Make(
                0,
                0.5,
                0,
                0,
                5,
                'distance',
                'incremental'
            );
        }).toThrow(
            new Error("Unable to create a cruise/dwell segment with zero velocity and non zero distance")
        );
    });

    it('Should be able to change cruise/dwell permutation using modifySegmentValues', function () {
        var seg = cruiseSegmentFactory.Make(0, 2, 0, 30, 60, 'distance', 'absolute');

        expect(seg.finalTime).toBe(2);
        expect(seg.segmentData.distance).toBe(60);
        expect(seg.segmentData.duration).toBe(2);
        expect(seg.segmentData.permutation).toBe('distance');

        seg.modifySegmentValues({
            permutation: 'time',
        }, new MotionPoint(0, 0, 0, 30, 0));

        expect(seg.finalTime).toBe(2);
        expect(seg.segmentData.distance).toBe(60);
        expect(seg.segmentData.duration).toBe(2);
        expect(seg.segmentData.permutation).toBe('time');

        seg.modifySegmentValues({
            permutation: 'distance',
            finalPosition: 40
        }, new MotionPoint(0, 0, 0, 30, 0));

        expect(seg.finalTime).toBe(40/30);
        expect(seg.segmentData.distance).toBe(40);
        expect(seg.segmentData.duration).toBe(40/30);
        expect(seg.segmentData.permutation).toBe('distance');
    });

    // should be able to serialize/deserialze
});


text:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { ListPokemonComponent } from './list-pokemon.component';
import { DetailPokemonComponent } from './detail-pokemon.component';
import { EditPokemonComponent } from './edit-pokemon.component';

import { AuthGuard } from '../auth-guard.service';

// routes definition
const pokemonsRoutes: Routes = [
	{
		path: 'pokemon',
		canActivate: [AuthGuard],
		children: [
			{ path: 'all', component: ListPokemonComponent },
			{ path: 'edit/:id', component: EditPokemonComponent },
			{ path: ':id', component: DetailPokemonComponent }
		]
	}
];

@NgModule({
	imports: [
		RouterModule.forChild(pokemonsRoutes)
	],
	exports: [
		RouterModule
	]
})
export class PokemonRoutingModule { }


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.UI.Core.Connection;
using Microsoft.EnterpriseManagement.ConsoleFramework;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters;
using Microsoft.EnterpriseManagement.GenericForm;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.ServiceManager.Application.Common;

////Requires Microsoft.EnterpriseManagement.UI.SMControls
using Microsoft.EnterpriseManagement.UI.WpfControls;    //Contains InstancePickerDialog, UserPicker, and ListPicker

////Requires Microsoft.EnterpriseManagement.UI.WpfViews
using Microsoft.EnterpriseManagement.UI.WpfViews;       //Contains FormEvents

//// Requires Microsoft.EnterpriseManagement.UI.Foundation
using Microsoft.EnterpriseManagement.UI.DataModel;      //Contains IDataItem

////Requires Microsoft.EnterpriseManagement.UI.FormsInfra
using Microsoft.EnterpriseManagement.UI.FormsInfra;     //Contains PreviewFormCommandEventArgs

namespace ITAssetMgmtForms
{
    /// <summary>
    /// Interaction logic for StorageDeviceForm.xaml
    /// </summary>
    public partial class StorageDeviceForm : UserControl
    {
        private RelatedItemsPane _relatedItemsPane;
        public StorageDeviceForm()
        {
            InitializeComponent();
            _relatedItemsPane = new RelatedItemsPane(new ConfigItemRelatedItemsConfiguration());
            tabItemRelItems.Content = _relatedItemsPane;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.AddHandler(FormEvents.PreviewSubmitEvent, new EventHandler<PreviewFormCommandEventArgs>(this.OnPreviewSubmit));
        }

        private void OnPreviewSubmit(object sender, PreviewFormCommandEventArgs e)
        {
            IDataItem DisplayName = this.DataContext as IDataItem;
            String strDisplayName;
            strDisplayName = DisplayName["DisplayName"].ToString();
            DisplayName["DisplayName"] = strDisplayName;
        }

        private void expMain_Loaded(object sender, RoutedEventArgs e)
        {
            HeaderedContentControl headeredContentControl = new HeaderedContentControl();
            headeredContentControl.OverridesDefaultStyle = true;
            headeredContentControl.Foreground = Brushes.Black;
            headeredContentControl.Header = "Main";
            this.expMain.Header = headeredContentControl;
        }

        private void InstancePicker_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            SingleInstancePicker singleInstancePicker = (SingleInstancePicker)sender;
            FormUtilities.Instance.PopoutForm(singleInstancePicker.Instance);
        }
    }
}


text:
Web-app
=======

Description: The Ottawa Chip Truck Finder helps hungry Ottawans find French fries fast. Users can either click on a map or select a zone within the City to search in.

[Ottawa Chip Truck Finder] (http://ottawachiptruck.phpfogapp.com/chiptruck-app/)

Author Information
==================

Susan Woodford: susanwoodford17@gmail.com

Installation Instructions
=========================
1. Clone the repository
2. Install chiptruck.sql
3. Set up and run it through localHost