BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etsy-python
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
etsy-python
Commits
d886ba25
Commit
d886ba25
authored
Sep 01, 2021
by
Forest Godfrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various fixups to make this work with python3
parent
4eb76b60
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
24 deletions
+32
-24
_core.py
etsy/_core.py
+12
-13
_multipartformdataencode.py
etsy/_multipartformdataencode.py
+8
-4
_v2.py
etsy/_v2.py
+5
-1
oauth.py
etsy/oauth.py
+7
-6
No files found.
etsy/_core.py
View file @
d886ba25
from
__future__
import
with_statement
from
__future__
import
with_statement
from
contextlib
import
closing
from
contextlib
import
closing
import
simplejson
as
json
import
simplejson
as
json
import
urllib
from
urllib.parse
import
urlencode
try
:
from
urllib
import
urlencode
from
urllib
import
urlopen
except
ImportError
:
from
urllib.parse
import
urlencode
from
urllib.request
import
urlopen
import
os
import
os
import
re
import
re
import
tempfile
import
tempfile
import
time
import
time
from
._multipartformdataencode
import
encode_multipart_formdata
from
etsy
._multipartformdataencode
import
encode_multipart_formdata
from
.exceptions
import
EtsyConcurrencyError
,
EtsyAPILimitError
from
.exceptions
import
EtsyConcurrencyError
,
EtsyAPILimitError
...
@@ -60,8 +66,6 @@ class TypeChecker(object):
...
@@ -60,8 +66,6 @@ class TypeChecker(object):
return
True
,
value
return
True
,
value
def
check_int
(
self
,
value
):
def
check_int
(
self
,
value
):
if
isinstance
(
value
,
long
):
# noqa
return
True
,
value
return
isinstance
(
value
,
int
),
value
return
isinstance
(
value
,
int
),
value
def
check_float
(
self
,
value
):
def
check_float
(
self
,
value
):
...
@@ -70,7 +74,7 @@ class TypeChecker(object):
...
@@ -70,7 +74,7 @@ class TypeChecker(object):
return
isinstance
(
value
,
float
),
value
return
isinstance
(
value
,
float
),
value
def
check_string
(
self
,
value
):
def
check_string
(
self
,
value
):
return
isinstance
(
value
,
basestring
),
value
# noqa
return
isinstance
(
value
,
str
),
value
# noqa
class
APIMethod
(
object
):
class
APIMethod
(
object
):
...
@@ -279,8 +283,8 @@ class API(object):
...
@@ -279,8 +283,8 @@ class API(object):
def
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
):
def
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
):
self
.
log
(
"API._get_url: url =
%
r"
%
url
)
self
.
log
(
"API._get_url: url =
%
r"
%
url
)
with
closing
(
url
lib
.
url
open
(
url
))
as
f
:
with
closing
(
urlopen
(
url
))
as
f
:
return
f
.
read
()
.
decode
(
'utf-8'
)
return
f
.
read
()
def
_get
(
self
,
http_method
,
url
,
**
kwargs
):
def
_get
(
self
,
http_method
,
url
,
**
kwargs
):
if
self
.
etsy_oauth_client
is
None
:
if
self
.
etsy_oauth_client
is
None
:
...
@@ -302,14 +306,10 @@ class API(object):
...
@@ -302,14 +306,10 @@ class API(object):
fields
.
append
((
name
,
str
(
value
)))
fields
.
append
((
name
,
str
(
value
)))
content_type
,
body
=
encode_multipart_formdata
(
fields
,
files
)
content_type
,
body
=
encode_multipart_formdata
(
fields
,
files
)
if
url
.
find
(
"inventory"
)
>
0
:
self
.
log
(
"Body = "
+
str
(
body
))
else
:
else
:
url
=
'
%
s
%
s'
%
(
self
.
api_url
,
url
)
url
=
'
%
s
%
s'
%
(
self
.
api_url
,
url
)
body
=
urlencode
(
kwargs
)
body
=
urlencode
(
kwargs
)
content_type
=
'application/x-www-form-urlencoded'
content_type
=
'application/x-www-form-urlencoded'
if
url
.
find
(
"inventory"
)
>
0
:
self
.
log
(
"Body = "
+
str
(
body
))
self
.
last_url
=
url
self
.
last_url
=
url
data
=
self
.
_get_url
(
url
,
http_method
,
content_type
,
body
)
data
=
self
.
_get_url
(
url
,
http_method
,
content_type
,
body
)
...
@@ -320,7 +320,6 @@ class API(object):
...
@@ -320,7 +320,6 @@ class API(object):
try
:
try
:
self
.
data
=
self
.
decode
(
data
)
self
.
data
=
self
.
decode
(
data
)
except
json
.
JSONDecodeError
:
except
json
.
JSONDecodeError
:
print
(
data
)
if
'being edited by another process'
in
data
:
if
'being edited by another process'
in
data
:
raise
EtsyConcurrencyError
(
data
)
raise
EtsyConcurrencyError
(
data
)
if
'exceeded your quota'
in
data
:
if
'exceeded your quota'
in
data
:
...
...
etsy/_multipartformdataencode.py
View file @
d886ba25
...
@@ -9,14 +9,18 @@ From http://code.activestate.com/recipes/146306/ (PSF License)
...
@@ -9,14 +9,18 @@ From http://code.activestate.com/recipes/146306/ (PSF License)
class
byteEncoder
:
class
byteEncoder
:
def
__init__
(
self
,
sep
):
def
__init__
(
self
,
sep
):
self
.
b
=
None
self
.
b
=
None
self
.
sep
=
bytes
(
sep
)
self
.
sep
=
bytes
(
sep
,
"utf-8"
)
def
append
(
self
,
val
):
def
append
(
self
,
v
):
if
isinstance
(
v
,
str
):
val
=
bytes
(
v
,
"utf-8"
)
else
:
val
=
bytes
(
v
)
if
self
.
b
is
None
:
if
self
.
b
is
None
:
self
.
b
=
bytes
(
val
)
self
.
b
=
val
return
return
self
.
b
=
self
.
b
+
self
.
sep
+
bytes
(
val
)
self
.
b
=
self
.
b
+
self
.
sep
+
val
def
value
(
self
):
def
value
(
self
):
return
self
.
b
return
self
.
b
...
...
etsy/_v2.py
View file @
d886ba25
...
@@ -19,8 +19,12 @@ class EtsyV2(API):
...
@@ -19,8 +19,12 @@ class EtsyV2(API):
def
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
):
def
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
):
print
(
"Getting URL "
+
str
(
url
))
print
(
"Getting URL "
+
str
(
url
))
if
self
.
etsy_oauth_client
is
not
None
:
if
self
.
etsy_oauth_client
is
not
None
:
if
isinstance
(
body
,
str
):
b
=
bytes
(
body
,
"utf-8"
)
else
:
b
=
bytes
(
body
)
return
self
.
etsy_oauth_client
.
do_oauth_request
(
url
,
return
self
.
etsy_oauth_client
.
do_oauth_request
(
url
,
http_method
,
http_method
,
content_type
,
content_type
,
b
ytes
(
body
,
"utf-8"
)
)
b
)
return
API
.
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
)
return
API
.
_get_url
(
self
,
url
,
http_method
,
content_type
,
body
)
etsy/oauth.py
View file @
d886ba25
import
oauth2
as
oauth
import
oauth2
as
oauth
import
urllib
import
urllib
from
cgi
import
parse_qsl
from
urllib.parse
import
parse_qsl
from
etsy.etsy_env
import
EtsyEnvProduction
from
etsy.etsy_env
import
EtsyEnvProduction
EtsyOAuthToken
=
oauth
.
Token
EtsyOAuthToken
=
oauth
.
Token
...
@@ -21,9 +21,10 @@ class EtsyOAuthClient(oauth.Client):
...
@@ -21,9 +21,10 @@ class EtsyOAuthClient(oauth.Client):
def
get_request_token
(
self
,
**
kwargs
):
def
get_request_token
(
self
,
**
kwargs
):
request_token_url
=
'
%
s?
%
s'
%
(
request_token_url
=
'
%
s?
%
s'
%
(
self
.
request_token_url
,
urllib
.
urlencode
(
kwargs
))
self
.
request_token_url
,
urllib
.
parse
.
urlencode
(
kwargs
))
resp
,
content
=
self
.
request
(
request_token_url
,
'GET'
)
resp
,
content
=
self
.
request
(
request_token_url
,
'GET'
)
return
self
.
_get_token
(
content
)
print
(
"get_request_token: "
+
str
(
content
))
return
self
.
_get_token
(
content
.
decode
(
'utf-8'
))
def
get_signin_url
(
self
,
**
kwargs
):
def
get_signin_url
(
self
,
**
kwargs
):
self
.
token
=
self
.
get_request_token
(
**
kwargs
)
self
.
token
=
self
.
get_request_token
(
**
kwargs
)
...
@@ -32,12 +33,12 @@ class EtsyOAuthClient(oauth.Client):
...
@@ -32,12 +33,12 @@ class EtsyOAuthClient(oauth.Client):
return
None
return
None
return
self
.
signin_url
+
'?'
+
\
return
self
.
signin_url
+
'?'
+
\
urllib
.
urlencode
({
'oauth_token'
:
self
.
token
.
key
})
urllib
.
parse
.
urlencode
({
'oauth_token'
:
self
.
token
.
key
})
def
get_access_token
(
self
,
oauth_verifier
):
def
get_access_token
(
self
,
oauth_verifier
):
self
.
token
.
set_verifier
(
oauth_verifier
)
self
.
token
.
set_verifier
(
oauth_verifier
)
resp
,
content
=
self
.
request
(
self
.
access_token_url
,
'GET'
)
resp
,
content
=
self
.
request
(
self
.
access_token_url
,
'GET'
)
return
self
.
_get_token
(
content
)
return
self
.
_get_token
(
content
.
decode
(
'utf-8'
)
)
def
set_oauth_verifier
(
self
,
oauth_verifier
):
def
set_oauth_verifier
(
self
,
oauth_verifier
):
self
.
token
=
self
.
get_access_token
(
oauth_verifier
)
self
.
token
=
self
.
get_access_token
(
oauth_verifier
)
...
@@ -48,7 +49,7 @@ class EtsyOAuthClient(oauth.Client):
...
@@ -48,7 +49,7 @@ class EtsyOAuthClient(oauth.Client):
if
self
.
logger
:
if
self
.
logger
:
self
.
logger
.
debug
(
'do_oauth_request: content =
%
r'
%
content
)
self
.
logger
.
debug
(
'do_oauth_request: content =
%
r'
%
content
)
return
content
return
content
.
decode
(
'utf-8'
)
def
_get_token
(
self
,
content
):
def
_get_token
(
self
,
content
):
d
=
dict
(
parse_qsl
(
content
))
d
=
dict
(
parse_qsl
(
content
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment