Skip to content

Commit 28c529b

Browse files
committed
update and added User-Agent
1 parent 6b342a3 commit 28c529b

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

tronapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
'__version__',
2929
'HttpProvider',
3030
'Tron',
31-
]
31+
]

tronapi/manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
# See License.txt in the project root for license information.
55
# --------------------------------------------------------------------
66

7-
"""This class is designed to configure and define nodes for different types."""
7+
"""
8+
tronapi.manager
9+
===============
10+
11+
This class is designed to configure and
12+
define nodes for different types.
13+
14+
:copyright: © 2018 by the iEXBase.
15+
:license: MIT License
16+
"""
17+
818
import logging
919

1020
from tronapi import HttpProvider

tronapi/providers/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License.
44
# See License.txt in the project root for license information.
55
# --------------------------------------------------------------------
6+
from tronapi.utils.help import format_user_agent
67

78

89
class BaseProvider(object):
@@ -21,5 +22,6 @@ def status_page(self, page):
2122
def _http_default_headers():
2223
"""Add default headers"""
2324
return {
24-
'Content-Type': 'application/json'
25+
'Content-Type': 'application/json',
26+
'User-Agent': format_user_agent()
2527
}

tronapi/providers/http.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# See License.txt in the project root for license information.
55
# --------------------------------------------------------------------
66

7+
"""
8+
tronapi.providers.http
9+
======================
10+
11+
Class for configuring http providers
12+
13+
:copyright: © 2018 by the iEXBase.
14+
:license: MIT License
15+
"""
16+
717
from collections import namedtuple
818
from urllib.parse import urlparse
919

tronapi/utils/help.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
# --------------------------------------------------------------------------------------------
1+
# --------------------------------------------------------------------
22
# Copyright (c) iEXBase. All rights reserved.
3-
# Licensed under the MIT License. See License.txt in the project root for license information.
4-
# --------------------------------------------------------------------------------------------
5-
3+
# Licensed under the MIT License.
4+
# See License.txt in the project root for license information.
5+
# --------------------------------------------------------------------
6+
import platform
67
import re
78
from typing import Any
89

910
import base58
11+
import tronapi
12+
13+
14+
def format_user_agent(name=None):
15+
"""Construct a User-Agent suitable for use in client code.
16+
This will identify use by the provided ``name`` (which should be on the
17+
format ``dist_name/version``), TronAPI version and Python version.
18+
.. versionadded:: 1.1
19+
"""
20+
parts = ['TronAPI/%s' % tronapi.__version__,
21+
'%s/%s' % (platform.python_implementation(),
22+
platform.python_version())]
23+
if name:
24+
parts.insert(0, name)
25+
return ' '.join(parts)
1026

1127

1228
def string_utf8_to_hex(name):
@@ -18,10 +34,10 @@ def hex_to_base58(value: Any) -> str:
1834

1935

2036
def is_valid_url(value):
21-
"""
22-
Return whether or not given value is a valid URL.
37+
"""Return whether or not given value is a valid URL.
2338
24-
:param value: URL address string to validate
39+
Args:
40+
value(str): URL address string to validate
2541
"""
2642
regex = re.compile(
2743
r'^(?:http|ftp)s?://'

0 commit comments

Comments
 (0)