Python json.update() Examples

The following are code examples for showing how to use json.update(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: x509-parser   Author: SeanWrightSec   File: x509Parser.py    Apache License 2.0 6 votes vote down vote up
def parse_x509(cert,ignore_extensions=False):
        x509_cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)

        cert = {
                "subject": x509_name_to_json(x509_cert.get_subject()),
                "issuer": x509_name_to_json(x509_cert.get_issuer()),
                "has-expired": x509_cert.has_expired(),
                "not-after": str(datetime.strptime(bytes_to_string(x509_cert.get_notAfter()), '%Y%m%d%H%M%SZ')),
                "not-before": str(datetime.strptime(bytes_to_string(x509_cert.get_notBefore()), '%Y%m%d%H%M%SZ')),
                "serial-number": x509_cert.get_serial_number(),
                "serial-number(hex)": hex(x509_cert.get_serial_number()),
                "signature-algorithm": bytes_to_string(x509_cert.get_signature_algorithm()),
                "version": x509_cert.get_version(),
                "pulic-key-length": x509_cert.get_pubkey().bits()
            }

        if (not ignore_extensions):
            cert.update({"extensions": x509_extensions_to_json(x509_cert)})

        return cert 
Example 2
Project: viewX-vscode   Author: textX   File: cytoscape_helper.py    MIT License 6 votes vote down vote up
def serialize_json(obj):
    """
    A helper method for serializing Cytoscape.js elements in desired json form.
    :param obj: Object to serialize
    :return: JSON string representation of obj
    """
    # handle concrete class serialization
    if hasattr(obj, '__metaclass__') and obj.__metaclass__.__name__ == 'Element':
        json = {}  # { '__classname__' : type(obj).__name__ }
        json.update(vars(obj))
        json.pop('__metaclass__', None)  # remove __metaclass__ from json
    # handle abstract class serialization
    elif obj.__class__.__name__ == 'type' and obj.__name__ == 'Element':
        json = obj.__name__
    elif obj.__class__.__name__ == 'ViewStyle':
        json = {}
        json.update(vars(obj))
    else:
        json = obj.__str__()
    return json 
Example 3
Project: sndlatr   Author: Schibum   File: api.py    Apache License 2.0 5 votes vote down vote up
def _encode_send_job(self, job):
        json = self._encode_base_job(job)
        json.update({
            'subject': job.subject,
            'messageId': job.message_id
        })
        return json 
Example 4
Project: sndlatr   Author: Schibum   File: api.py    Apache License 2.0 5 votes vote down vote up
def _encode_remind_job(self, job):
        json = self._encode_base_job(job)
        json.update({
            'subject': job.subject,
            'threadId': job.thread_id,
            'knownMessageIds': job.known_message_ids,
            'onlyIfNoreply': job.only_if_noreply,
            'disabledReply': job.disabled_reply
        })
        return json 
Example 5
Project: smc-python   Author: gabstopper   File: session.py    Apache License 2.0 5 votes vote down vote up
def _build_auth_request(self, verify=False, **kwargs):
        """
        Build the authentication request to SMC
        """
        json = {
            'domain': self.domain
        }
        
        credential = self.credential
        params = {}
        
        if credential.provider_name.startswith('lms'):
            params = dict(
                login=credential._login,
                pwd=credential._pwd)
        else:
            json.update(authenticationkey=credential._api_key)
        
        if kwargs:
            json.update(**kwargs)
            self._extra_args.update(**kwargs) # Store in case we need to rebuild later
        
        request = dict(
            url=self.credential.get_provider_entry_point(self.url, self.api_version),
            json=json,
            params=params,
            headers={'content-type': 'application/json'},
            verify=verify)
        
        return request 
Example 6
Project: smc-python   Author: gabstopper   File: session.py    Apache License 2.0 5 votes vote down vote up
def switch_domain(self, domain):
        """
        Switch from one domain to another. You can call session.login() with
        a domain key value to log directly into the domain of choice or alternatively
        switch from domain to domain. The user must have permissions to the domain or
        unauthorized will be returned. In addition, when switching domains, you will
        be logged out of the current domain to close the connection pool associated
        with the previous session. This prevents potentially excessive open
        connections to SMC
        ::
        
            session.login() # Log in to 'Shared Domain'
            ...
            session.switch_domain('MyDomain')
        
        :raises SMCConnectionError: Error logging in to specified domain.
            This typically means the domain either doesn't exist or the
            user does not have privileges to that domain.
        """
        if self.domain != domain:
            if self in self.manager: # Exit current domain
                self.logout()
            logger.info('Switching to domain: %r and creating new session', domain)
            params = self.copy()
            params.update(domain=domain)
            self.login(**params) 
Example 7
Project: smc-python   Author: gabstopper   File: session.py    Apache License 2.0 5 votes vote down vote up
def copy(self):
        # Copy the relevant parameters to make another session login
        # using the existing information
        params = copy.copy(self._params)
        kwargs = params.pop('kwargs', {})
        params.update(**kwargs)
        return params 
Example 8
Project: fp-NGFW-SMC-python   Author: Forcepoint   File: session.py    Apache License 2.0 5 votes vote down vote up
def _build_auth_request(self, verify=False, **kwargs):
        """
        Build the authentication request to SMC
        """
        json = {
            'domain': self.domain
        }
        
        credential = self.credential
        params = {}
        
        if credential.provider_name.startswith('lms'):
            params = dict(
                login=credential._login,
                pwd=credential._pwd)
        else:
            json.update(authenticationkey=credential._api_key)
        
        if kwargs:
            json.update(**kwargs)
            self._extra_args.update(**kwargs) # Store in case we need to rebuild later
        
        request = dict(
            url=self.credential.get_provider_entry_point(self.url, self.api_version),
            json=json,
            params=params,
            headers={'content-type': 'application/json'},
            verify=verify)
        
        return request 
Example 9
Project: fp-NGFW-SMC-python   Author: Forcepoint   File: session.py    Apache License 2.0 5 votes vote down vote up
def switch_domain(self, domain):
        """
        Switch from one domain to another. You can call session.login() with
        a domain key value to log directly into the domain of choice or alternatively
        switch from domain to domain. The user must have permissions to the domain or
        unauthorized will be returned. In addition, when switching domains, you will
        be logged out of the current domain to close the connection pool associated
        with the previous session. This prevents potentially excessive open
        connections to SMC
        ::
        
            session.login() # Log in to 'Shared Domain'
            ...
            session.switch_domain('MyDomain')
        
        :raises SMCConnectionError: Error logging in to specified domain.
            This typically means the domain either doesn't exist or the
            user does not have privileges to that domain.
        """
        if self.domain != domain:
            if self in self.manager: # Exit current domain
                self.logout()
            logger.info('Switching to domain: %r and creating new session', domain)
            params = self.copy()
            params.update(domain=domain)
            self.login(**params) 
Example 10
Project: fp-NGFW-SMC-python   Author: Forcepoint   File: session.py    Apache License 2.0 5 votes vote down vote up
def copy(self):
        # Copy the relevant parameters to make another session login
        # using the existing information
        params = copy.copy(self._params)
        kwargs = params.pop('kwargs', {})
        params.update(**kwargs)
        return params 
Example 11
Project: x509-parser   Author: SeanWrightSec   File: x509Parser.py    Apache License 2.0 5 votes vote down vote up
def x509_name_to_json(x509_name):
    json = { }

    for key, value in x509_name.get_components():
        json.update({ bytes_to_string(key): bytes_to_string(value) })

    return json 
Example 12
Project: x509-parser   Author: SeanWrightSec   File: x509Parser.py    Apache License 2.0 5 votes vote down vote up
def x509_extensions_to_json(x509_cert):
    json = { }
    for ext_index in range(0, x509_cert.get_extension_count(), 1):
        extension = x509_cert.get_extension(ext_index)
        json.update({ bytes_to_string(extension.get_short_name()): str(extension) })

    return json 
Example 13
Project: viewX-vscode   Author: textX   File: cytoscape_helper.py    MIT License 5 votes vote down vote up
def add_data(self, key, value):
        # self.data.update({key : value})
        self.data[key] = value