import jsondecodeerror seperately since its not in ujson
This commit is contained in:
		
							parent
							
								
									919ab12b76
								
							
						
					
					
						commit
						39d0be32ac
					
				
					 6 changed files with 15 additions and 9 deletions
				
			
		| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
This file deals with configuration management.
 | 
					This file deals with configuration management.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					from json import JSONDecodeError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ujson as json
 | 
					import ujson as json
 | 
				
			||||||
import logger
 | 
					import logger
 | 
				
			||||||
| 
						 | 
					@ -105,7 +106,7 @@ def save():
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        with open(get_config_file(), 'w', encoding="utf8") as configfile:
 | 
					        with open(get_config_file(), 'w', encoding="utf8") as configfile:
 | 
				
			||||||
            json.dump(get_config(), configfile, indent=2)
 | 
					            json.dump(get_config(), configfile, indent=2)
 | 
				
			||||||
    except json.JSONDecodeError:
 | 
					    except JSONDecodeError:
 | 
				
			||||||
        logger.warn('Failed to write to configuration file.')
 | 
					        logger.warn('Failed to write to configuration file.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,7 +116,7 @@ def reload():
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        with open(get_config_file(), 'r', encoding="utf8") as configfile:
 | 
					        with open(get_config_file(), 'r', encoding="utf8") as configfile:
 | 
				
			||||||
            set_config(json.loads(configfile.read()))
 | 
					            set_config(json.loads(configfile.read()))
 | 
				
			||||||
    except (FileNotFoundError, json.JSONDecodeError) as e:
 | 
					    except (FileNotFoundError, JSONDecodeError) as e:
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
        #logger.debug('Failed to parse configuration file.')
 | 
					        #logger.debug('Failed to parse configuration file.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@
 | 
				
			||||||
    You should have received a copy of the GNU General Public License
 | 
					    You should have received a copy of the GNU General Public License
 | 
				
			||||||
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
					    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					from json import JSONDecodeError
 | 
				
			||||||
import ujson as json
 | 
					import ujson as json
 | 
				
			||||||
from flask import Blueprint, request, Response, abort
 | 
					from flask import Blueprint, request, Response, abort
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +43,7 @@ def set_all_config():
 | 
				
			||||||
    """Overwrite existing JSON config with new JSON string"""
 | 
					    """Overwrite existing JSON config with new JSON string"""
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        new_config = request.get_json(force=True)
 | 
					        new_config = request.get_json(force=True)
 | 
				
			||||||
    except json.JSONDecodeError:
 | 
					    except JSONDecodeError:
 | 
				
			||||||
        abort(400)
 | 
					        abort(400)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        config.set_config(new_config)
 | 
					        config.set_config(new_config)
 | 
				
			||||||
| 
						 | 
					@ -59,7 +60,7 @@ def set_by_key(key):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        data = json.loads(bytes_to_str(request.data))
 | 
					        data = json.loads(bytes_to_str(request.data))
 | 
				
			||||||
    except (json.JSONDecodeError, KeyError):
 | 
					    except (JSONDecodeError, KeyError):
 | 
				
			||||||
        abort(400)
 | 
					        abort(400)
 | 
				
			||||||
    config.set(key, data, True)
 | 
					    config.set(key, data, True)
 | 
				
			||||||
    return Response('success')
 | 
					    return Response('success')
 | 
				
			||||||
| 
						 | 
					@ -4,12 +4,14 @@ send a command to the local API server
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import urllib
 | 
					import urllib
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import functools
 | 
					 | 
				
			||||||
from typing import TYPE_CHECKING, Callable
 | 
					from typing import TYPE_CHECKING, Callable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
 | 
					import deadsimplekv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import logger
 | 
				
			||||||
 | 
					import config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logger, config, deadsimplekv
 | 
					 | 
				
			||||||
from . import getclientapiserver
 | 
					from . import getclientapiserver
 | 
				
			||||||
import filepaths
 | 
					import filepaths
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
validate new block's metadata
 | 
					validate new block's metadata
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					from json import JSONDecodeError
 | 
				
			||||||
import ujson as json
 | 
					import ujson as json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logger, onionrexceptions
 | 
					import logger, onionrexceptions
 | 
				
			||||||
| 
						 | 
					@ -34,7 +35,7 @@ def validate_metadata(metadata, block_data) -> bool:
 | 
				
			||||||
    if type(metadata) is str:
 | 
					    if type(metadata) is str:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            metadata = json.loads(metadata)
 | 
					            metadata = json.loads(metadata)
 | 
				
			||||||
        except json.JSONDecodeError:
 | 
					        except JSONDecodeError:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Validate metadata dict for invalid keys to sizes that are too large
 | 
					    # Validate metadata dict for invalid keys to sizes that are too large
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ HTTP endpoints for communicating with peers
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					from json import JSONDecodeError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import deadsimplekv as simplekv
 | 
					import deadsimplekv as simplekv
 | 
				
			||||||
import ujson as json
 | 
					import ujson as json
 | 
				
			||||||
| 
						 | 
					@ -50,7 +51,7 @@ def sendto():
 | 
				
			||||||
    """Endpoint peers send chat messages to"""
 | 
					    """Endpoint peers send chat messages to"""
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        msg = request.get_json(force=True)
 | 
					        msg = request.get_json(force=True)
 | 
				
			||||||
    except json.JSONDecodeError:
 | 
					    except JSONDecodeError:
 | 
				
			||||||
        msg = ''
 | 
					        msg = ''
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        msg = json.dumps(msg)
 | 
					        msg = json.dumps(msg)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ with open(
 | 
				
			||||||
    os.path.dirname(
 | 
					    os.path.dirname(
 | 
				
			||||||
        os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
 | 
					        os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
 | 
				
			||||||
    data = info_file.read().strip()
 | 
					    data = info_file.read().strip()
 | 
				
			||||||
    version = json.loads(data, strict=False)['version']
 | 
					    version = json.loads(data)['version']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BOARD_CACHE_FILE = identifyhome.identify_home() + '/board-index.cache.json'
 | 
					BOARD_CACHE_FILE = identifyhome.identify_home() + '/board-index.cache.json'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue